0% found this document useful (0 votes)
20 views51 pages

07 - 231122 - Advanced - Numerical - Analysis-Fourier Analysis

This 3-sentence summary provides the high level information about the document: The document discusses advanced numerical methods for Fourier analysis with engineering applications. It covers topics such as periodic functions, Fourier series, the Fourier transform, discrete Fourier transform (DFT), and fast Fourier transform (FFT). MATLAB functions for computing the discrete Fourier transform and inverse discrete Fourier transform are also presented.

Uploaded by

Đăng Duy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views51 pages

07 - 231122 - Advanced - Numerical - Analysis-Fourier Analysis

This 3-sentence summary provides the high level information about the document: The document discusses advanced numerical methods for Fourier analysis with engineering applications. It covers topics such as periodic functions, Fourier series, the Fourier transform, discrete Fourier transform (DFT), and fast Fourier transform (FFT). MATLAB functions for computing the discrete Fourier transform and inverse discrete Fourier transform are also presented.

Uploaded by

Đăng Duy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 51

MN7500124: Advanced Numerical Methods

with Engineering Applications


Fourier transform

Autumn, 2023

June Kee Min


1/50

Theory
Periodic functions(1) 2/50

• A periodic function

ℎ(𝑡𝑡) = ℎ(𝑡𝑡 + 𝑇𝑇)

𝑇𝑇 : period [sec]
𝑓𝑓 = 1/𝑇𝑇 : frequency [Hz]=[1/sec]

• Sinusoids
ℎ(𝑡𝑡) = 𝐴𝐴0 + 𝐶𝐶1 cos( 𝜔𝜔0 𝑡𝑡 + 𝜃𝜃) h(t)

Mean Angular Phase


value Amplitude
frequency shift

2𝜋𝜋
𝜔𝜔 = 2𝜋𝜋𝜋𝜋 = [rad/sec]
𝑇𝑇
Periodic functions(2) 3/50

• Alternative Representation
ℎ(𝑡𝑡) = 𝐴𝐴0 + 𝐴𝐴1 cos( 𝜔𝜔0 𝑡𝑡) + 𝐵𝐵1 sin( 𝜔𝜔0 𝑡𝑡)
ℎ(𝑡𝑡) = 𝐴𝐴0 + 𝐶𝐶1 cos( 𝜔𝜔0 𝑡𝑡 + 𝜃𝜃)

ℎ(𝑡𝑡) = 𝐴𝐴0 + 𝐴𝐴1 cos( 𝜔𝜔0 𝑡𝑡) + 𝐵𝐵1 sin( 𝜔𝜔0 𝑡𝑡)

where

𝐶𝐶1 = 𝐴𝐴12 + 𝐵𝐵12

𝐵𝐵1
𝜃𝜃 = tan−1 −
𝐴𝐴1
Fourier series(1) 4/50

Fourier series of square wave


• Continuous Fourier Series

- For an periodic function


ℎ(𝑡𝑡) = 𝑎𝑎0 + � 𝑎𝑎𝑘𝑘 cos( 𝑘𝑘𝜔𝜔0 𝑡𝑡) + 𝑏𝑏𝑘𝑘 sin( 𝑘𝑘𝜔𝜔0 𝑡𝑡)
𝑘𝑘=1

where

2 𝑇𝑇
𝑎𝑎𝑘𝑘 = � ℎ(𝑡𝑡) cos( 𝑘𝑘𝜔𝜔0 𝑡𝑡)𝑑𝑑𝑑𝑑
𝑇𝑇 0

2 𝑇𝑇
𝑏𝑏𝑘𝑘 = � ℎ(𝑡𝑡) sin( 𝑘𝑘𝜔𝜔0 𝑡𝑡)𝑑𝑑𝑑𝑑
𝑇𝑇 0

𝜔𝜔0 = 2𝜋𝜋/𝑇𝑇 : fundamental frequency

2𝜔𝜔0 , 3𝜔𝜔0 , ⋯ : harmonics


Fourier series(2) 5/50

• Euler’s formula: compact form

𝑒𝑒 ±𝑖𝑖𝑖𝑖 = cos( 𝑥𝑥) ± 𝑖𝑖 sin( 𝑥𝑥)

Then

ℎ(𝑡𝑡) = � 𝑐𝑐̃𝑘𝑘 𝑒𝑒 𝑖𝑖𝑖𝑖𝜔𝜔0 𝑡𝑡


𝑘𝑘=−∞

where
2 𝑇𝑇/2
𝑐𝑐𝑘𝑘̃ = � ℎ(𝑡𝑡)𝑒𝑒 −𝑖𝑖𝑖𝑖𝜔𝜔0 𝑡𝑡 𝑑𝑑𝑑𝑑 : complex number
𝑇𝑇 −𝑇𝑇/2
Frequency and time domains 6/50

ℎ(𝑡𝑡)

𝜋𝜋
ℎ(𝑡𝑡) = 𝐶𝐶1 cos( 𝑡𝑡 + )
2

ℎ(𝑡𝑡)

Amplitude: 𝐶𝐶1
Angular frequency: 𝜔𝜔0 = 1

Frequency: 𝑓𝑓 = 𝜔𝜔/2𝜋𝜋 = 1/2𝜋𝜋


Period:
𝑇𝑇 = 1/𝑓𝑓 = 2𝜋𝜋
Phase shift: 𝜃𝜃 = 𝜋𝜋/2
Fourier Transform 7/50

• A physical problem
Time domain Frequency domain
(Power spectrum)
Fourier transform

𝐻𝐻(𝑓𝑓)
ℎ(𝑡𝑡)

Inverse Fourier
transform

𝑡𝑡 [sec] 𝑓𝑓 [Hz]

• Fourier transform:
+∞ +∞
𝐻𝐻(𝑓𝑓) = � ℎ(𝑡𝑡)𝑒𝑒 2𝜋𝜋𝜋𝜋𝜋𝜋𝜋𝜋 𝑑𝑑𝑑𝑑 or 𝐻𝐻(𝜔𝜔) = � ℎ(𝑡𝑡)𝑒𝑒 𝑖𝑖𝑖𝑖𝑖𝑖 𝑑𝑑𝑑𝑑
−∞ −∞

• Inverse Fourier transform:


+∞
1 +∞
ℎ(𝑡𝑡) = � 𝐻𝐻(𝑓𝑓)𝑒𝑒 −2𝜋𝜋𝜋𝜋𝜋𝜋𝜋𝜋
𝑑𝑑𝑑𝑑 or ℎ(𝑡𝑡) = � 𝐻𝐻(𝜔𝜔)𝑒𝑒 −𝑖𝑖𝑖𝑖𝑖𝑖 𝑑𝑑𝑑𝑑
−∞ 2𝜋𝜋 −∞
DFT: Discrete Fourier Transform(1) 8/50

• An engineering data

h(t) Evenly spaced discrete data


h2 h3
h1

h0 hN-1

t1 t2 tN-1 tN=T

Δ𝑡𝑡 : time interval


1
Δ𝑡𝑡
: sampling rate (frequency)

