Fast Fourier transform (FFT) MATLAB tutorial series (Part 2.1) - - PowerPoint PPT Presentation

โ–ถ
fast fourier transform fft
SMART_READER_LITE
LIVE PREVIEW

Fast Fourier transform (FFT) MATLAB tutorial series (Part 2.1) - - PowerPoint PPT Presentation

Fast Fourier transform (FFT) MATLAB tutorial series (Part 2.1) Pouyan Ebrahimbabaie Laboratory for Signal and Image Exploitation (INTELSIG) Dept. of Electrical Engineering and Computer Science University of Lige Lige, Belgium Applied


slide-1
SLIDE 1

Fast Fourier transform (FFT)

Pouyan Ebrahimbabaie Laboratory for Signal and Image Exploitation (INTELSIG)

  • Dept. of Electrical Engineering and Computer Science

University of Liรจge Liรจge, Belgium Applied digital signal processing (ELEN0071-1) 1 April 2020

MATLAB tutorial series (Part 2.1)

slide-2
SLIDE 2

Introduction ๐’– |๐’€ ๐’ˆ | ๐’ˆ ๐’š(๐’–)

slide-3
SLIDE 3

Introduction ๐’– |๐’€ ๐’ˆ | ๐’ˆ ๐’š(๐’–)

DFT

slide-4
SLIDE 4

Introduction ๐’– |๐’€ ๐’ˆ | ๐’ˆ ๐’š(๐’–)

DFT

Time: sampled, finite Frequency: sampled, finite

slide-5
SLIDE 5

Introduction ๐’š(๐’–) ๐’– |๐’€ ๐’ˆ | ๐’ˆ

DFT

Time: sampled, finite Frequency: sampled, finite

slide-6
SLIDE 6

Introduction ๐’š(๐’–) ๐’– |๐’€ ๐’ˆ | ๐’ˆ

DFT

Each sample in frequency domain corresponds to a sample in time domain !

slide-7
SLIDE 7

Introduction ๐’š(๐’–) ๐’– |๐’€ ๐’ˆ | ๐’ˆ

DFT

Time: N samples Frequency: N samples

slide-8
SLIDE 8

Introduction ๐’š(๐’–) ๐’– |๐’€ ๐’ˆ | ๐’ˆ

DFT

Time: N samples Frequency: N samples

๐‘ผ๐’•

slide-9
SLIDE 9

Introduction ๐’š(๐’–) ๐’– |๐’€ ๐’ˆ | ๐’ˆ

DFT

Time: N samples Frequency: N samples

๐‘ผ๐’• ๐‘ฎ๐’• = ๐Ÿ ๐‘ผ๐’•

slide-10
SLIDE 10

Introduction ๐’š(๐’–) ๐’– |๐’€ ๐’ˆ | ๐’ˆ

DFT

Time: N samples Frequency: N samples

๐‘ผ๐’• ๐‘ฎ๐’• = ๐Ÿ ๐‘ผ๐’• ๐‘ผ๐’๐’ƒ๐’š

slide-11
SLIDE 11

Introduction ๐’š(๐’–) ๐’– |๐’€ ๐’ˆ | ๐’ˆ

DFT

Time: N samples Frequency: N samples

๐‘ผ๐’• ๐‘ฎ๐’• = ๐Ÿ ๐‘ผ๐’• ๐‘ผ๐’๐’ƒ๐’š = ๐‘ถ โˆ’ ๐Ÿ ร— ๐‘ผ๐’• ๐‘ผ๐’๐’ƒ๐’š

slide-12
SLIDE 12

Introduction ๐’š(๐’–) ๐’– |๐’€ ๐’ˆ |

DFT

Time: N samples Frequency: N samples

๐‘ผ๐’• ๐‘ฎ๐’• = ๐Ÿ ๐‘ผ๐’• ๐‘ผ๐’๐’ƒ๐’š = ๐‘ถ โˆ’ ๐Ÿ ร— ๐‘ผ๐’• ๐‘ผ๐’๐’ƒ๐’š ๐‘ฎ๐’•/๐Ÿ‘ โˆ’๐‘ฎ๐’•/๐Ÿ‘

From sampling theorem

slide-13
SLIDE 13

