psd question...

Hi All:

I’m trying to use the matplotlib psd function to plot
some data. The result from MATLAB’s pWelch function looks vastly
different.

Any suggestions/recommendations would be greatly
appreciated!

THANXS

amb

Here is the MATLAB code:

Fs = 13e6;

fid =
fopen(‘C:\asp\roseRT\ics_output.bin’, ‘r’, ‘ieee-le’);

s = fread(fid, [2, Inf], ‘int32’);

fclose(fid);

z = complex(s(2,:), s(1,:));

pwelch(z, [], [], [], Fs)

And here is the (hypothetically) equivalent
Python/matplotlib code:

datatype = np.complex64

       
fd = open(self.filename, 'rb')

       
read_data = np.fromfile(file=fd, dtype=datatype)

       
Pxx,freqs = psd(read_data,Fs=13000000)

       
self.axes.plot(freqs, 10*log10(Pxx) )

       
self.canvas.draw()

Ambrose Lewis

SAIC

4001 N Fairfax Drive, Suite 400

Arlington****, VA 22203****

703.558.2786

ambrose.j.lewis@…2441…

Lewis, Ambrose J. wrote:

Hi All:

I’m trying to use the matplotlib psd function to plot some data. The
result from MATLAB’s pWelch function looks vastly different.

Any suggestions/recommendations would be greatly appreciated!

What version of matplotlib are you running? I made some changes in the new
version that should improve this.

Can you put an example of the data somewhere or create some dummy data that
reproduces the problem so that I can try to reproduce the problem here?

Ryan

···

--
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma

mlab.psd and pyplot.psd are different!!!!

http://www.nabble.com/file/p24713274/psd_testpng.png
http://www.nabble.com/file/p24713274/psd_testpng.png psd_testpng.png
#This program below do reveal that mlab.psd and pyplot.psd are different
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
dt = np.pi / 100.
fs = 1. / dt
t = np.arange(0, 8, dt)
y = 10. * np.sin(2 * np.pi * 4 * t) + 5. * np.sin(2 * np.pi * 4.25 * t)
y = y + np.random.randn(*t.shape)
print "t=",t
print "y=",y
print "fs=",fs
#Plot the raw time series
fig = plt.figure()
fig.subplots_adjust(hspace=0.6, wspace=0.5)

···

#
ax = fig.add_subplot(3, 1, 1)
plt.title('Data')
ax.plot(t,y)

ax = fig.add_subplot(3, 1, 2)
plt.title('psd using pyplot')
ax.psd(y,Fs=fs,scale_by_freq=False)

ax = fig.add_subplot(3, 1, 3)
plt.title('psd using mlab')
x,y=mlab.psd(y,Fs=fs,scale_by_freq=False)
ax.plot(y,x)
plt.show()

Lewis, Ambrose J. wrote:

Hi All:

I'm trying to use the matplotlib psd function to plot some data. The
result from MATLAB's pWelch function looks vastly different.

Any suggestions/recommendations would be greatly appreciated!

THANXS

amb

Here is the MATLAB code:

Fs = 13e6;

fid = fopen('C:\asp\roseRT\ics_output.bin', 'r', 'ieee-le');

s = fread(fid, [2, Inf], 'int32');

fclose(fid);

z = complex(s(2,:), s(1,:));

pwelch(z, [], [], [], Fs)

And here is the (hypothetically) equivalent Python/matplotlib code:

                datatype = np.complex64

                fd = open(self.filename, 'rb')

                read_data = np.fromfile(file=fd, dtype=datatype)

                Pxx,freqs = psd(read_data,Fs=13000000)

                self.axes.plot(freqs, 10*log10(Pxx) )

                self.canvas.draw()

Ambrose Lewis

SAIC

4001 N Fairfax Drive, Suite 400

Arlington, VA 22203

703.558.2786

ambrose.j.lewis@...2441...

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


View this message in context: http://www.nabble.com/psd-question…-tp21458898p24713274.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

The plotting command pyplot.psd scales the numbers in decibels (the dB
in the ylabel in pyplot.psd). mlab.psd just returns the unscaled
power. So in your example in subplot(3,1,3), call before plotting

  x = 10*np.log10(np.absolute(x))

JDH

···

On Wed, Jul 29, 2009 at 1:39 AM, 3togo<freetogo@...287...> wrote:

mlab.psd and pyplot.psd are different!!!!