-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfast_fourier_transform2.py
More file actions
37 lines (30 loc) · 908 Bytes
/
fast_fourier_transform2.py
File metadata and controls
37 lines (30 loc) · 908 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
26
27
28
29
30
31
32
33
34
35
36
37
"""another Fourier transform example from I don't remember where"""
from numpy import sin, pi, arange
from pylab import plot, show, xlabel, ylabel, subplot
from scipy.fft import fft, ifft
def plotSpectrum(y, Fs):
"""
Plots a Single-Sided Amplitude Spectrum of y(t)
"""
n = len(y) # length of the signal
k = arange(n)
T = n / Fs
frq = k / T # two sides frequency range
frq = frq[range(n // 2)] # one side frequency range
Y = fft(y) / n # fft computing and normalization
Y = Y[range(n // 2)]
plot(frq, abs(Y), 'r') # plotting the spectrum
xlabel('Freq (Hz)')
ylabel('|Y(freq)|')
Fs = 150.0 # sampling rate
Ts = 1.0 / Fs # sampling interval
t = arange(0, 1, Ts) # time vector
ff = 5 # frequency of the signal
y = sin(2 * pi * ff * t)
subplot(2, 1, 1)
plot(t, y)
xlabel('Time')
ylabel('Amplitude')
subplot(2, 1, 2)
plotSpectrum(y, Fs)
show()