HOWTO: From magnitude spectrum to sound


Calling all atlhack signal geeks!

Given a real-valued signal it is fairly straightforward to generate the magnitude spectrum. To plot it in matlab it’s

spec = fft( signal, size );
plot( abs( fftshift( spec ) ) );

The purpose of the abs is to get the complex modulus of the transform values. To get the original signal it’s

plot( real( ifft( spec, size ) ) );

Question: if I only knew X where X = abs( fft( signal, size ) ) and signal is real, could I properly reconstruct signal?

4 Responses to “HOWTO: From magnitude spectrum to sound”

  1. Anonymous says:

    Properly, no. The magnitude spectrum throws out the phase information from the DFT transform (what the FFT computes). Given the full DFT, one can exactly reproduce the bandlimited time domain signal – but the phase is critical to positioning the component sinusoids.

    A short example:
    load handel;
    plot( abs( yfft )); %show the spectrum

    %compare the reconstruction and the original
    plot( y );
    plot( iy );

    sound(iay, Fs);

    This isn’t the best explanation. But the low frequencies of a non-stationary signal are actually doing some weird form of making events in the sound.

    If you want to throw out the phases of the spectrum but still use the magnitude for synthesis, it might work in the context of short-time fourier transform, where you break the time domain signal into windows (with more or less stationary spectrums) to analyse them.

  2. Stephen says:

    I suspected as much. I will go ahead with experimenting with the STFT using just real parts or maybe the magnitudes. This will be my absentee hackfest project for the week.

    The goal is to create a tool that will convert sounds to images of spectrograms and backwards. Joel mentioned applying applying photoshop filters to them and wondering what the sounds would be. I, of course, am interested in the results of texture synthesis / image analogies on the spectrogram.

  3. ynniv says:

    This website ( has images hidden in the spectrogram of some Aphex Twin songs.

  4. Stephen says:

    The process distorts even sine waves using teensy weensy windows.  Check out the results here:

    I think I’m going to just roll my own photoshop-style filters to run on images with complex pixel values.  Most image filters are quite simple and I think there’s nothing wrong with substituting complex numbers in them.

Leave a Reply