8000 2 new examples · matplotlib/matplotlib@e6cb8f4 · GitHub
[go: up one dir, main page]

Skip to content

Commit e6cb8f4

Browse files
committed
2 new examples
svn path=/trunk/matplotlib/; revision=88
1 parent c056b73 commit e6cb8f4

File tree

3 files changed

+74
-3
lines changed

3 files changed

+74
-3
lines changed

examples/csd_demo.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""
2+
Compute the cross spectral density of two signals
3+
"""
4+
from __future__ import division
5+
import sys
6+
from matplotlib.matlab import *
7+
8+
dt = 0.01
9+
t = arange(0, 30, dt)
10+
nse1 = randn(len(t)) # white noise 1
11+
nse2 = randn(len(t)) # white noise 2
12+
r = exp(divide(-t,0.05))
13+
14+
cnse1 = convolve(nse1, r, mode=2)*dt # colored noise 1
15+
cnse1 = cnse1[:len(t)]
16+
cnse2 = convolve(nse2, r, mode=2)*dt # colored noise 2
17+
cnse2 = cnse2[:len(t)]
18+
19+
# two signals with a coherent part and a random part
20+
s1 = 0.01*sin(2*pi*10*t) + cnse1
21+
s2 = 0.01*sin(2*pi*10*t) + cnse2
22+
23+
subplot(211)
24+
plot(t, s1, 'b-', t, s2, 'g-')
25+
set(gca(), 'xlim', [0,5])
26+
xlabel('time')
27+
ylabel('s1 and s2')
28+
29+
subplot(212)
30+
cxy, f = cohere(s1, s2, 256, 1/dt)
31+
show()
32+
33+

examples/figtext.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ def f(t):
1414
plot(t1, f(t1), 'bo', t2, f(t2), 'k')
1515
title('subplot 1')
1616
ylabel('Damped oscillation')
17-
figtitle = 'This is a somehwhat long figure title'
17+
figtitle = 'This is a somewhat long figure title'
1818
t = gcf().text(0.5, 0.95, figtitle,
19-
horizontalalignment='center', fontsize=20,)
19+
horizontalalignment='center', fontsize=16,)
2020

2121

2222
subplot(122)
@@ -25,6 +25,6 @@ def f(t):
2525
title('subplot 2')
2626
ylabel('Undamped')
2727

28-
#savefig('figtext')
28+
savefig('figtext')
2929
show()
3030

examples/psd_demo.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""
2+
Compute the power spectral density of a signal
3+
"""
4+
5+
from matplotlib.matlab import *
6+
7+
dt = 0.01
8+
t = arange(0,10,dt)
9+
nse = randn(len(t)) # white noise
10+
r = exp(-t/0.05)
11+
cnse = convolve(nse, r, mode=2)*dt # colored noise
12+
cnse = cnse[:len(t)]
13+
s = 0.1*sin(2*pi*t) + cnse
14+
figure(1)
15+
plot(t,s)
16+
17+
figure(2)
18+
psd(s, 512, 1/dt)
19+
savefig('psd_demo')
20+
show()
21+
22+
"""
23+
% compare with matlab
24+
dt = 0.01;
25+
t = [0:dt:10];
26+
s = sin(2*pi*t);
27+
nse = randn(size(t));
28+
r = exp(-t/0.05);
29+
cnse = conv(nse, r)*dt;
30+
cnse = cnse(1:length(t));
31+
s = 0.1*sin(2*pi*t) + cnse;
32+
figure(1)
33+
plot(t,s)
34+
35+
figure(2)
36+
psd(s, 512, 1/dt)
37+
savefig('psd_demo')
38+
"""

0 commit comments

Comments
 (0)
0