Title: FFT and LPF Design
1FFT and LPF Design
- Digital Signal Processing, Lecture 6
Neural Signal Processing Laboratory at Yonsei BME
2Generating Square wave
Generate Square wave fs 100 x -21/fs2 y
(xgt-1 xlt0)(x0) (xgt0 xlt1) plot(x,
y) axis( -4 4 -1 2), grid title('Square wave')
3H.W. Generate Triangular wave
Generate Triangular wave fs 100 x
-21/fs2 y (x1).(xgt-1 xlt0) (x0)
(-x1).(xgt0 xlt1) plot(x,y), axis( -4 4 -1
2), grid title('Triangular wave')
(x1).(xgt-1 xlt0)
x0
(-x1).(xgt0 xlt1)
4Result Triangular wave
5Fourier Transform
In the MATLAB, Use a 'fft' and 'ifft'
lt Fast Fourier Transform gt Y fft(X) returns the
discrete Fourier transform (DFT) of vector X,
computed with a fast Fourier transform (FFT)
algorithm1
x 1 0 -2 -1 1 2 1 0.5 a fft(x) b ifft(a)
Compare b with x Is b the same as x?
plot(fft(eye(8)))
6fastfft.m
FASTFFT Create useful data from an FFT
operation. Usage vFrequency, vAmplitude
fastfft(vData, SampleRate, Plot) (no plot
will be shown if the last input 0 or is not
included) This function inputs 'vData' as a
vector (row or column), 'SampleRate' as a
number (samples/sec), 'Plot' as anything, and
does the following 1 Removes the DC offset
of the data 2 Puts the data through a
hanning window 3 Calculates the Fast Fourier
Transform (FFT) 4 Calculates the amplitude
from the FFT 5 Calculates the frequency
scale 6 Optionally creates a Bode plot
7Fourier Transform
clear all, close all, clc fs 1000 t
01/fs1 y sin(2pi10t) .5
sin(2pi60t) figure(1), plot(t,y,'g') title('10
Hz Original Signal 60Hz Noise
signal') xlabel('time (second)') Y
fft(y,512) Pyy Y. conj(Y) / 512 f
1000(0256)/512 figure(2), plot(f,Pyy(1257),'r'
) title('Frequency content of y') xlabel('frequenc
y (Hz)'), grid
8Using fastfft.m
clear all, close all, clc fs 1000 t
01/fs1 y sin(2pi10t) .5
sin(2pi60t) figure(1), plot(t,y,'g') title('10
Hz and 60Hz signal') xlabel('time
(second)') figure(2), ff, aa
fastfft(y,fs,1) grid
9Remove 60Hz noise
- Generate 40Hz Butterworth Low-Pass Filter (LPF)
4th-order Low-Pass Filter order
4 Nyquist_Freq fs/2 Normalization (range 0
1) cutoff_freq 30 / Nyquist_Freq Find
Filter Coefficients b,a butter(order,cutoff_fr
eq,'low') Filtering_y filter(b, a, y)
10Confirmation using FFT
Filtering_Y fft(Filtering_y,512) Pyy2
Filtering_Y. conj(Filtering_Y) / 512 f
1000(0256)/512 figure(3),plot(f,Pyy2(1257),'r'
) title('Frequency content of Filtering_y') xlabel
('frequency (Hz)'), grid figure(4),
fastfft(Filtering_y, fs, 1) grid
or
11Comparison
Before Low Pass filtering
After Low Pass filtering
60Hz component