ℎ𝑛𝑛 = ℎ(𝑛𝑛𝑛𝑛𝑛) 𝑛𝑛 = ⋯ , −3, −2, −1, 0, 1, 2, ⋯


DFT: Discrete Fourier Transform(2) 9/50

• Nyquist critical frequency


: The highest detectable frequency Sine wave of frequency 𝑓𝑓𝑐𝑐
Δ𝑡𝑡
1 1
𝑓𝑓𝑐𝑐 = 𝑓𝑓max = = 𝑓𝑓
2Δ𝑡𝑡 2 𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠

cf) The lowest detectable frequency (except DC component i.e. 𝑓𝑓 = 0 Hz)


1 1 1 𝑓𝑓𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠
𝑓𝑓min = = = ∆𝑓𝑓 = =
Total sampling time 𝑡𝑡𝑁𝑁 𝑁𝑁 × Δ𝑡𝑡 𝑁𝑁

• Sampling theorem
“ℎ(𝑡𝑡) is bandwidth limited to frequencies smaller than 𝑓𝑓𝑐𝑐 ”
(Cannot detect higher frequency than 𝑓𝑓𝑐𝑐 )
DFT: Discrete Fourier Transform(3) 10/50

• Aliasing: false translation


- All the power spectral density that lies
outside of the range −𝑓𝑓𝑐𝑐 < 𝑓𝑓 < 𝑓𝑓𝑐𝑐 is Δ𝑡𝑡
spuriously moved into that range.

• To prevent aliasing

- Use sufficiently small Δ𝑡𝑡 (high frequency)


- Enforce a known limit by analog filtering
(ex: High-pass filtering etc.)

1 1

2Δ𝑡𝑡 2Δ𝑡𝑡
DFT: Discrete Fourier Transform(4) 11/50

• DFT: +∞
𝐻𝐻(𝑓𝑓𝑛𝑛 ) = � ℎ(𝑡𝑡)𝑒𝑒 2𝜋𝜋𝜋𝜋𝑓𝑓𝑛𝑛 𝑡𝑡 𝑑𝑑𝑑𝑑
−∞
𝑁𝑁−1 𝑁𝑁−1

≈ � ℎ𝑘𝑘 𝑒𝑒 2𝜋𝜋𝜋𝜋𝑓𝑓𝑛𝑛 𝑡𝑡𝑘𝑘 Δ𝑡𝑡 = Δ𝑡𝑡 � ℎ𝑘𝑘 𝑒𝑒 2𝜋𝜋𝜋𝜋𝜋𝜋𝜋𝜋/𝑁𝑁


𝑘𝑘=0 𝑘𝑘=0

𝑁𝑁−1
𝑛𝑛
𝐻𝐻𝑛𝑛 ≡ � ℎ𝑘𝑘 𝑒𝑒 2𝜋𝜋𝜋𝜋𝜋𝜋𝜋𝜋/𝑁𝑁 𝑓𝑓𝑛𝑛 ≡
𝑁𝑁
𝑘𝑘=0

𝐻𝐻(𝑓𝑓𝑛𝑛 ) = Δ𝑡𝑡𝐻𝐻𝑛𝑛

• Inverse DFT:
𝑁𝑁−1
1
ℎ𝑘𝑘 = � 𝐻𝐻𝑛𝑛 𝑒𝑒 −2𝜋𝜋𝜋𝜋𝜋𝜋𝜋𝜋/𝑁𝑁
𝑁𝑁
𝑛𝑛=0
FFT: Fast Fourier Transform(1) 12/50

• Danielson & Lanczos(1942), Cooley & Tukey(mid 1960s)


𝑊𝑊 ≡ 𝑒𝑒 2𝜋𝜋𝜋𝜋/𝑁𝑁
𝑁𝑁−1

𝐻𝐻𝑛𝑛 = � 𝑊𝑊 𝑛𝑛𝑛𝑛 ℎ𝑘𝑘


𝑘𝑘=0
𝑁𝑁−1

𝐹𝐹𝑘𝑘 = � 𝑒𝑒 2𝜋𝜋𝜋𝜋𝜋𝜋𝜋𝜋/𝑁𝑁 𝑓𝑓𝑗𝑗


𝑗𝑗=0
𝑁𝑁/2−1 𝑁𝑁/2−1

= � 𝑒𝑒 2𝜋𝜋𝜋𝜋(2𝑗𝑗)𝑘𝑘/𝑁𝑁 𝑓𝑓2𝑗𝑗 + � 𝑒𝑒 2𝜋𝜋𝜋𝜋(2𝑗𝑗+1)𝑘𝑘/𝑁𝑁 𝑓𝑓2𝑗𝑗+1


𝑗𝑗=0 𝑗𝑗=0
𝑁𝑁/2−1 𝑁𝑁/2−1

= � 𝑒𝑒 2𝜋𝜋𝜋𝜋𝜋𝜋𝜋𝜋/(𝑁𝑁/2) 𝑓𝑓2𝑗𝑗 + 𝑊𝑊 𝑘𝑘 � 𝑒𝑒 2𝜋𝜋𝜋𝜋𝜋𝜋𝜋𝜋/(𝑁𝑁/2) 𝑓𝑓2𝑗𝑗+1


𝑗𝑗=0 𝑗𝑗=0
= 𝐹𝐹𝑘𝑘𝑒𝑒 + 𝑊𝑊 𝑘𝑘 𝐹𝐹𝑘𝑘0

Divided recursively
FFT: Fast Fourier Transform(2) 13/50

• Operation count

DFT: O(N2) N (N-1)2 (N/2)log2N


Operations

256 65,025 1,024


1,024 1,046,529 5,120
4,096 16,769,025 24,576

Samples (N)
FFT: Fast Fourier Transform(3) 14/50

• Restriction
1. Use N only powers of 2 (N = 2n = … 512, 1024, 2048 …)
2. If N is not power of 2, pad it with zero’s up to the next power of 2
15/50

MATLAB

Ch 16. Fourier Analysis


MATLAB functions 16/50

• MATLAB functions fft and ifft

Y = fft(X) : DFT(FFT) of vector X Y: stored in reverse-wrap-around order


Y = fft(X,n) : n-point DFT of vector X (ex: if N=8 k= 0, 1, 2, 3, 4,-3,-2,-1)

k=0 DC (neglect)


y = ifft(X) : Inverse DFT of vector X
k=1 fmin Even space
y = ifft(X,n) : n-point Inverse DFT of vector X k=4 fc
Exercise-1 (1) 17/50

• Prob: Conduct FFT using N=8 points and Δt=0.02 sec.

ℎ(𝑡𝑡) = 5 + cos( 2𝜋𝜋(12.5) t) + sin( 2𝜋𝜋(18.75) t)

DC component 1st freq. 2nd freq.


(f = 0 Hz) (f = 12.5 Hz) (f = 18.75 Hz)

1 1
• Sampling frequency: 𝑓𝑓𝑠𝑠 = = = 50 Hz
Δ𝑡𝑡 0.02

• Total sampling time 𝑡𝑡𝑁𝑁 = Δ𝑡𝑡 × 8 = 0.02 × 8 = 0.16 sec

