A spectral approach to ill-posed problems for wave equations