|
From: Luis M. García-C. G. <lui...@gm...> - 2013-11-21 18:30:37
|
Hello!
I have a doubt about the way matplotlib computes (and plots) a psd. I have
the following example code (I've imported pylab for convenience here):
from pylab import *
A = 10. ** (10. / 20.) / sqrt(2.) * 2. # This amplitude should give 10 dB
frequency = 5.
sampling_frequency = 1000.
t_max = 12.
t = arange(0., t_max, 1. / sampling_frequency)
x = A * cos(2. * pi * frequency * t)
Pxx, freqs = mlab.psd(x, Fs=sampling_frequency, NFFT=len(x),
window=mlab.window_none)
dB_actual = 20. * log10(rms_flat(x)) # dB_actual = 10., as expected
dB_psd = 10. * log10(Pxx.max()) # dB_psd = 20.791812460476248
As I understand, this should not happen this way. dB_psd should be equal to
10, as dB_actual. I can get it to compute the correct value with this:
Pxx, freqs = mlab.psd(x / sqrt(t_max), Fs=sampling_frequency, NFFT=len(x),
window=mlab.window_none)
(i.e., dividing the variable by the square root of the time). Is this really
the expected behavior or this is a bug?
If it does matter, I'm using using matplotlib 1.3.1.
Thanks for your help!
--
Luis Miguel García-Cuevas González
|