• Nyquist critical frequency (The highest detectable frequency)


1 1
𝑓𝑓𝑐𝑐 = 𝑓𝑓max = = =25 Hz
2Δ𝑡𝑡 2 × 0.02
• The lowest detectable frequency
1 1
𝑓𝑓min = = = 6.25 Hz
𝑡𝑡𝑁𝑁 0.16
Exercise-1 (2) 18/50

• Script • Results
(a) f(t) versus time (s)
10
% [1] Data plot
n=8; dt=0.02; fs=1/dt; T = 0.16; 5
tspan=(0:n-1)/fs; 0
y=5+cos(2*pi*12.5*tspan)+sin(2*pi*31.25*tspan); 0 0.02 0.04 0.06 0.08 0.1 0.12 0.14
subplot(3,1,1);
plot(tspan,y,'-ok','linewidth',2,'MarkerFaceColor','black');
(b) Real component versus frequency
title('(a) f(t) versus time (s)');
0.5
% [2] Do the FFT 0
Divide by n in order for that the 1st coefficient is (f = 12.5 Hz)
Y=fft(y)/n; -0.5
Y' equal to the mean of the samples. (not important) 5 10 15 20 25

% [3] Plot Real Part


nyquist=fs/2;fmin=1/T; Available frequencies: fmin – fc, n/2 points (b) Imaginary component versus frequency
f = linspace(fmin,nyquist,n/2); 1 (f = 18.75 Hz)
Y(1)=[];YP=Y(1:n/2); Delete k=0 (DC), and take only positive k 0.5
subplot(3,1,2) 0
stem(f,real(YP),'linewidth',2,'MarkerFaceColor','blue') 5 10 15 20 25
grid;title('(b) Real component versus frequency') frequency (Hz)
% [4] Plot Imaginary Part ans =
subplot(3,1,3)
stem(f,imag(YP),'linewidth',2,'MarkerFaceColor','blue') 5.0000 + 0.0000i
grid;title('(b) Imaginary component versus frequency') 0.0000 - 0.0000i
xlabel('frequency (Hz)') 0.5000 - 0.0000i
-0.0000 - 0.5000i
0.0000 + 0.0000i
-0.0000 + 0.5000i
0.5000 + 0.0000i
0.0000 + 0.0000i
The Power Spectrum 19/50

• Power
2
𝑃𝑃𝑘𝑘 = 𝑐𝑐̃𝑘𝑘

Fourier coefficients (for k-th frequency)


• Power Spectrum
A plot of the power versus frequency (Most popular plot)
Power spectrum

• Example-1
0.25

% [5] Power spectrum 0.2

%f = (1:n/2)/(n/2)*nyquist;
Pyy = abs(Y(1:n/2)).^2; Calculate Power 0.15
figure
stem(f,Pyy,'linewidth',2,'MarkerFaceColor','blue')
0.1
title('Power spectrum')
xlabel('Frequency (Hz)');grid; ylim([0 0.3])
0.05

0
6 8 10 12 14 16 18 20 22 24 26
Frequency (Hz)
Exercise-2 20/50

Conduct FFT using N=64 points and t=0 to 2π sec. 2.5

ℎ(𝑡𝑡) = cos( 10 t) + sin( 3 t) + random 1.5

0.5

10 3
• Hint
0

ℎ(𝑡𝑡) = cos 2𝜋𝜋 t + sin 2𝜋𝜋 t + random


2𝜋𝜋 2𝜋𝜋 -0.5

-1

-1.5

ℎ(𝑡𝑡) = cos 2𝜋𝜋 1.5915 t + sin 2𝜋𝜋 0.47746 t + random


0 1 2 3 4 5 6 7

• Script
noise
0.25
% [1] Data plot
n = 64; tn = 2*pi;
dt=tn/n; fs=1/dt; t=(0:n-1)/fs;
0.2
y=cos(10.*t)+sin(3*t)+rand(1,n);
plot(t,y,'-o');grid; pause;
0.15
% [2] Do the FFT & Power
Y=fft(y)/n;
Y(1)=[];YP=Y(1:n/2); 0.1
Pyy = abs(Y).^2;

% [3] Frequency & Plot 0.05


fc = 1./dt/2.;
fmin = 1./tn;
f=linspace(fmin,fc,n/2) 0
0 1 2 3 4 5 6
plot(f,Pyy(1:n/2),'-o'); grid; pause;
21/50

MS Excel
1) Basic
2) DC component
3) De-trending
4) Window
5) Aliasing
6) Square wave
Usage 22/50

• (Enabling) Excel Options – Add-ins – Manage – Analysis ToolPak

• (Run FFT) Data – Data Analysis – Fourier Analysis

(Limit) maximum N = 4096


Basic (1) 23/50

• FFT
N 256 (Excel limit : 4096)
dt
f
0.01 s
100 Hz
Sampling dt
Sampling freq
ℎ(𝑡𝑡) = sin 2𝜋𝜋 2 t + sin 2𝜋𝜋 5 t
df 0.391 Hz df
t_max 3.2 s t_max = dt
Nyquist f 50.0 Hz Critical freq f_c = 1/(2*dt)

No t h(t) FA Abs Freq Amp


h(t)
1 0.00 0.00E+00 4.46856235714709 4.468562 0.000 0.034911
2.50E+00
2 0.01 4.34E-01 4.56760703277497-0.867637590704403i 4.649283 0.391 0.036323
2.00E+00
3 0.02 8.36E-01 4.91196208713486-2.0251088833857i 5.313044 0.781 0.041508
1.50E+00
4 0.03 1.18E+00 5.72401324767166-4.10820576375805i 7.045685 1.172 0.055044
1.00E+00
5 0.04 1.43E+00 8.08503453377628-9.8715782428769i 12.759931 1.563 0.099687
5.00E-01
6 0.05 1.59E+00 49.2650991659593-113.436071204176i 123.672116 1.953 0.966188
0.00E+00
7 0.06 1.64E+00 -2.84668073049086+18.9232057113436i 19.136126 2.344 0.149501 0.00 0.50 1.00 1.50 2.00 2.50 3.00
-5.00E-01
8 0.07 1.58E+00 0.768845638121891+10.9342556756248i 10.961253 2.734 0.085635
-1.00E+00
9 0.08 1.43E+00 2.22532149025346+9.01446004894544i 9.285071 3.125 0.07254
-1.50E+00
10 0.09 1.21E+00 3.43031715477655+8.7966942488608i 9.441870 3.516 0.073765
-2.00E+00
11 0.10 9.51E-01 4.99071705538393+9.85533063402072i 11.046936 3.906 0.086304
-2.50E+00
12 0.11 6.73E-01 7.92750461458817+13.1925741956768i 15.391210 4.297 0.120244
13 0.12 4.10E-01 17.7955285862186+26.2854000590281i 31.742764 4.688 0.24799
14 0.13 1.89E-01 -70.1211311045021-95.0782221367765i 118.139076 5.078 0.922962 Amp
15 0.14 3.12E-02 -11.426078403635-14.5610060060202i 18.508867 5.469 0.144601 1.2

