Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4c17c1f

Browse files
committed
Add a converted MatLab example that was used to figure out the differences between MatLab and matplotlib PSD scaling.
svn path=/trunk/matplotlib/; revision=6519
1 parent 110be94 commit 4c17c1f

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#This is a ported version of a Matlab example from the signal processing
2+
#toolbox that showed some difference at one time between Matplotlib's and
3+
#MatLab's scaling of the PSD.
4+
5+
import numpy as np
6+
import matplotlib.pyplot as plt
7+
import matplotlib.mlab as mlab
8+
9+
fs = 1000
10+
t = np.linspace(0, 0.3, 301)
11+
A = np.array([2, 8]).reshape(-1, 1)
12+
f = np.array([150, 140]).reshape(-1, 1)
13+
xn = (A * np.sin(2 * np.pi * f * t)).sum(axis=0) + 5 * np.random.randn(*t.shape)
14+
15+
yticks = np.arange(-50, 30, 10)
16+
xticks = np.arange(0,550,100)
17+
18+
plt.subplot(1,2,1)
19+
plt.psd(xn, NFFT=301, Fs=fs, window=mlab.window_none, pad_to=1024,
20+
scale_by_freq=True)
21+
plt.title('Periodogram PSD Estimate')
22+
plt.yticks(yticks)
23+
plt.xticks(xticks)
24+
plt.grid(True)
25+
26+
plt.subplot(1,2,2)
27+
plt.psd(xn, NFFT=150, Fs=fs, window=mlab.window_none, noverlap=75, pad_to=512,
28+
scale_by_freq=True)
29+
plt.title('Welch Method PSD Estimate')
30+
plt.xticks(xticks)
31+
plt.yticks(yticks)
32+
plt.grid(True)
33+
34+
plt.show()

0 commit comments

Comments
 (0)