Introduction ๐’š(๐’–) ๐’– |๐’€ ๐’ˆ |

DFT

Time: N samples Frequency: N samples

๐‘ผ๐’• ๐‘ฎ๐’• = ๐Ÿ ๐‘ผ๐’• ๐‘ผ๐’๐’ƒ๐’š = ๐‘ถ โˆ’ ๐Ÿ ร— ๐‘ผ๐’• ๐‘ผ๐’๐’ƒ๐’š ๐‘ฎ๐’•/๐Ÿ‘ โˆ’๐‘ฎ๐’•/๐Ÿ‘ ๐‘ฎ๐’•

slide-14
SLIDE 14

Introduction ๐’š(๐’–) ๐’– |๐’€ ๐’ˆ |

DFT

Time: N samples Frequency: N samples

๐‘ผ๐’• ๐‘ฎ๐’• = ๐Ÿ ๐‘ผ๐’• ๐‘ผ๐’๐’ƒ๐’š = ๐‘ถ โˆ’ ๐Ÿ ร— ๐‘ผ๐’• ๐‘ผ๐’๐’ƒ๐’š ๐‘ฎ๐’•/๐Ÿ‘ โˆ’๐‘ฎ๐’•/๐Ÿ‘ ๐‘ฎ๐’•

๐‘ฎ๐’•/(๐‘ถ โˆ’ ๐Ÿ)

slide-15
SLIDE 15

FFT is just an algorithm to compute DFT efficiently ! In MATLAB: X=fft(x)

  • r

X=fft(x,n)

slide-16
SLIDE 16

Example 2.1: pure tone % Sampling frequency Fs=44100; % Sampling period Ts=1/Fs; % Signal length (in second) N_sec=5; % Siganal length (in sample) N=N_sec*Fs; % Maximum time Tmax=(N-1)*Ts; % Time vector t=0:Ts:Tmax;

slide-17
SLIDE 17

Example 2.1: pure tone % Sampling frequency Fs=44100; % Sampling period Ts=1/Fs; % Signal length (in second) N_sec=5; % Siganal length (in sample) N=N_sec*Fs; % Maximum time Tmax=(N-1)*Ts; % Time vector t=0:Ts:Tmax;

slide-18
SLIDE 18

Example 2.1: pure tone % Sampling frequency Fs=44100; % Sampling period Ts=1/Fs; % Signal length (in second) N_sec=5; % Siganal length (in sample) N=N_sec*Fs; % Maximum time Tmax=(N-1)*Ts; % Time vector t=0:Ts:Tmax;

slide-19
SLIDE 19

Example 2.1: pure tone % Sampling frequency Fs=44100; % Sampling period Ts=1/Fs; % Signal length (in second) N_sec=5; % Siganal length (in sample) N=N_sec*Fs; % Maximum time Tmax=(N-1)*Ts; % Time vector t=0:Ts:Tmax;

slide-20
SLIDE 20

Example 2.1: pure tone % Signal x=sin(2*pi*F0.*t); % Play the sound sound(x,Fs) % Plot the sound (show from zero to 60 msec) figure(1) plot(t,x,'LineWidth',2.5) xlim([0 0.06])

slide-21
SLIDE 21

Example 2.1: pure tone % Signal x=sin(2*pi*F0.*t); % Play the sound sound(x,Fs) % Plot the sound (show from zero to 60 msec) figure(1) plot(t,x,'LineWidth',2.5) xlim([0 0.06]) % take FFT (without shift) X1=fft(x);

slide-22
SLIDE 22

Example 2.1: pure tone % Signal x=sin(2*pi*F0.*t); % Play the sound sound(x,Fs) % Plot the sound (show from zero to 60 msec) figure(1) plot(t,x,'LineWidth',2.5) xlim([0 0.06]) % take FFT (without shift) X1=fft(x); % plot result figure(2) plot(abs(X1),'LineWidth',2.5);

slide-23
SLIDE 23

Example 2.1: pure tone % Signal x=sin(2*pi*F0.*t); % Play the sound sound(x,Fs) % Plot the sound (show from zero to 60 msec) figure(1) plot(t,x,'LineWidth',2.5) xlim([0 0.06]) % take FFT (without shift) X1=fft(x); % plot result figure(2) plot(abs(X1),'LineWidth',2.5);