16 0.15 -4.89E-02 -6.06436850946559-7.3907196923702i 9.560298 5.859 0.07469


1
17 0.16 -4.62E-02 -4.04408339409351-4.77641561173909i 6.258495 6.250 0.048894
18 0.17 3.53E-02 -2.98224234284109-3.44944983890959i 4.559876 6.641 0.035624 0.8

19 0.18 1.83E-01 -2.32778114208853-2.65906556962952i 3.534005 7.031 0.027609


0.6
20 0.19 3.76E-01 -1.88457465441206-2.14078355686598i 2.852118 7.422 0.022282
21 0.20 5.88E-01 -1.56513903056184-1.77816306367483i 2.368866 7.813 0.018507 0.4
22 0.21 7.91E-01 -1.32448654352554-1.51223382283653i 2.010253 8.203 0.015705
0.2
23 0.22 9.56E-01 -1.13708510790446-1.3100880732933i 1.734731 8.594 0.013553
24 0.23 1.06E+00 -0.987353023854652-1.15199977152452i 1.517224 8.984 0.011853 0
0.000 10.000 20.000 30.000 40.000 50.000 60.000
25 0.24 1.08E+00 -0.865235745982687-1.02547416480666i 1.341727 9.375 0.010482
26 0.25 1.00E+00 -0.763952175817764-0.922241730395136i 1.197561 9.766 0.009356
27 0.26 8.26E-01 -0.678761887276836-0.836629593373963i 1.077342 10.156 0.008417
28 0.27 5.60E-01 -0.606251115866456-0.764628133069382i 0.975806 10.547 0.007623
29 0.28 2.20E-01 -0.543899265918856-0.703330638103671i 0.889101 10.938 0.006946
30 0.29 -1.73E-01 -0.489805125612729-0.650583568764188i 0.814351 11.328 0.006362
Basic (2) 24/50

• FFT
N 32 (Excel limit : 4096)
dt
f
0.1 s
10 Hz Sampling freq
ℎ(𝑡𝑡) = sin 2𝜋𝜋 1 t
df 0.3125 Hz df
t_max 3.2 s t_max = dt
Nyquist f 5.0 Hz Critical freq f_c = 1/(2*dt)

No t h(t) FA Abs Freq Amp h(t)


1 0.0 0.00E+00 0.587785252292474 0.587785 0.000 0.036737
1.50E+00
2 0.1 5.88E-01 0.706731953217216-0.540093652646119i 0.889478 0.313 0.055592
3 0.2 9.51E-01 1.29245296045061-1.58430058195741i 2.044613 0.625 0.127788 1.00E+00
4 0.3 9.51E-01 8.56906559725113-11.7665274507577i 14.556100 0.938 0.909756
5.00E-01
5 0.4 5.88E-01 -2.46821185473808+3.29946573029299i 4.120503 1.250 0.257531
6 0.5 1.23E-16 -1.27678059634907+1.56004083195412i 2.015911 1.563 0.125994 0.00E+00
7 0.6 -5.88E-01 -0.951856720744358+1.03048613569656i 1.402830 1.875 0.087677 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5
8 0.7 -9.51E-01 -0.806308495085828+0.759685377758503i 1.107816 2.188 0.069238 -5.00E-01
9 0.8 -9.51E-01 -0.72654252800536+0.587785252292474i 0.934535 2.500 0.058408
-1.00E+00
10 0.9 -5.88E-01 -0.677772387664975+0.464483335987646i 0.821657 2.813 0.051354
11 1.0 -2.45E-16 -0.645935858572028+0.368658779484626i 0.743735 3.125 0.046483 -1.50E+00
12 1.1 5.88E-01 -0.62434601495254+0.289748642302477i 0.688304 3.438 0.043019
13 1.2 9.51E-01 -0.609471682437164+0.22178219311774i 0.648570 3.750 0.040536
Amp
14 1.3 9.51E-01 -0.599317632177802+0.161043280762609i 0.620578 4.063 0.038786
1
15 1.4 5.88E-01 -0.592716334293394+0.10501307100055i 0.601947 4.375 0.037622
0.9
16 1.5 3.68E-16 -0.588990405898356+5.18330780539882E-002i 0.591267 4.688 0.036954 0.8
17 1.6 -5.88E-01 -0.587785252292473 0.587785 5.000 0.036737 0.7
18 1.7 -9.51E-01 -0.588990405898358-5.1833078053985E-002i 0.591267 5.313 0.036954 0.6
19 1.8 -9.51E-01 -0.592716334293394-0.105013071000548i 0.601947 5.625 0.037622 0.5
20 1.9 -5.88E-01 -0.599317632177796-0.161043280762601i 0.620578 5.938 0.038786 0.4
21 2.0 -4.90E-16 -0.609471682437165-0.221782193117741i 0.648570 6.250 0.040536 0.3

22 2.1 5.88E-01 -0.624346014952549-0.289748642302476i 0.688304 6.563 0.043019 0.2


0.1
23 2.2 9.51E-01 -0.645935858572031-0.368658779484624i 0.743735 6.875 0.046483
0
24 2.3 9.51E-01 -0.677772387664978-0.464483335987644i 0.821657 7.188 0.051354
0.000 1.000 2.000 3.000 4.000 5.000 6.000
25 2.4 5.88E-01 -0.726542528005361-0.587785252292474i 0.934535 7.500 0.058408
26 2.5 6.13E-16 -0.806308495085837-0.759685377758503i 1.107816 7.813 0.069238
27 2.6 -5.88E-01 -0.951856720744362-1.03048613569656i 1.402830 8.125 0.087677
28 2.7 -9.51E-01 -1.27678059634908-1.56004083195412i 2.015911 8.438 0.125994
29 2.8 -9.51E-01 -2.46821185473809-3.29946573029299i 4.120503 8.750 0.257531
30 2.9 -5.88E-01 8.56906559725116+11.7665274507577i 14.556100 9.063 0.909756
31 3.0 -7.35E-16 1.29245296045061+1.5843005819574i 2.044613 9.375 0.127788
32 3.1 5.88E-01 0.706731953217217+0.540093652646126i 0.889478 9.688 0.055592
Basic (3) 25/50

• Inverse FFT
N 32 (Excel limit : 4096)
dt 0.1 s ℎ(𝑡𝑡) = sin 2𝜋𝜋 1 t
f 10 Hz Sampling freq
df 0.3125 Hz df
t_max 3.2 s t_max = dt
Nyquist f 5.0 Hz Critical freq f_c = 1/(2*dt)

i t h(t) FA Abs Freq Amp iFFT(FA) h(t) iFFT(FA)


