2
$\begingroup$

I'm working on a research project where we would like to apply convolutional neural networks to an image representation of a signal. However, it seems that if I would use a spectrogram, I would end up loosing the phase information. As a result, my question is:

Does an equivalent transformation of a signal to a spectrogram image exist in which the phase information is part of the resulting image?

Thanks a lot and have a great day, Maxime

From https://en.wikipedia.org/wiki/Spectrogram:

Limitations and resynthesis

From the formula above, it appears that a spectrogram contains no information about the exact, or even approximate, phase of the signal that it represents. For this reason, it is not possible to reverse the process and generate a copy of the original signal from a spectrogram.

$\endgroup$
2
  • 1
    $\begingroup$ I don't know if this is what you are looking for, but in MATLAB the function spectrogram() returns complex numbers, so you can calculate the magnitude and phase of them for every timestep. $\endgroup$
    – Tendero
    Apr 19, 2017 at 15:32
  • $\begingroup$ Hi Tendero, Thanks for the reply. I would like to represent the signal as an image so that I can then train a CNN using the image as the input $\endgroup$ Apr 19, 2017 at 15:37

2 Answers 2

2
$\begingroup$

A homemade solution comes to my mind, but I don't know if it will work for you. I'll write it down anyway, since it may be helpful.

In MATLAB you can do:

[s,f,t] = spectrogram(x,window,noverlap,f,fs);

Thus in s complex values will be stored. You can then find their magnitudes and angles

A = abs(s);
phi = angle(s);

Then you can do a homemade spectrogram with imagesc. For amplitude:

imagesc(time_vector,freq_vector,20*log10(A));

where the first two inputs are vectors that you can define to set your axis. Similarly, for the phase:

imagesc(time_vector,phase_vector,phi);
$\endgroup$
0
2
$\begingroup$

If you create a volumetric (unflattened 3D) image, you can use 2 layers in the 3rd dimension to represent magnitude and phase, or real and imaginary components of a complex spectrogram output.

In a 2D color spectrogram, you could try using an orthogonal color mapping, for instance, in RGB space, red + green for magnitude and blue (or delta blue) for phase, or similar for real and imaginary components, or use YUV or HSL color spaces, etc.

$\endgroup$
2
  • $\begingroup$ Just a thought - you might try HUSL/HSLuv, hsluv.org, mapping phase to hue and lightness to magnitude. I bring this up because normal HSL is pretty visually confusing, since human-perceived lightness varies by color. $\endgroup$
    – lahwran
    Apr 19, 2017 at 22:06
  • $\begingroup$ With phase there's the problem that it is wrapped phase, so it has discontinuities that will make it difficult for the neural network to compare phases. So the real and imaginary components might work better. $\endgroup$ Apr 20, 2017 at 6:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.