You should always perform some post processing operations (shifting, scaling, etc.) to be able to present the results of fft !

slide-24
SLIDE 24

Example 2.1: pure tone % take FFT (with shift) X2=fftshift(fft(x)); % Frequency range F=-Fs/2:Fs/(N-1):Fs/2; figure(3) plot(F,abs(X2)/N,'LineWidth',2.5); xlabel('Frequency (Hz)') title('Double sided magnitude response')

slide-25
SLIDE 25

Example 2.1: pure tone % take FFT (with shift) X2=fftshift(fft(x)); % Frequency range F=-Fs/2:Fs/(N-1):Fs/2; figure(3) plot(F,abs(X2)/N,'LineWidth',2.5); xlabel('Frequency (Hz)') title('Double sided magnitude response')

slide-26
SLIDE 26

Example 2.1: pure tone % take FFT (with shift) X2=fftshift(fft(x)); % Frequency range F=-Fs/2:Fs/(N-1):Fs/2; figure(3) plot(F,abs(X2)/N,'LineWidth',2.5); xlabel('Frequency (Hz)') title('Double sided magnitude response')

slide-27
SLIDE 27

Example 2.1: pure tone % take FFT (with shift) X2=fftshift(fft(x)); % Frequency range F=-Fs/2:Fs/(N-1):Fs/2; figure(3) plot(F,abs(X2)/N,'LineWidth',2.5); xlabel('Frequency (Hz)') title('Double sided magnitude response') fftshift Scaling

slide-28
SLIDE 28

Example 2.1: pure tone % take FFT (with shift) X2=fftshift(fft(x)); % Frequency range F=-Fs/2:Fs/(N-1):Fs/2; figure(3) plot(F,abs(X2)/N,'LineWidth',2.5); xlabel('Frequency (Hz)') title('Double sided magnitude response')

This is the correct method to graph a โ€œdouble-sidedโ€ (negative and positive) frequency spectrum๏Š

slide-29
SLIDE 29

Example 2.2: single sided spectrum % Sampling frequency Fs=44100; % Sampling period Ts=1/Fs; % Signal length (in second) N_sec=5; % Signal length (in sample) N=N_sec*Fs; % Maximum time Tmax=(N-1)*Ts; % Time vector t=0:Ts:Tmax;

slide-30
SLIDE 30

Example 2.2: single sided spectrum % pure F0, F1 and F3 F0=600; F1=1300; F2=2000; % Signal x=sin(2*pi*F0.*t)+โ€ฆ โ€ฆ0.5*sin(2*pi*F1.*t)+0.2*sin(2*pi*F2.*t); % Play the sound sound(x,Fs) % Plot the sound (show from zero to 60 msec) figure(1) plot(t,x,'LineWidth',2.5) xlim([0 0.06])

slide-31
SLIDE 31

Example 2.2: single sided spectrum % Compute fft X=fft(x); % Take abs and scale it X2=abs(X/N); % Pick the first half X1=X2(1:N/2+1); % Multiply by 2 (except the DC part), to compensate % the removed side from the spectrum. X1(2:end-1) = 2*X1(2:end-1); % Frequency range F = Fs*(0:(N/2))/N;

slide-32
SLIDE 32

Example 2.2: single sided spectrum % Compute fft X=fft(x); % Take abs and scale it X2=abs(X/N); % Pick the first half X1=X2(1:N/2+1); % Multiply by 2 (except the DC part), to compensate % the removed side from the spectrum. X1(2:end-1) = 2*X1(2:end-1); % Frequency range F = Fs*(0:(N/2))/N;

slide-33
SLIDE 33

Example 2.2: single sided spectrum % Compute fft X=fft(x); % Take abs and scale it X2=abs(X/N); % Pick the first half X1=X2(1:N/2+1); % Multiply by 2 (except the DC part), to compensate % the removed side from the spectrum. X1(2:end-1) = 2*X1(2:end-1); % Frequency range F = Fs*(0:(N/2))/N;

slide-34
SLIDE 34

