-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathexample_FFT.py
53 lines (39 loc) · 1.08 KB
/
example_FFT.py
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
#!/usr/bin/env python
#
# Example how to perform FFT analysis.
#
# Last revision: 21/06/2021
from __future__ import print_function, division
import numpy as np
import matplotlib.pyplot as plt
import pyLOM
## Parameters
Fs = 1000. # Sampling frequency
T = 1/Fs # Sampling period
L = 1500 # Number of samples
## Build a noisy signal
t = np.linspace(0,np.pi/2,L)#np.arange(L)*T
S = 0.7*np.sin(50*2.*np.pi*t) + np.sin(120*2.*np.pi*t)
X = S + 2*np.random.randn(t.size)
## Compute FFT in different ways
f1,p1 = pyLOM.math.fft(t,X)
f2,p2 = pyLOM.math.fft(t,X,equispaced=False)
## Plot
fig, ax = plt.subplots(3,1,figsize=(8,12),dpi=100,facecolor='w',edgecolor='k',gridspec_kw={'hspace':0.25,'wspace':0.25})
# Signal plot
ax[0].plot(1000*t,X,'k')
ax[0].set_xlim([0,50])
ax[0].set_xlabel('time [msec]')
ax[0].set_ylabel('Y(t)')
# FFT spectrum plot
ax[1].plot(f1,p1,'k')
ax[1].set_xlim([0,150])
ax[1].set_xlabel('f [Hz]')
ax[1].set_ylabel('|P1(f)|')
# FFT spectrum plot
ax[2].plot(f2,p2,'k')
ax[2].set_xlim([0,150])
ax[2].set_xlabel('f [Hz]')
ax[2].set_ylabel('|P1(f)|')
pyLOM.cr_info()
plt.show()