1 0.0 0.00E+00 0.587785252292474 0.587785 0 0.036737 0 1.50E+00
2 0.1 5.88E-01 0.706731953217216-0.540093652646119i 0.889478 0.3125 0.055592 0.587785
3 0.2 9.51E-01 1.29245296045061-1.58430058195741i 2.044613 0.6250 0.127788 0.951057 1.00E+00
4 0.3 9.51E-01 8.56906559725113-11.7665274507577i 14.556100 0.9375 0.909756 0.951057
5.00E-01
5 0.4 5.88E-01 -2.46821185473808+3.29946573029299i 4.120503 1.2500 0.257531 0.587785
6 0.5 1.23E-16 -1.27678059634907+1.56004083195412i 2.015911 1.5625 0.125994 0 0.00E+00
7 0.6 -5.88E-01 -0.951856720744358+1.03048613569656i 1.402830 1.8750 0.087677 -0.58779 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5
8 0.7 -9.51E-01 -0.806308495085828+0.759685377758503i 1.107816 2.1875 0.069238 -0.95106 -5.00E-01
9 0.8 -9.51E-01 -0.72654252800536+0.587785252292474i 0.934535 2.5000 0.058408 -0.95106
-1.00E+00
10 0.9 -5.88E-01 -0.677772387664975+0.464483335987646i 0.821657 2.8125 0.051354 -0.58779
11 1.0 -2.45E-16 -0.645935858572028+0.368658779484626i 0.743735 3.1250 0.046483 0
-1.50E+00
12 1.1 5.88E-01 -0.62434601495254+0.289748642302477i 0.688304 3.4375 0.043019 0.587785
13 1.2 9.51E-01 -0.609471682437164+0.22178219311774i 0.648570 3.7500 0.040536 0.951057
14 1.3 9.51E-01 -0.599317632177802+0.161043280762609i 0.620578 4.0625 0.038786 0.951057 Amp
15 1.4 5.88E-01 -0.592716334293394+0.10501307100055i 0.601947 4.3750 0.037622 0.587785 1
16 1.5 3.68E-16 -0.588990405898356+5.18330780539882E-002i 0.591267 4.6875 0.036954 0 0.9

17 1.6 -5.88E-01 -0.587785252292473 0.587785 5.0000 0.036737 -0.58779 0.8

18 1.7 -9.51E-01 -0.588990405898358-5.1833078053985E-002i 0.591267 5.3125 0.036954 -0.95106 0.7


0.6
19 1.8 -9.51E-01 -0.592716334293394-0.105013071000548i 0.601947 5.6250 0.037622 -0.95106
0.5
20 1.9 -5.88E-01 -0.599317632177796-0.161043280762601i 0.620578 5.9375 0.038786 -0.58779
0.4
21 2.0 -4.90E-16 -0.609471682437165-0.221782193117741i 0.648570 6.2500 0.040536 0
0.3
22 2.1 5.88E-01 -0.624346014952549-0.289748642302476i 0.688304 6.5625 0.043019 0.587785
0.2
23 2.2 9.51E-01 -0.645935858572031-0.368658779484624i 0.743735 6.8750 0.046483 0.951057 0.1
24 2.3 9.51E-01 -0.677772387664978-0.464483335987644i 0.821657 7.1875 0.051354 0.951057 0
25 2.4 5.88E-01 -0.726542528005361-0.587785252292474i 0.934535 7.5000 0.058408 0.587785 0 1 2 3 4 5 6

26 2.5 6.13E-16 -0.806308495085837-0.759685377758503i 1.107816 7.8125 0.069238 0


27 2.6 -5.88E-01 -0.951856720744362-1.03048613569656i 1.402830 8.1250 0.087677 -0.58779
28 2.7 -9.51E-01 -1.27678059634908-1.56004083195412i 2.015911 8.4375 0.125994 -0.95106
29 2.8 -9.51E-01 -2.46821185473809-3.29946573029299i 4.120503 8.7500 0.257531 -0.95106
30 2.9 -5.88E-01 8.56906559725116+11.7665274507577i 14.556100 9.0625 0.909756 -0.58779
31 3.0 -7.35E-16 1.29245296045061+1.5843005819574i 2.044613 9.3750 0.127788 0
32 3.1 5.88E-01 0.706731953217217+0.540093652646126i 0.889478 9.6875 0.055592 0.587785
DC component 26/50

• Removal of DC component

ℎ 𝑡𝑡 = sin 2𝜋𝜋𝜋𝜋 + 5.0

ℎ 𝑡𝑡

ℎ 𝑡𝑡 = sin 2𝜋𝜋𝜋𝜋
De-trending 27/50

• De-trending using the LS fit ( No t e ) It is n e ce s s a ry t o u s e it p rop e rly a ccord in g t o t h e


p u rp os e a n d a p p lica t ion . Be ca u s e t h is t re n d m a y
con t a in im p ort a n t in form a t ion .

ℎ 𝑡𝑡 = sin 2𝜋𝜋𝜋𝜋 + 𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡


Window (1) 28/50

• Error occurred

ℎ(𝑡𝑡) = sin 2𝜋𝜋𝜋𝜋

Errors

• Cause of error

FFT assumption (periodicity)


Window (2) 29/50
𝑤𝑤ℎ𝑎𝑎𝑎𝑎 𝑡𝑡 = 0.5 − 0.5 cos 2𝜋𝜋𝜋𝜋/𝑡𝑡𝑚𝑚𝑚𝑚𝑚𝑚
• Hann and Hamming window functions 𝑤𝑤ℎ𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎𝑎 𝑡𝑡 = 0.54 − 0.46 cos 2𝜋𝜋𝜋𝜋/𝑡𝑡𝑚𝑚𝑚𝑚𝑚𝑚
Window functions
ℎ(𝑡𝑡) = sin 2𝜋𝜋𝜋𝜋

ℎ(𝑡𝑡) × 𝑤𝑤 𝑡𝑡 Power spectrum


Aliasing 30/50

• 𝑓𝑓𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠 = 3 Hz (𝑓𝑓𝑐𝑐 = 1.5 Hz > 𝑓𝑓𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠 = 1 Hz)


ℎ(𝑡𝑡) = sin 2𝜋𝜋𝜋𝜋

• 𝑓𝑓𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠 = 1.5 Hz (𝑓𝑓𝑐𝑐 = 0.75 Hz < 𝑓𝑓𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠 = 1 Hz)


Square wave (1) 31/50

• Square wave

𝐴𝐴0 0 ≤ 𝑡𝑡 < 𝑇𝑇/2 ∞


ℎ(𝑡𝑡) = � 4𝐴𝐴0 2𝜋𝜋 2𝑛𝑛 − 1 𝑡𝑡
ℎ(𝑡𝑡) = � 𝑠𝑠𝑠𝑠𝑠𝑠
−𝐴𝐴0 𝑇𝑇/2 ≤ 𝑡𝑡 < 𝑇𝑇 (2𝑛𝑛 − 1)𝜋𝜋 𝑇𝑇
𝑛𝑛=1

𝐴𝐴0 = 1, 𝑇𝑇 = 0.25 𝑠𝑠 (𝑓𝑓 = 1/𝑇𝑇 = 4 𝐻𝐻𝐻𝐻)


Square wave (2) 32/50

• FFT results

