You are on page 1of 23

Digital Signal

Processing
Lecture 7- Concept of filtering
IVAN TANRA
What is filter ?
Filter is a device or process that removes some unwanted components or features
from a signal

Filter normally in the form of analog (RC circuit) or digital (digital signal
processing/microprosseor))

Analog filter Digital filter


Filter category
Based on frequency that it let pass, filter can be categorized as

𝑓𝑐
𝑓𝑐

𝐻 ( 𝜔 )=
{ 1 𝑓 ≤| 𝑓 𝑐|
0 𝑓 >| 𝑓 𝑐|
𝐻 ( 𝜔 )=
{ 1 𝑓 ≥| 𝑓 𝑐|
0 𝑓 <| 𝑓 𝑐|

𝑓 𝑐1 𝑓 𝑐2

𝑓 𝑐1 𝑓 𝑐2

𝐻 ( 𝜔 )=
{ 1| 𝑓 𝑐 1|≤ 𝑓 ≤| 𝑓 𝑐 2|
0 𝑓 >| 𝑓 𝑐 2| , 𝑓 <| 𝑓 𝑐 1|
𝐻 ( 𝜔 )=
{ 0| 𝑓 𝑐 1|≤ 𝑓 ≤| 𝑓 𝑐 2|
1 𝑓 >| 𝑓 𝑐 2|, 𝑓 <| 𝑓 𝑐 1|
Linear Filtering concept
(Mathematically)

x(n) y(n)
h(n)

Fourier Transform properties


Linear filtering concept
𝑥[𝑛] This part you will learn here 𝑦 [𝑛]
Inverse
Input Fourier Filtered
Filter Fourier
data Transform data
Transform
𝑋[𝑘] 𝐻[𝑘] 𝑌 [ 𝑘 ] =𝐻 [ 𝑘 ] 𝑋 [𝑘]
Due to that properties, filtering can be achieved using fourier transform
where
FT IFT
𝑦[𝑛]
Example of filter and code
First we generate a signal that consist of multiple frequency.
Example, we generate a signal that consist of frequency of 10Hz,50Hz and 100 Hz.
\
Code
%% Generate signal that have multiple sinusoidal The signal that you will get
f1=10; %10Hz
f2=50; %50Hz
f3=100; %100 Hz
Fs=800; %fill with sampling frequency that you get times 4
for better resolution
nf=800; %no of data
for i=1:1:nf
t(i)=i/fs;
x(i)=sin(2*pi*f1*t(i))+sin(2*pi*f2*t(i))+sin(2*pi*f3*t(i));
end
plot(t,x)
Example of filter and code
After that we do a Fourier Transform to the signal to obtain the form of signal in
frequency domain
Code
%% fft
X=fft(x);
Xplot=X.*conj(X);
f=(1:1:nf)*fs/nf;
plot(f,Xplot)
Example of filter and code
Here, we will generate filter window to times with the signal in frequency domain in order to
filter some of the frequency element. Here we will design a high pass filter with cut-off
frequency of 80 Hz, in order to display only 100 Hz of signal.
Code
%% Design filter
fc = 80; %cut off frequency 80 Hz
for i=1:1:nf
f(i)=i*fs/nf;
if f(i)<=fc || f(i)>(fs-fc) %condi-
tion of high pass frequency
W(i)=0;
else
W(i)=1;
end Remember to filter this side also
end
plot(f,W) % plot the filter
Example of filter and code
Last we apply filter by times the window with signal in frequency domain
Code
%% Applying iffft (inverse Fourier Transform)
Y=W.*X; % applying filter window to the signal in frequency domain
plot(f,Y);
y=ifft(Y); %inverse Fourier to form back the signal
figure
plot(t,real(y))
Type of filter
a) Finite Impulse Response (FIR) is a filter whose impulse response is a
finite duration. It settles to zero in finite duration. The difference
equation is define as
𝑀 −1 𝑀 −1
𝑦 ( 𝑛 ) = ∑ 𝑏 𝑘 𝑥 (𝑛− 𝑘) 𝐻 ( 𝑧 )= ∑ 𝑏 𝑘 𝑧 − 𝑘
𝑘= 0 𝑘=0

b) Infinite Impulse Response (IIR) is a filter whose impulse response is


indefinitely and does not become zero. Example of IIR filter is analog
filter that make use of inductor and capacitor
𝑃 𝑄
𝑎𝑜 𝑦 ( 𝑛 )=∑ 𝑏𝑖 𝑥 ( 𝑛−𝑖 ) − ∑ 𝑎 𝑗 𝑦 ( 𝑛− 𝑗 )
𝑃

∑ 𝑏𝑖 𝑧 − 𝑖
𝑖 =0
𝐻 ( 𝑧 )=
𝑖=0 𝑗=1 𝑄

∑ 𝑎𝑗 𝑧
− 𝑗

𝑗 =0
An ideal lowpass filter

is ratio of cut off frequency over


sampling frequency times
An ideal lowpass filter
The signal is anti causal

Can we predict the before signal?


Design of low pass filter
In order to make it casual signal, we introduce delay to the system (),
which is normally at the middle or half of the filter size (N) Hence :

{
𝜔𝑐
𝑛=𝑛0
h ( 𝑛) = 𝜋
sin 𝜔𝑐 (𝑛 − 𝑛 0)
𝑛 ≠ 𝑛0
(𝑛 − 𝑛0 ) 𝜋
Example
You are given a 20,000 data signal that consist of 3 frequency
(10Hz,100Hz, and 200Hz). The signal is sample at 2000 Hz. You are going
to design a low pass filter to filter out the high frequency (100 and 200
Hz) with filter order 100. What will the impulse response of low pass
filter look like?
Solution
First, we will simulate in matlab thus condition, where a signal of 20,000 data
with 3 frequency.
The code will be:
clear all
clc

fs=2000; %sampling frequency


f1=10;
f2=100;
f3=200;
I=20000; %No of data
for i=1:1:I
t(i)=(i-1)/fs;
x(i)=5*sin(2*pi*t(i)*f1)+5*sin(2*pi*t(i)*f2)+5*sin(2*pi*t(i)*f3);
end
Solution (the signal)
Solution (impulse response of
low pass filter)
Now, we will make the impulse response of our filter. Here we decide
the cut off frequency will be 20 Hz. Hence
20
𝜔 𝑐 =2 𝜋 =0.02 𝜋
2000

And the impulse response for the low pass filter will be

{
0.02 𝜋
𝑛=𝑛0
𝜋
h ( 𝑛) =
sin 0.02 𝜋 (𝑛 − 𝑛 0)
𝑛 ≠ 𝑛0
(𝑛 − 𝑛 0) 𝜋
Solution
Here we will use 100 data filter (M=100) so will be half of it (100/2 =50).
To generate our impulse response, the command will be
fc=20;
Rc=fc/fs;
plot(t,x)
M=100; %filter order
for n=1:1:M
h(n)=sin(2*Rc*pi*(n-(M/2)))/(n-(M/2))/pi;
end
h(M/2)=Rc;
Solution
To test our filter, we will use convolution between the input signal (x)
with the impulse response (h). The command will be
y=conv(h,x);
And we will get the result of our y to be :

Notice that for the first 50 data (0-


0.025 second), the data will be
distorted due to effect of the delay.
The higher order (M) that we take, the
longer the delay
Solution

Filtered with M=500 Filtered with M=1000


High pass filter
High pass filter is the same as original signal minus low pass filter,
hence the impulse response will be

{
𝜔𝑐
1− 𝑛=𝑛 0
h ( 𝑛) = 𝜋
sin 𝜔 𝑐 (𝑛− 𝑛0 )
− 𝑛 ≠ 𝑛0
(𝑛 − 𝑛 0) 𝜋
Band pass filter
Band pass filter is the same as two low pass filter with different
frequency ( and ) substract each other

{
𝜔𝑐 2 𝜔𝑐 1
− 𝑛=𝑛0
h ( 𝑛) = 𝜋 𝜋
sin 𝜔𝑐 2 (𝑛 − 𝑛 0) − sin 𝜔𝑐 1 (𝑛 − 𝑛0 )
𝑛 ≠ 𝑛0
𝑓 𝑐1 𝑓 𝑐2 (𝑛 − 𝑛 0) 𝜋
Band stop filter
Band pass filter is the same as low pass filter () is added with high pass
filter( )

{
𝜔𝑐 1 𝜔𝑐 2
+1− 𝑛=𝑛0
h ( 𝑛) = 𝜋 𝜋
sin 𝜔𝑐 1 (𝑛 −𝑛 0) − sin 𝜔𝑐 2 (𝑛 − 𝑛0 )
𝑛 ≠ 𝑛0
(𝑛 − 𝑛 0) 𝜋

𝑓 𝑐1 𝑓 𝑐2

You might also like