-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpectrogram.py
More file actions
92 lines (34 loc) · 1.08 KB
/
Copy pathSpectrogram.py
File metadata and controls
92 lines (34 loc) · 1.08 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# import the libraries
import matplotlib.pyplot as plot
import numpy as np
# Define the list of frequencies
frequencies = np.arange(5,105,5)
# Sampling Frequency
samplingFrequency = 400
# Create two ndarrays
s1 = np.empty([0]) # For samples
s2 = np.empty([0]) # For signal
# Start Value of the sample
start = 1
# Stop Value of the sample
stop = samplingFrequency+1
for frequency in frequencies:
sub1 = np.arange(start, stop, 1)
# Signal - Sine wave with varying frequency + Noise
sub2 = np.sin(2*np.pi*sub1*frequency*1/samplingFrequency)+np.random.randn(len(sub1))
s1 = np.append(s1, sub1)
s2 = np.append(s2, sub2)
start = stop+1
stop = start+samplingFrequency
# Plot the signal
plot.subplot(211)
plot.plot(s1,s2)
plot.xlabel('Sample')
plot.ylabel('Amplitude')
# Plot the spectrogram
plot.subplot(212)
powerSpectrum, freqenciesFound, time, imageAxis = plot.specgram(s2, Fs=samplingFrequency)
plot.xlabel('Time')
plot.ylabel('Frequency')
print(powerSpectrum[[0,1],1])
plot.show()