4𝐴𝐴0 2𝜋𝜋 2𝑛𝑛 − 1 𝑡𝑡
ℎ(𝑡𝑡) = � 𝑠𝑠𝑠𝑠𝑠𝑠
(2𝑛𝑛 − 1)𝜋𝜋 𝑇𝑇
𝐴𝐴0 = 1, 𝑇𝑇 = 0.25 𝑠𝑠 (𝑓𝑓 = 4 𝐻𝐻𝐻𝐻) 𝑛𝑛=1
33/50

Filtering
1) Convolution theorem
2) Excel example
3) MATLAB example
Convolution 34/50

• Convolution integral

𝑓𝑓 ∗ 𝑔𝑔 𝑡𝑡 = � 𝑓𝑓 𝜏𝜏 𝑔𝑔 𝑡𝑡 − 𝜏𝜏 𝑑𝑑𝜏𝜏
−∞

Signal Filter (or kernel)

• Convolution theorem
+∞
Consider 𝐺𝐺 𝑓𝑓 = � 𝑔𝑔 𝑡𝑡 𝑒𝑒 2𝜋𝜋𝜋𝜋𝜋𝜋𝜋𝜋 𝑑𝑑𝑑𝑑 ≡ ℱ{𝑔𝑔} ℱ{}: Fourier transform operator
−∞
+∞
𝐻𝐻(𝑓𝑓) = � ℎ(𝑡𝑡)𝑒𝑒 2𝜋𝜋𝜋𝜋𝜋𝜋𝜋𝜋 𝑑𝑑𝑑𝑑 ≡ ℱ{ℎ}
−∞

Then or
ℱ{𝑔𝑔 ∗ ℎ} = 𝐺𝐺 𝑓𝑓 𝐻𝐻(𝑓𝑓)

(𝑔𝑔 ∗ ℎ) 𝑡𝑡 = ℱ −1 {𝐺𝐺 𝑓𝑓 𝐻𝐻(𝑓𝑓)}


Excel example : Dirac delta kernel (1) 35/50

• Dirac delta function

∞, 𝑥𝑥 = 0
𝛿𝛿(𝑡𝑡) = �
0, 𝑥𝑥 ≠ 0

∞, 𝑥𝑥 = 𝑇𝑇
𝛿𝛿(𝑡𝑡 − 𝑇𝑇) = �
0, 𝑥𝑥 ≠ 𝑇𝑇

� 𝛿𝛿 𝑡𝑡 𝑑𝑑𝑑𝑑 = 1
−∞

ℱ{𝛿𝛿} = 1

ℱ 𝑔𝑔 ∗ 𝛿𝛿 = ℱ 𝑔𝑔 ℱ 𝛿𝛿 = ℱ 𝑔𝑔


𝑔𝑔 ∗ 𝛿𝛿 𝑡𝑡 = � 𝑔𝑔 𝜏𝜏 𝛿𝛿 𝑡𝑡 − 𝜏𝜏 𝑑𝑑𝜏𝜏
−∞
Excel example : Dirac delta kernel (2) 36/50
Normalized time
Shift 1 Shifted kernel 𝛿𝛿(𝑡𝑡 − 1)
t Kernel h(t) FFT Kernel FFT h(t) Product iFFT t-shift
0 0 0.3 1 15.9666565654047 15.9666565654047 0.3 -1
1 1 0.3 0.98078528040323-0.195090322016128i -5.09158170779648-1.01277857120476i -5.1913316905645-8.88178419700125E-16i 0.3 0
2 0 0.3 0.923879532511287-0.38268343236509i 2.41120380085125+0.998753315958139i 2.60986818735677-4.21884749357559E-15i 0.3 1
3 0 0.3 0.831469612302545-0.555570233019602i -0.387870541381202-0.25916681002911i -0.466487933704626+2.13717932240343E-15i 0.3 2
4 0 0.3 0.707106781186547-0.707106781186548i -0.193982099957017-0.193982099957016i -0.274332116616826+9.15933995315754E-16i 0.3 3
5 0 0.3 0.555570233019602-0.831469612302545i 4.65785003939058E-002+6.9709652105837E-002i 0.0838390857277314+4.57966997657877E-16i 0.3 4
6 0 0.3 0.382683432365089-0.923879532511287i 4.71440392436242E-002+0.113815778927004i 0.123193311380793-1.23512311489549E-15i 0.3 5
7 0 0.3 0.195090322016128-0.98078528040323i -8.00195516800961E-003-4.02285452303434E-002i -0.041016669024442+2.31585584042904E-15i 0.3 6
8 0 0.375311 -1i -6.74391305458326E-002i -0.0674391305458326 0.3 7
9 0 0.486752 -0.195090322016129-0.98078528040323i -4.73892064059265E-003+2.38241628864995E-002i 0.0242909058307897+4.19803081186387E-16i 0.375311099 8
10 0 0.606531 -0.38268343236509-0.923879532511286i -1.62956781019965E-002+3.93412470819081E-002i 0.0425826589912329-7.47665818146004E-16i 0.486752256 9
11 0 0.726149 -0.555570233019603-0.831469612302545i 8.23840043636663E-003-1.23296375682141E-002i -0.0148287290188149+1.07813064031959E-15i 0.60653066 10
12 0 0.83527 -0.707106781186548-0.707106781186547i 2.13999020255143E-002-2.13999020255146E-002i -0.030264031677938+2.32452945780892E-16i 0.726149037 11
13 0 0.923116 -0.831469612302546-0.555570233019601i -6.7686351542714E-003+4.52265741795294E-003i 0.00814056828309937+6.59628601740181E-16i 0.835270211 12
14 0 0.980199 -0.923879532511287-0.382683432365089i -2.2501864171447E-002+9.32057731849245E-003i 0.0243558422712138-1.75207071073658E-15i 0.923116346 13
15 0 1 -0.980785280403231-0.195090322016127i 2.55547285622537E-003-5.08315155610006E-004i -0.00260553752924948+3.69235891861663E-15i 0.980198673 14
16 0 0.980199 -1 2.25860077235236E-002 -0.0225860077235236 1 15
17 0 0.923116 -0.98078528040323+0.195090322016128i 2.5554728562267E-003+5.08315155605787E-004i -0.00260553752924996+7.07984018633034E-16i 0.980198673 16
18 0 0.83527 -0.923879532511287+0.38268343236509i -2.25018641714476E-002-9.32057731849029E-003i 0.0243558422712136-4.96130914129367E-16i 0.923116346 17
19 0 0.726149 -0.831469612302545+0.555570233019602i -6.7686351542709E-003-4.52265741795466E-003i 0.00814056828309991+1.03693095776514E-15i 0.835270211 18
20 0 0.606531 -0.707106781186547+0.707106781186548i 2.13999020255145E-002+2.13999020255143E-002i -0.0302640316779379+1.61329283265843E-16i 0.726149037 19
21 0 0.486752 -0.555570233019602+0.831469612302545i 8.23840043636761E-003+1.23296375682124E-002i -0.014828729018814+6.93022028652734E-16i 0.60653066 20
22 0 0.375311 -0.382683432365089+0.923879532511287i -1.62956781019978E-002-3.93412470819062E-002i 0.0425826589912317-1.23685783837146E-15i 0.486752256 21
23 0 0.3 -0.195090322016128+0.98078528040323i -4.73892064059067E-003-2.38241628865021E-002i 0.0242909058307919+2.00534033822919E-15i 0.375311099 22
24 0 0.3 1i 6.74391305458326E-002i -0.0674391305458326 0.3 23
25 0 0.3 0.195090322016129+0.98078528040323i -8.0019551680063E-003+4.02285452303411E-002i -0.0410166690244391+5.20417042793042E-16i 0.3 24
26 0 0.3 0.38268343236509+0.923879532511286i 4.71440392436218E-002-0.113815778927003i 0.123193311380791-7.56339435525888E-16i 0.3 25
27 0 0.3 0.555570233019603+0.831469612302545i 4.65785003939087E-002-6.97096521058391E-002i 0.0838390857277349+7.21644966006352E-16i 0.3 26
28 0 0.3 0.707106781186548+0.707106781186547i -0.193982099957016+0.193982099957017i -0.274332116616826+9.15933995315754E-16i 0.3 27
29 0 0.3 0.831469612302546+0.555570233019601i -0.387870541381196+0.25916681002911i -0.466487933704621+1.88737914186277E-15i 0.3 28
30 0 0.3 0.923879532511287+0.382683432365089i 2.41120380085124-0.998753315958145i 2.60986818735676-7.66053886991358E-15i 0.3 29
31 0 0.3 0.980785280403231+0.195090322016127i -5.09158170779647+1.01277857120477i -5.19133169056449+1.88737914186277E-14i 0.3 30
Excel example : Gaussian kernel (1) 37/50

