-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCA2-Q3.py
More file actions
25 lines (21 loc) · 742 Bytes
/
CA2-Q3.py
File metadata and controls
25 lines (21 loc) · 742 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import spectrogram
# Creating sine wave
def plot_spectrogram(freq, fs=1000, duration=5):
t = np.linspace(0, duration, int(fs*duration), endpoint=False)
signal = np.sin(2 * np.pi * freq * t)
f, t_spec, Sxx = spectrogram(signal, fs)
plt.figure(figsize=(10, 4))
plt.pcolormesh(t_spec, f, 10 * np.log10(Sxx), shading='gouraud')
plt.title(f'f = {freq} Hz')
plt.ylabel('Frequency [Hz]')
plt.xlabel('Time [sec]')
plt.colorbar(label='Intensity [dB]')
plt.ylim(0, 300) # Create a domain
plt.show()
plot_spectrogram(5)
plot_spectrogram(20)
plot_spectrogram(50)
plot_spectrogram(100)
plot_spectrogram(200)