Example 2.2: single sided spectrum % Compute fft X=fft(x); % Take abs and scale it X2=abs(X/N); % Pick the first half X1=X2(1:N/2+1); % Multiply by 2 (except the DC part), to compensate % the removed side from the spectrum. X1(2:end-1) = 2*X1(2:end-1); % Frequency range F = Fs*(0:(N/2))/N;

slide-35
SLIDE 35

Example 2.2: single sided spectrum % Compute fft X=fft(x); % Take abs and scale it X2=abs(X/N); % Pick the first half X1=X2(1:N/2+1); % Multiply by 2 (except the DC part), to compensate % the removed side from the spectrum. X1(2:end-1) = 2*X1(2:end-1); % Frequency range F = Fs*(0:(N/2))/N;

slide-36
SLIDE 36

Example 2.2: single sided spectrum % Plot single-sided spectrum plot(F,X1,'LineWidth',2.5) title('Single-Sided Amplitude Spectrum') xlabel('f (Hz)')

Most of the time we use โ€œsingle-sidedโ€ amplitude or phase spectrum !

slide-37
SLIDE 37

Example 2.3: siren F0=1300; F1=200; F2=1400; B0=100; B1=100; B2=500; % Signal x=sin(2*pi*F0.*t+B0*pi*t.^2)+โ€ฆ sin(2*pi*F1.*t+B1*pi*t.^2)... +sin(2*pi*F2.*t+B2*pi*t.^2);

slide-38
SLIDE 38

Example 2.4: voice % read audio file .wav [x,Fs]=audioread('adult_female_speech.wav'); % play the sound sound(x,Fs) % Sampling period Ts=1/Fs; % Length of signal N=length(x); % Maximum time Tmax=(N-1)*Ts; % Time vector t=0:Ts:Tmax; โ€ฆ

slide-39
SLIDE 39

Usable voice frequency band in telephony: ~ 300 Hz to 3400 Hz

slide-40
SLIDE 40

How fast is it?

๐’€(๐’‡๐’Œ๐) = เท

๐’=๐Ÿ ๐‘ถโˆ’๐Ÿ

๐’š[๐’]๐’‡โˆ’๐’Œ๐๐’ DTFT:

slide-41
SLIDE 41

How fast is it?

๐’€(๐’‡๐’Œ๐) = เท

๐’=๐Ÿ ๐‘ถโˆ’๐Ÿ

๐’š[๐’]๐’‡โˆ’๐’Œ๐๐’ DTFT: Sample ๐ at ๐๐’ = ฮค (๐Ÿ‘๐† ๐‘ถ)๐’, ๐’ = ๐Ÿ, ๐Ÿ, ๐Ÿ‘, โ‹ฏ ๐‘ถ

slide-42
SLIDE 42

How fast is it?

๐’€(๐’‡๐’Œ๐) = เท

๐’=๐Ÿ ๐‘ถโˆ’๐Ÿ

๐’š[๐’]๐’‡โˆ’๐’Œ๐๐’ DTFT: Sample ๐ at ๐๐’ = ฮค (๐Ÿ‘๐† ๐‘ถ)๐’, ๐’ = ๐Ÿ, ๐Ÿ, ๐Ÿ‘, โ‹ฏ ๐‘ถ ๐’€ ๐’ = ๐’€(๐’‡๐’Œ๐Ÿ‘๐†

๐‘ถ ๐’) = เท ๐’=๐Ÿ ๐‘ถโˆ’๐Ÿ

๐’š[๐’]๐’‡โˆ’๐’Œ๐Ÿ‘๐†

๐‘ถ ๐’๐’

DFT:

slide-43
SLIDE 43

How fast is it?

๐’€(๐’‡๐’Œ๐) = เท

๐’=๐Ÿ ๐‘ถโˆ’๐Ÿ

๐’š[๐’]๐’‡โˆ’๐’Œ๐๐’ DTFT: Sample ๐ at ๐๐’ = ฮค (๐Ÿ‘๐† ๐‘ถ)๐’, ๐’ = ๐Ÿ, ๐Ÿ, ๐Ÿ‘, โ‹ฏ ๐‘ถ ๐’€ ๐’ = ๐’€(๐’‡๐’Œ๐Ÿ‘๐†

๐‘ถ ๐’) = เท ๐’=๐Ÿ ๐‘ถโˆ’๐Ÿ

