#This program below do reveal that mlab.psd and pyplot.psd are different
http://www.nabble.com/file/p24713274/psd_testpng.png psd_testpng.png
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
>
> amb...@sa...
>
>
>
>
> ------------------------------------------------------------------------------
> 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
> Mat...@li...
> 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.
|