• Gaussian function (ex: PDF)


: Popular for low-pass filter

1 1 𝑡𝑡 2

𝑓𝑓 𝑡𝑡 = 𝑒𝑒 2 𝜎𝜎
𝜎𝜎 2𝜋𝜋

1 1 𝑡𝑡−𝑇𝑇 2

𝑓𝑓 𝑡𝑡 − 𝑇𝑇 = 𝑒𝑒 2 𝜎𝜎
𝜎𝜎 2𝜋𝜋
Excel example : Gaussian kernel (2) 38/50

2
Gaussian filter
1 1 𝑡𝑡−𝑡𝑡𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠
sigma 1 −
𝑓𝑓 𝑡𝑡 − 𝑡𝑡𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠 = 𝑒𝑒 2 𝜎𝜎
shift 4
Tmax 32 𝜎𝜎 2𝜋𝜋
t Kernel h(t) FFT Kernel FFT h(t) Product iFFT t-shift
0 0.0001 0 0.999998512546039 13 12.9999806630985 0 -4
1 0.0044 1 0.693605265639587-0.693607021787994i 1.90466481291451-9.57539663322764i -5.32047679769587-7.962 1.34E-04 -3
2 0.0540 1 -1.37784952463278E-006-0.925792053866677i -2.63098631369784-1.08979021355164i -1.00891549498454+2.43 4.57E-03 -2
3 0.2420 1 -0.594484557704588-0.594484150818588i 1.21415304466763-1.81710844340743i -1.80203740566927+0.35 5.86E-02 -1
4 0.3989 1 -0.734604268868589-1.05735179245503E-006i -1.70710678118655-1.70710678118655i 1.25404612386174+1.254 0.30052737 0
5 0.2420 1 -0.436710530801492+0.436708465381227i 0.172886800654513-0.115519266975558i -0.0250532446795439+0. 0.69946965 1
6 0.0540 1 -5.64638189074751E-007+0.49959628785912i -0.675576651178546-1.63098631369783i 0.814835089328843-0.337 0.941440375 2
7 0.0044 1 0.274964976931668+0.274963800887644i -0.728789210495159+0.144965187180348i -0.240251687315347-0.16 0.995431341 3
8 0.0001 1 0.291228001750709-1.48671038002757E-006i -1i -1.48671038002757E-06-0 0.99986319 4
9 0.0000 1 0.148407077149866-0.148408237316857i -1.11896985452741-0.222576942790519i -0.19909529727614+0.13 0.99999702 5
10 0.0000 1 5.73230785417534E-007-0.145578767359166i 8.97902135516364E-002-0.216772751324741i -0.0315574584643962-0.0 0.999998506 6
11 0.0000 1 -6.8772002481372E-002-6.87740613251636E-002i -0.938253665384694-0.626921056159531i 0.0214096762416406+0.1 0.999998513 7
12 0.0000 1 -6.27449710312274E-002-1.04520002744413E-006i -0.292893218813453+0.292893218813451i 0.0183778826616934-0.01 0.999998513 8
13 0.0000 1 -2.78767552049874E-002+2.7877168667488E-002i -0.448786179937457-0.671655983099026i 0.0312345696048769+0.0 0.999998513 9
14 0.0000 0 1.36925692745733E-006+2.48020125207467E-002i -0.783227248675261+0.324423348821456i -0.00804742439882835-0 0.999864682 10
15 0.0000 0 1.19371682774361E-002+1.19354280060922E-002i -5.69057478919495E-002-0.286084513706125i 0.0027352476284578-0.00 0.995432834 11
16 0.0000 0 1.43852473644143E-002 -1 -0.0143852473644143 0.941441867 12
17 0.0000 0 1.19371682774363E-002-1.19354280060918E-002i -5.69057478919436E-002+0.286084513706125i 0.00273524762845774+0. 0.699471143 13
18 0.0000 0 1.36925692796135E-006-2.48020125207467E-002i -0.783227248675261-0.324423348821458i -0.00804742439882879+0 0.300528862 14
19 0.0000 0 -2.78767552049871E-002-2.78771686674881E-002i -0.448786179937455+0.671655983099027i 0.0312345696048768-0.00 5.86E-02 15
20 0.0000 0 -6.27449710312271E-002+1.04520002675024E-006i -0.292893218813453-0.292893218813453i 0.0183778826616931+0.0 4.57E-03 16
21 0.0000 0 -6.8772002481372E-002+6.87740613251634E-002i -0.938253665384692+0.626921056159534i 0.0214096762416404-0.10 1.35E-04 17
22 0.0000 0 5.73230785385359E-007+0.145578767359166i 8.97902135516381E-002+0.216772751324737i -0.0315574584643956+0. 1.49E-06 18
23 0.0000 0 0.148407077149866+0.148408237316857i -1.11896985452742+0.222576942790519i -0.199095297276141-0.13 6.09E-09 19
24 0.0000 0 0.291228001750709+1.48671038002757E-006i 1i -1.48671038002757E-06+ 0 20
25 0.0000 0 0.274964976931668-0.274963800887645i -0.72878921049516-0.144965187180343i -0.240251687315346+0.1 0 21
26 0.0000 0 -5.64638189986266E-007-0.49959628785912i -0.67557665117854+1.63098631369783i 0.814835089328844+0.33 0 22
27 0.0000 0 -0.436710530801493-0.436708465381226i 0.17288680065451+0.115519266975554i -0.0250532446795446-0.1 0 23
28 0.0000 0 -0.734604268868589+1.05735179314892E-006i -1.70710678118655+1.70710678118655i 1.25404612386174-1.2540 0 24
29 0.0000 0 𝑡𝑡𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠
-0.594484557704587+0.594484150818589i 1.21415304466764+1.81710844340743i -1.80203740566927-0.358 0 25
30 0.0000 0 -1.37784952252777E-006+0.925792053866677i -2.63098631369783+1.08979021355164i -1.00891549498454-2.435 0 26
31 0.0000 0 0.693605265639589+0.693607021787992i 1.90466481291454+9.57539663322764i -5.32047679769582+7.96 0 27
MATLAB functions 39/50