๐’š[๐’]๐’‡โˆ’๐’Œ๐Ÿ‘๐†

๐‘ถ ๐’๐’

DFT: For each ๐’: ๐‘ถ complex multiplications, ๐‘ถ โˆ’ ๐Ÿ complex adds

slide-44
SLIDE 44

How fast is it?

๐‘ท(๐‘ถ๐Ÿ‘) computations for direct DFT

slide-45
SLIDE 45

How fast is it?

๐‘ท(๐‘ถ๐Ÿ‘) computations for direct DFT vs. ๐‘ท(๐‘ถ ๐ฆ๐ฉ๐ก๐Ÿ‘ ๐‘ถ) computations for fft !

slide-46
SLIDE 46

How fast is it?

๐‘ท(๐‘ถ๐Ÿ‘) computations for direct DFT vs. ๐‘ท(๐‘ถ ๐ฆ๐ฉ๐ก๐Ÿ‘ ๐‘ถ) computations for fft ! ๐‘ถ ๐Ÿ๐Ÿ๐Ÿ๐Ÿ ๐Ÿ๐Ÿ๐Ÿ• ๐Ÿ๐Ÿ๐Ÿ˜ ๐‘ถ๐Ÿ‘ ๐Ÿ๐Ÿ๐Ÿ• ๐Ÿ๐Ÿ๐Ÿ๐Ÿ‘ ๐Ÿ๐Ÿ๐Ÿ๐Ÿ— ๐‘ถ ๐ฆ๐ฉ๐ก๐Ÿ‘ ๐‘ถ ๐Ÿ๐Ÿ๐Ÿ“ ๐Ÿ‘๐Ÿ ร— ๐Ÿ๐Ÿ๐Ÿ• ๐Ÿ’๐Ÿ ร— ๐Ÿ๐Ÿ๐Ÿ˜

slide-47
SLIDE 47

How fast is it?

๐‘ท(๐‘ถ๐Ÿ‘) computations for direct DFT vs. ๐‘ท(๐‘ถ ๐ฆ๐ฉ๐ก๐Ÿ‘ ๐‘ถ) computations for fft ! ๐‘ถ ๐Ÿ๐Ÿ๐Ÿ๐Ÿ ๐Ÿ๐Ÿ๐Ÿ• ๐Ÿ๐Ÿ๐Ÿ˜ ๐‘ถ๐Ÿ‘ ๐Ÿ๐Ÿ๐Ÿ• ๐Ÿ๐Ÿ๐Ÿ๐Ÿ‘ ๐Ÿ๐Ÿ๐Ÿ๐Ÿ— ๐‘ถ ๐ฆ๐ฉ๐ก๐Ÿ‘ ๐‘ถ ๐Ÿ๐Ÿ๐Ÿ“ ๐Ÿ‘๐Ÿ ร— ๐Ÿ๐Ÿ๐Ÿ• ๐Ÿ’๐Ÿ ร— ๐Ÿ๐Ÿ๐Ÿ˜ ๐Ÿ๐Ÿ๐Ÿ๐Ÿ— ๐’๐’• ~ ๐Ÿ’๐Ÿ. ๐Ÿ‘ ๐’›๐’‡๐’ƒ๐’”๐’• vs. ๐Ÿ’๐Ÿ ร— ๐Ÿ๐Ÿ๐Ÿ˜ ๐’๐’• ~ ๐Ÿ’๐Ÿ ๐’•๐’‡๐’…๐’‘๐’๐’†๐’•

slide-48
SLIDE 48

First time presented by โ€ฆ

Cooley and Tukey (1965)

slide-49
SLIDE 49

First time presented by โ€ฆ

Gauss (1805)

slide-50
SLIDE 50

Real-Time application โ€ฆ

slide-51
SLIDE 51

Useful links

  • https://www.youtube.com/watch?v=iTMn0Kt18tg
  • https://allsignalprocessing.com/fast-fourier-transform-

fft-algorithm/

  • https://allsignalprocessing.com/discrete-fourier-

transform-sampling-the-dtft/

  • https://nl.mathworks.com/help/matlab/ref/fft.html