|
20 | 20 | dt = 0.01 |
21 | 21 | t = np.arange(0, 10, dt) |
22 | 22 | nse = np.random.randn(len(t)) |
23 | | -r = np.exp(-t/0.05) |
| 23 | +r = np.exp(-t / 0.05) |
24 | 24 |
|
25 | | -cnse = np.convolve(nse, r)*dt |
| 25 | +cnse = np.convolve(nse, r) * dt |
26 | 26 | cnse = cnse[:len(t)] |
27 | | -s = 0.1*np.sin(2*np.pi*t) + cnse |
| 27 | +s = 0.1 * np.sin(2 * np.pi * t) + cnse |
28 | 28 |
|
29 | 29 | plt.subplot(211) |
30 | 30 | plt.plot(t, s) |
31 | 31 | plt.subplot(212) |
32 | | -plt.psd(s, 512, 1/dt) |
| 32 | +plt.psd(s, 512, 1 / dt) |
33 | 33 |
|
34 | 34 | plt.show() |
35 | 35 |
|
|
68 | 68 | # time series at once |
69 | 69 | ax2 = fig.add_subplot(2, 3, 4) |
70 | 70 | ax2.psd(y, NFFT=len(t), pad_to=len(t), Fs=fs) |
71 | | -ax2.psd(y, NFFT=len(t), pad_to=len(t)*2, Fs=fs) |
72 | | -ax2.psd(y, NFFT=len(t), pad_to=len(t)*4, Fs=fs) |
| 71 | +ax2.psd(y, NFFT=len(t), pad_to=len(t) * 2, Fs=fs) |
| 72 | +ax2.psd(y, NFFT=len(t), pad_to=len(t) * 4, Fs=fs) |
73 | 73 | plt.title('zero padding') |
74 | 74 |
|
75 | 75 | # Plot the PSD with different block sizes, Zero pad to the length of the |
76 | 76 | # original data sequence. |
77 | 77 | ax3 = fig.add_subplot(2, 3, 5, sharex=ax2, sharey=ax2) |
78 | 78 | ax3.psd(y, NFFT=len(t), pad_to=len(t), Fs=fs) |
79 | | -ax3.psd(y, NFFT=len(t)//2, pad_to=len(t), Fs=fs) |
80 | | -ax3.psd(y, NFFT=len(t)//4, pad_to=len(t), Fs=fs) |
| 79 | +ax3.psd(y, NFFT=len(t) // 2, pad_to=len(t), Fs=fs) |
| 80 | +ax3.psd(y, NFFT=len(t) // 4, pad_to=len(t), Fs=fs) |
81 | 81 | ax3.set_ylabel('') |
82 | 82 | plt.title('block size') |
83 | 83 |
|
84 | 84 | # Plot the PSD with different amounts of overlap between blocks |
85 | 85 | ax4 = fig.add_subplot(2, 3, 6, sharex=ax2, sharey=ax2) |
86 | | -ax4.psd(y, NFFT=len(t)//2, pad_to=len(t), noverlap=0, Fs=fs) |
87 | | -ax4.psd(y, NFFT=len(t)//2, pad_to=len(t), noverlap=int(0.05*len(t)/2.), Fs=fs) |
88 | | -ax4.psd(y, NFFT=len(t)//2, pad_to=len(t), noverlap=int(0.2*len(t)/2.), Fs=fs) |
| 86 | +ax4.psd(y, NFFT=len(t) // 2, pad_to=len(t), noverlap=0, Fs=fs) |
| 87 | +ax4.psd(y, NFFT=len(t) // 2, pad_to=len(t), |
| 88 | + noverlap=int(0.05 * len(t) / 2.), Fs=fs) |
| 89 | +ax4.psd(y, NFFT=len(t) // 2, pad_to=len(t), |
| 90 | + noverlap=int(0.2 * len(t) / 2.), Fs=fs) |
89 | 91 | ax4.set_ylabel('') |
90 | 92 | plt.title('overlap') |
91 | 93 |
|
|
0 commit comments