<div dir="ltr">I suspect that this is related to <a href="https://github.com/matplotlib/matplotlib/issues/4328">https://github.com/matplotlib/matplotlib/issues/4328</a> which was fixed by <a href="https://github.com/matplotlib/matplotlib/pull/4593">https://github.com/matplotlib/matplotlib/pull/4593</a> and was an intentional change.<div><br></div><div>Tom</div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, May 12, 2016 at 3:13 PM plotalot <<a href="mailto:dr369@nau.edu">dr369@nau.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello,<br>
<br>
I noticed an inconsistency with the pyplot.psd function when upgrading<br>
from matplotlib version 1.4.0 to 1.5.3<br>
<br>
I have written some code (below) that will show what I'm talking about<br>
when run with the different matplotlib versions. In 1.4.0, the line "PX2<br>
/= fft_size" was needed, but gives the wrong answer (P_ave is not equal<br>
to 1, and Pxw.max() is -36dB instead of 0dB) if it is included when<br>
using 1.5.3<br>
<br>
I am mainly concerned with knowing if this change was intentional; will<br>
it behave like this from now on (no longer needing division by fft_size)?<br>
<br>
import matplotlib.pyplot as plt<br>
import matplotlib.mlab as mlab<br>
import numpy as np<br>
<br>
fft_size = 4096<br>
fs = 2500.00<br>
<br>
gram_lines = 100;<br>
t = np.arange(1.0,gram_lines*fft_size,1.0);<br>
t = t / fs;<br>
del_f = fs/fft_size;<br>
base_freq = 10.0 # in Hz<br>
bin_err = 0.0<br>
f = (int(base_freq / del_f) + bin_err) * del_f # ensure f is in center<br>
of Fourier band<br>
A = np.sqrt(2.0); # if the amplitude is sqrt(2) then the total power =<br>
1.0 linear and 0.0 in dB<br>
dat = A * np.sin(2 * np.pi * f * t);<br>
<br>
(Px2, F) = plt.psd(dat, NFFT = fft_size, Fs=fs, Fc=0,<br>
detrend=mlab.detrend_none, window=mlab.window_none, noverlap=0, pad_to =<br>
None, sides='onesided', scale_by_freq = False);<br>
Px2 /= fft_size; #comment this line out if using 1.5.1??<br>
P_ave = sum(Px2);<br>
Px2 = 10.0*np.log10(Px2);<br>
<br>
#print results to compare actual with expected<br>
print "Sum of psd Px2 = %f, This should equal 1.0." %P_ave<br>
print "Max psd Px2 = %f dB. This should equal 0.0 dB if freq is a<br>
multiple of freq resolution.\n" %(Px2.max())<br>
<br>
<br>
<br>
<br>
--<br>
View this message in context: <a href="http://matplotlib.1069221.n5.nabble.com/PSD-Scaling-matplotlib-version-1-4-X-versus-1-5-X-tp47064.html" rel="noreferrer" target="_blank">http://matplotlib.1069221.n5.nabble.com/PSD-Scaling-matplotlib-version-1-4-X-versus-1-5-X-tp47064.html</a><br>
Sent from the matplotlib - devel mailing list archive at Nabble.com.<br>
_______________________________________________<br>
Matplotlib-devel mailing list<br>
<a href="mailto:Matplotlib-devel@python.org" target="_blank">Matplotlib-devel@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/matplotlib-devel" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/matplotlib-devel</a><br>
</blockquote></div>