A method for magnetic resonance spectroscopy (=MRS) or magnetic resonance imaging (=MRI) in which an NMR time-domain signal is generated by an excited transverse nuclear magnetization precessing about the applied magnetic field, whereby the RF excitation pulse is adapted to cover a whole range of NMR frequencies of interest present in the object, and time-domain signal acquisition takes place during, or during and after the application of the RF excitation pulse, is characterized in that spectral or image data are reconstructed by a matrix product of a reconstruction matrix and a vector of time-domain signal points, the reconstruction matrix being an inversion of an encoding matrix. An improved method for reconstructing spectral or image data from a time-domain signal is thereby provided which is more versatile than conventional Fourier transform.