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

Skip to content

Commit 9f5c27f

Browse files
committed
Fix cohere-demo
1 parent 0dfd271 commit 9f5c27f

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

examples/pylab_examples/cohere_demo.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,28 @@
77
# Fixing random state for reproducibility
88
np.random.seed(19680801)
99

10-
11-
# make a little extra space between the subplots
12-
plt.subplots_adjust(wspace=0.5)
13-
1410
dt = 0.01
1511
t = np.arange(0, 30, dt)
1612
nse1 = np.random.randn(len(t)) # white noise 1
1713
nse2 = np.random.randn(len(t)) # white noise 2
18-
r = np.exp(-t/0.05)
14+
r = np.exp(-t / 0.05)
1915

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
2218

2319
# 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)
2629

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')
3332

34-
plt.subplot(212)
35-
cxy, f = plt.cohere(s1, s2, 256, 1./dt)
36-
plt.ylabel('coherence')
33+
fig.tight_layout()
3734
plt.show()

0 commit comments

Comments
 (0)