|
1 | | -#!/usr/bin/env python |
2 | | -from pylab import * |
| 1 | +import matplotlib.pyplot as plt |
| 2 | +import numpy as np |
3 | 3 |
|
4 | 4 | dt = 0.0005 |
5 | | -t = arange(0.0, 20.0, dt) |
6 | | -s1 = sin(2*pi*100*t) |
7 | | -s2 = 2*sin(2*pi*400*t) |
| 5 | +t = np.arange(0.0, 20.0, dt) |
| 6 | +s1 = np.sin(2*np.pi*100*t) |
| 7 | +s2 = 2*np.sin(2*np.pi*400*t) |
8 | 8 |
|
9 | 9 | # create a transient "chirp" |
10 | | -mask = where(logical_and(t > 10, t < 12), 1.0, 0.0) |
| 10 | +mask = np.where(np.logical_and(t > 10, t < 12), 1.0, 0.0) |
11 | 11 | s2 = s2 * mask |
12 | 12 |
|
13 | 13 | # add some noise into the mix |
14 | | -nse = 0.01*randn(len(t)) |
| 14 | +nse = 0.01*np.random.random(size=len(t)) |
15 | 15 |
|
16 | 16 | x = s1 + s2 + nse # the signal |
17 | 17 | NFFT = 1024 # the length of the windowing segments |
|
22 | 22 | # the power is computed, and im is the matplotlib.image.AxesImage |
23 | 23 | # instance |
24 | 24 |
|
25 | | -ax1 = subplot(211) |
26 | | -plot(t, x) |
27 | | -subplot(212, sharex=ax1) |
28 | | -Pxx, freqs, bins, im = specgram(x, NFFT=NFFT, Fs=Fs, noverlap=900, |
29 | | - cmap=cm.gist_heat) |
30 | | -show() |
| 25 | +ax1 = plt.subplot(211) |
| 26 | +plt.plot(t, x) |
| 27 | +plt.subplot(212, sharex=ax1) |
| 28 | +Pxx, freqs, bins, im = plt.specgram(x, NFFT=NFFT, Fs=Fs, noverlap=900, |
| 29 | + cmap=plt.cm.gist_heat) |
| 30 | +plt.show() |
0 commit comments