• Butterworth filtering

[b,a]= butter(n,Wn,ftype)
: designs a lowpass, highpass, bandpass, or bandstop Butterworth filter

n : Order of the filter


Wn : Cut-off frequency/Nyquist freq
ftype : ‘high’ – high-pass filter, ‘low’ – low-pass filter
‘bandpass’ – band-pass filter, ‘stop’ – notch filter
[b,a] : Transfer function coefficients

y = filter(b,a,x)
: filters the input data x using transfer function coefficients b and a
MATLAB Example: Source code 40/50

clear; clc;
% High-pass filter % band-pass filter
Fs = 200; % Sampling frequency Fs = 200; % Sampling frequency
dt = 1/Fs; dt = 1/Fs;
t = 0:dt:5; t = 0:dt:5;
X = 3*sin(2*pi*3*t)+2*cos(2*pi*40*t); % Example signal X = 3*sin(2*pi*3*t)+1*cos(2*pi*10*t)+2*cos(2*pi*40*t); % Example signal
n = 5; % Order n = 5; % Order
Wn = 10; % Cut-off freq Wn = [8 12]; % 8 - 12 Hz band
Fn = Fs/2; %Nyquist freq Fn = Fs/2; %Nyquist freq
ftype = 'high'; % High-pass ftype = 'bandpass';
[b,a] = butter(n,Wn/Fn,ftype); [b,a] = butter(n,Wn/Fn,ftype);
y = filter(b,a,X); % Filtered signal y = filter(b,a,X); % Filtered signal
subplot(2,1,1); plot(t,X); subplot(2,1,2); plot(t,y); pause; subplot(2,1,1); plot(t,X); subplot(2,1,2); plot(t,y); pause;

f_sz=ceil(length(X)/2); f_X = fft(X);


f = Fs/2*linspace(0,1,f_sz); f_y=fft(y);
f_X = fft(X); subplot(2,1,1); stem(f,abs(f_X(1:f_sz))); subplot(2,1,2); stem(f,abs(f_y(1:f_sz))); pause;
f_y = fft(y);
subplot(2,1,1); stem(f,abs(f_X(1:f_sz))); subplot(2,1,2); stem(f,abs(f_y(1:f_sz))); pause;
% Notch filter
ftype = 'stop';
% Low-pass filter [b,a] = butter(n,Wn/Fn,ftype);
ftype = 'low'; y = filter(b,a,X); % Filtered signal
[b,a] = butter(n,Wn/Fn,ftype); subplot(2,1,1); plot(t,X); subplot(2,1,2); plot(t,y); pause;
y = filter(b,a,X); % Filtered signal
subplot(2,1,1); plot(t,X); subplot(2,1,2); plot(t,y); pause;
f_y=fft(y);
subplot(2,1,1); stem(f,abs(f_X(1:f_sz))); subplot(2,1,2); stem(f,abs(f_y(1:f_sz))); pause;
f_y=fft(y);
subplot(2,1,1); stem(f,abs(f_X(1:f_sz))); subplot(2,1,2); stem(f,abs(f_y(1:f_sz))); pause;
MATLAB Example: Results (1) 41/50

ℎ(𝑡𝑡) = 3 sin 2𝜋𝜋3𝑡𝑡 + 2 cos 2𝜋𝜋40𝑡𝑡

5
signal 1500
FFT spectrum
• Original data 1000

500

-5 0

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 0 10 20 30 40 50 60 70 80 90 100

2 1000

• High-pass filter
1 800

0 600

(over 10 Hz) -1

-2
400

200

-3 0

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 0 10 20 30 40 50 60 70 80 90 100

4
1500

• Low-pass filter 2

1000

(below 10 Hz)
0

500
-2

-4
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 0 10 20 30 40 50 60 70 80 90 100
MATLAB Example: Results (2) 42/50

ℎ 𝑡𝑡 = 3 sin 2𝜋𝜋3𝑡𝑡 + 1 cos 2𝜋𝜋10𝑡𝑡 + 2 cos 2𝜋𝜋40𝑡𝑡


signal FFT spectrum
1500
5

• Original data 0
1000

500

-5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
0 10 20 30 40 50 60 70 80 90 100

500

400

0.5

• Band-pass filter
300

0
200

(8-12 Hz)
-0.5
100

-1
0
0 10 20 30 40 50 60 70 80 90 100
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

1500
5

• Notch filter
1000

(8-12 Hz)
500

0
-5
0 10 20 30 40 50 60 70 80 90 100
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
43/50

Examples
1) Saw-tooth wave
2) Free to choose
Examples 44/50

1. (Saw-tooth wave) For the saw-tooth wave shown in the figure, solve the followings.
Choose your own 𝑇𝑇 and 𝑁𝑁.

(a) Find the Fourier series expansion of the signal,


and plot the signal using first four terms.
(b) Carry out the FFT and discuss the results.

2. (Free to choose) Choose one data in the HW2-3.xlsx, and carry out the FFT.
Examine the effect of de-trending, filtering.
45/50

Appendix
- FFT for sound data (mp3)
Appendix: Example(Music) 46/50
Appendix: Example(Music) 47/50

Frequency spectrum
1 0.014
0.8
0.012
0.6
0.01

Amplitude (arbitrary)
0.4

0.2 0.008
0
0.006
-0.2

-0.4 0.004

-0.6
0.002
-0.8
0
-1
0 2 4 6 8 10 12 0 0.5 1 1.5 2 2.5
5 Frequency (Hz) 4
x 10 x 10

Frequency spectrum
0.8 0.01

0.6
0.008
0.4

Amplitude (arbitrary)
0.2
0.006

0
0.004

-0.2

0.002
-0.4

-0.6 0
0 5 10 15 0 0.5 1 1.5 2 2.5
5
x 10 Frequency (Hz) 4
x 10
Appendix: Human Voice Frequency Range 48/50

• Audible frequency: 20 – 20,000 Hz


• Voice frequency: 300 – 3,400 Hz (approx.)
Appendix: Close-up power spectrum(Music) 49/50

Frequency spectrum
0.014

0.012

0.01

Amplitude (arbitrary)
0.008

0.006

0.004

0.002

0
0 500 1000 1500 2000 2500 3000 3500 4000
Frequency (Hz)

Frequency spectrum
0.01

0.009

0.008

0.007
Amplitude (arbitrary)

0.006

0.005

0.004

0.003

0.002

0.001

0
0 500 1000 1500 2000 2500 3000 3500 4000
Frequency (Hz)
50/50

Thank you!

You might also like