PLT.PSD unable to match plt.psd vs actual output data

Viewed 32

I am actually trying the PSD of a signal using the plt.psd function.

Pxxf, psd_frequencies = plt.psd(phase,Fs=50,scale_by_freq= False,noverlap=250,NFFT=500,label = "3 minute",return_line=False)

Where phase is the input signal.

This is what it outputs: This is what it outputs

but if I am to plot it using the output values it does not really work. Here is what I do.

Pxxf, psd_frequencies = plt.psd(phase,Fs=50,scale_by_freq= False,noverlap=250,NFFT=500,label = "3 minute",return_line=False)

plt.cla()
plt.plot(psd_frequencies,Pxxf)

This is what I get: This is what I get

Any thoughts on why there is such a difference?

1 Answers

As noted in matplotlib.pyplot.psd`'s documentation,

For plotting, the power is plotted as 10log10(Pxx) for decibels, though Pxx itself is returned.

So, to get a similar result while manually plotting the returned arrays, try

plt.plot(psd_frequencies,10*np.log10(Pxxf))
Related