If you're using pyplot.specgram (i.e. "from pylab import *;

specgram(...)"), note that the plot is in dB, hence the negative

values.

I'm surprised this fact isn't mentioned in the documentation:

http://matplotlib.org/api/pyplot_api.html?highlight=specgram#matplotlib.pyplot.specgram

However, when in doubt, look at the code.

## ···

On Mon, Nov 12, 2012 at 12:28 PM, Paul Anton Letnes <paul.anton.letnes@...287...> wrote:

Heh,

that's funny. Now then, why do my plots come out with negative values all over the place? That's why I started digging around. After all, X * conj(X) should be equal to the absolute square of X, right?

Paul

On 12. nov. 2012, at 21:00, G Jones wrote:

Hi,

If you trace back into the code further, you will see that the Pxx is

computed as X = fft(x), Pxx = X * conj(X) which is real, but the data

type will be complex with a ~0 imaginary part (up to floating point

precision). Thus the Pxx.real is just to ensure that the resulting

data type is real instead of complex to save memory.

GlennOn Mon, Nov 12, 2012 at 11:42 AM, Paul Anton Letnes >> <paul.anton.letnes@...287...> wrote:

Hi,

not 100% sure this is a bug, but here goes:

In file matplotlib/lib/matplotlib/mlab.py, the functions psd (power spectral density) and specgram returns the real part of the fourier transform.

% grep -n Pxx.real mlab.py

390: return Pxx.real,freqs

470: Pxx = Pxx.real #Needed since helper implements generically

(git version 4f902fac1c5bf267e3fdeb4c2045926d7498e85a, cloned from github today)This all means that the specgram plot routine yields the real part of the Fourier transform, rather than its absolute square (forgetting normalization for simplicity of discussion). The definition of the PSD is that it is the absolute square of the Fourier transform:

https://en.wikipedia.org/wiki/Power_spectral_density#Energy_spectral_densityHence, I believe this is a bug which should be fixed.

Cheers

Paul

------------------------------------------------------------------------------

Monitor your physical, virtual and cloud infrastructure from a single

web console. Get in-depth insight into apps, servers, databases, vmware,

SAP, cloud infrastructure, etc. Download 30-day Free Trial.

Pricing starts from $795 for 25 servers or applications!

http://p.sf.net/sfu/zoho_dev2dev_nov

_______________________________________________

Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users