| 31 | |
| 32 | |
| 33 | def your_matplotlib_code(): |
| 34 | # Fixing random state for reproducibility |
| 35 | np.random.seed(19680801) |
| 36 | |
| 37 | dt = 0.0005 |
| 38 | t = np.arange(0.0, 20.0, dt) |
| 39 | s1 = np.sin(2 * np.pi * 100 * t) |
| 40 | s2 = 2 * np.sin(2 * np.pi * 400 * t) |
| 41 | |
| 42 | # create a transient "chirp" |
| 43 | s2[t <= 10] = s2[12 <= t] = 0 |
| 44 | |
| 45 | # add some noise into the mix |
| 46 | nse = 0.01 * np.random.random(size=len(t)) |
| 47 | |
| 48 | x = s1 + s2 + nse # the signal |
| 49 | NFFT = 1024 # the length of the windowing segments |
| 50 | Fs = int(1.0 / dt) # the sampling frequency |
| 51 | |
| 52 | fig, (ax1, ax2) = plt.subplots(nrows=2) |
| 53 | ax1.plot(t, x) |
| 54 | Pxx, freqs, bins, im = ax2.specgram(x, NFFT=NFFT, Fs=Fs, noverlap=900) |
| 55 | |
| 56 | return fig |
| 57 | |
| 58 | |
| 59 | # 88888888b dP |