|
7 | 7 | # Fixing random state for reproducibility
|
8 | 8 | np.random.seed(19680801)
|
9 | 9 |
|
10 |
| - |
11 |
| -# make a little extra space between the subplots |
12 |
| -plt.subplots_adjust(wspace=0.5) |
13 |
| - |
14 | 10 | dt = 0.01
|
15 | 11 | t = np.arange(0, 30, dt)
|
16 | 12 | nse1 = np.random.randn(len(t)) # white noise 1
|
17 | 13 | nse2 = np.random.randn(len(t)) # white noise 2
|
18 |
| -r = np.exp(-t/0.05) |
| 14 | +r = np.exp(-t / 0.05) |
19 | 15 |
|
20 |
| -cnse1 = np.convolve(nse1, r, mode='same')*dt # colored noise 1 |
21 |
| -cnse2 = np.convolve(nse2, r, mode='same')*dt # colored noise 2 |
| 16 | +cnse1 = np.convolve(nse1, r, mode='same') * dt # colored noise 1 |
| 17 | +cnse2 = np.convolve(nse2, r, mode='same') * dt # colored noise 2 |
22 | 18 |
|
23 | 19 | # two signals with a coherent part and a random part
|
24 |
| -s1 = 0.01*np.sin(2*np.pi*10*t) + cnse1 |
25 |
| -s2 = 0.01*np.sin(2*np.pi*10*t) + cnse2 |
| 20 | +s1 = 0.01 * np.sin(2 * np.pi * 10 * t) + cnse1 |
| 21 | +s2 = 0.01 * np.sin(2 * np.pi * 10 * t) + cnse2 |
| 22 | + |
| 23 | +fig, axs = plt.subplots(2, 1) |
| 24 | +axs[0].plot(t, s1, t, s2) |
| 25 | +axs[0].set_xlim(0, 5) |
| 26 | +axs[0].set_xlabel('time') |
| 27 | +axs[0].set_ylabel('s1 and s2') |
| 28 | +axs[0].grid(True) |
26 | 29 |
|
27 |
| -plt.subplot(211) |
28 |
| -plt.plot(t, s1, t, s2) |
29 |
| -plt.xlim(0, 5) |
30 |
| -plt.xlabel('time') |
31 |
| -plt.ylabel('s1 and s2') |
32 |
| -plt.grid(True) |
| 30 | +cxy, f = axs[1].cohere(s1, s2, 256, 1. / dt) |
| 31 | +axs[1].set_ylabel('coherence') |
33 | 32 |
|
34 |
| -plt.subplot(212) |
35 |
| -cxy, f = plt.cohere(s1, s2, 256, 1./dt) |
36 |
| -plt.ylabel('coherence') |
| 33 | +fig.tight_layout() |
37 | 34 | plt.show()
|
0 commit comments