Professional Documents
Culture Documents
Imtiyaz Mohiuddin
10361A0434
In charge
Dr.M.Narayana
Electronics and Communications Engineering
SECTION OUTLINE:
Introduction to Digital filter design
Introduction to FIR Filter
Design of FIR Filter using WINDOW Techniques
Introduction to IIR Filter
Design of IIR Filter using Approximation Method
MATLAB Code of Designed Filters
Introduction:
A digital filter is a system that performs mathematical
operations on a sampled, discrete-time signal to reduce or
enhance certain aspects of that signal.
In digital signal processing, there are two important types
of systems:
Digital filters: perform signal filtering in the time
domain
Spectrum analyzers: provide signal representation in the
frequency domain
Digital Filter:
Sampling
frequency
fS
Analog xn yn
x(t) anti- A D Analog y(t)
aliasing D Digital Filter A smoothing
C C filter
filter
Preliminaries:
The design of a digital filter is carried out in three steps:
Specifications: they are determined by the applications
Approximations: once the specification are defined, we use various
concepts and mathematics that we studied so far to come up with a
filter description that approximates the given set of specifications.
(in detail)
Implementation: The product of the above step is a filter
description in the form of either a difference equation, or a system
function H(z), or an impulse response h(n). From this description
we implement the filter in hardware or through software on a
computer.
Classification:
Digital filters are classified into one of two basic forms,
according to how they respond to a unit impulse:
Finite impulse response
Infinite impulse response
Finite Impulse Response:
In signal processing, a finite impulse response
(FIR) filter is a filter whose impulse response is
of finite duration, because it settles to zero in finite
time.
FIR digital filters use only current and past input
samples, and none of the filter's previous output
samples, to obtain a current output sample value
The transfer function is given by
N 1
H ( z ) h(n).z n
n 0
n
d
j n
hd n
1
2
Hd
e j
e jn
d
4.54 2.9/N 50
6.76 4.3/N 70
8.96 5.7/N 90
Rectangular Window
Narrowest main lob
– 4/(M+1)
– Sharpest transitions at
discontinuities in frequency
1 0 n M
wn
0 else
2
I0 1 n M / 2
M / 2
wn
0nM
I0(.) represents zeroth-order
I0 Bessel
modified function of 1st kind
0 else
MATLAB CODE:
%Design of LPF&HPF using rectangular,hamming and kaiser windows
clc;clear all;close all;
rp=input('enter attenuation in pass band');
rs=input('enter attenuation in stop band');
fp=input('enter pass band frequency');
fs=input('enter stop band frequency');
Fs=input('enter sampling frequency');
wp=2*pi*fp/Fs;
ws=2*pi*fs/Fs;
%formula for FIR filter
num=-20*log10(sqrt(rp*rs))-13;
den=14.6*(fs-fp)/Fs;
n=ceil(num/den);
disp('order of filter is \n');
disp(n);
disp('press any key to continue');
pause;
n1=n+1;
%For even order
if(rem(n,2)~=0)
n1=n;
end
%LPF
%LPF
s1=input('enter the value for window 0-rectangularLPF 1-kaiserLPF 2-hammingLPF 3-
rectangularHPF 4-kaiserHPF 5-hammingHPF');
switch(s1);
case 0
y=rectwin(n1);
[b,a]=fir1(n,wp,'low',y);
freqz(b,a,512);
case 1
y=kaiser(n1);
[b,a]=fir1(n,wp,'low',y);
freqz(b,a,512);
case 2
y=hamming(n1);
[b,a]=fir1(n,wp,'low',y);
freqz(b,a,512);
case 3
y=rectwin(n1);
[b,a]=fir1(n,wp,'high',y);
freqz(b,a,512);
case 4
y=kaiser(n1);
[b,a]=fir1(n,wp,'high',y);
freqz(b,a,512);
case 5
y=hamming(n1);
[b,a]=fir1(n,wp,'high',y);
freqz(b,a,512);
end
Pros & Cons:
FIR filters have the following
advantages: FIR filters have the following
disadvantages:
Exactly linear phase is possible
• Higher filter order than IIR
Always stable, even when quantized filters
Design methods are generally linear • Corresponding greater
delays
Efficient hardware realizations
[B,A] = BUTTER(N,Wn)
[B,A] = CHEBY1(N,R,Wn)
[B,A] = CHEBY2(N,R,Wn)
[B,A] = ELLIP(N,Rp,Rs,Wn)
– N = filter order
– R = pass band ripple (cheby1) or stop-band ripple (cheby2) in
dB. (Rp and Rs respectively for the elliptic filter)
– Wn = cut-off frequency (radians/sec for analog filters or
normalized digital frequencies for digital filters)
– [B,A] = filter coefficients, s-domain (analog filter) or z-domain
(digital filter)
Design Example
Filter Specifications:
Butterworth response
Pass-band edges = 400 Hz and 600 Hz
Stop-band edges = 300 Hz and 700 Hz
Pass-band ripple = 1 dB
Stop-band attenuation = -20 dB
Sampling Frequency = 2000 Hz
Design Example Results
Magnitude Response
1.4
1.2
1
Magnitude
0.8
Band Edges
0.6
(-1dB and -20 dB)
0.4
0.2
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
Frequency (kHz)
Design Example
Chebyshev II High-Pass Filter
Filter specifications:
Chebyshev II response (stop-band ripple)
Pass-band edge = 1000 Hz
Stop-band edge = 900 Hz
Pass-band ripple = 1 dB
Stop-band attenuation = -40 dB
Sampling frequency = 8 kHz
MATLAB Code for Design Example
>> fs=8000;
>> Wp=[2*1000/fs]; % Pass-band edge normalized digital frequency
>> Ws=[2*900/fs]; % Stop-band edge normalized digital frequency
>> [N,Wn]=cheb2ord(Wp,Ws,1,40); % The “order” command
>> [B,A]=cheby2(N,40,Wn,'high');
% cheby2 is the “filter” command. In this command
% the syntax requires the stop-band attenuation
% as the second parameter
>> fvtool(B,A)
Design Example Results
-20
Magnitude (dB)
-40
-60
-80
-100
0 0.5 1 1.5 2 2.5 3 3.5
Frequency (kHz)
MATLAB CODE:
%Design of IIR filters
fp1=input('enter pass band frequency');
fs1=input('enter stop band frequency');
Fs1=input('enter sampling frequency');
wp1=fp1/Fs1;
ws1=fs1/Fs1;
[n1,wn1]=buttord(wp1,ws1,2,60);
[x,y]=butter(n1,wn1,'low');
figure;
freqz(x,y,512);
[n1,wn1]=buttord(wp1,ws1,2,60);
[x,y]=butter(n1,wn1,'high');
figure;
freqz(x,y,512);
[n1,wn1]=cheb1ord(wp1,ws1,2,60);
[x,y]=cheby1(n1,3,wn1,'low');
figure;
freqz(x,y,512);
[n1,wn1]=cheb1ord(wp1,ws1,2,60);
[x,y]=cheby1(n1,3,wn1,'high');
figure;
freqz(x,y,512);
Summary of IIR Filter: