# [Matplotlib-users] PSD Scaling (matplotlib version 1.4.X versus 1.5.X)

Dan Roberts droberts at spawar.navy.mil
Thu Apr 21 17:00:56 EDT 2016

Hello,

I noticed an inconsistency with the pyplot.psd function when upgrading
from matplotlib version 1.4.0 to 1.5.3

I have written some code (below) that will show what I'm talking about
when run with the different matplotlib versions. In 1.4.0, the line "PX2
/= fft_size" was needed, but gives the wrong answer (P_ave is not equal
to 1, and Pxw.max() is -36dB instead of 0dB) if it is included when
using 1.5.3

I am mainly concerned with knowing if this change was intentional; will
it behave like this from now on (no longer needing division by fft_size)?

import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
import numpy as np

fft_size = 4096
fs = 2500.00

gram_lines = 100;
t = np.arange(1.0,gram_lines*fft_size,1.0);
t = t / fs;
del_f = fs/fft_size;
base_freq = 10.0              # in Hz
bin_err = 0.0
f = (int(base_freq / del_f) + bin_err) * del_f # ensure f is in center
of Fourier band
A = np.sqrt(2.0);  # if the amplitude is sqrt(2) then the total power =
1.0 linear and 0.0 in dB
dat = A * np.sin(2 * np.pi * f * t);

(Px2, F) = plt.psd(dat, NFFT = fft_size, Fs=fs, Fc=0,