Uploaded by KRISCHAL KHANAL

FILTER DESIGN LAB Titles 6 files merged

advertisement
FILTER DESIGN [EX704]
Full Marks: 25
LAB 1: REVIEW OF MATLAB
Objectives


To be familiar with the basic function and commands of Matlab
To form sinusoidal, square and sawtooth signals in Matlab
LAB 2: FUNDAMENTALS OF SIGNALS
Objectives


To know about LTI system and check for the linearity
To plot poles and zeros of the continuous-time system using tf2zpk () function and
obtain the transfer function back from the given poles and zeros using zp2tf ()
function.
LAB 3: DESIGN OF IIR DIGITAL FILTER USING IMPULSE
INVARIANCE/BILINEAR METHOD
Objectives

To design IIR digital filter using Impulse Invariance/Bilinear Method
LAB 4: DESIGN OF BUTTERWORTH AND CHEBYSEHEV FILTER
Objectives


To plot and design a Butterworth Filter using buttord() and butter() transfer function
To plot and design Chebyshev type I & II Filters.
LAB 1: REVIEW OF MATLAB
Objectives


To be familiar with the basic function and commands of Matlab
To form sinusoidal, square and sawtooth signals in Matlab
Theory
Matlab – Matrix Laboratory
Windows available in Matlab
1. Command window
We can observe:
i.
ii.
iii.
iv.
Errors
Results
Short code tests
Help
2. Command History
i.
Lists the history of commands
3. Editor window
Can be opened:
i.
ii.
Typing edit command in command window
>> edit (press enter)
Go to File menu -> New -> M-file
Used to write matlab code, edit them if necessary and save as .m file.
4. Basic Matlab operations and commands
i.
ii.
iii.
iv.
v.
Clc:- used to clear the command window
Clear all:- used to clear all the buffer
Close all:- used to close figure windows
Clf:- used to clear the figure window
;:- result suppressor. Suppresses the result.
a. Scalar operation
Type in command window
i.
ii.
x=2: assign value 2 to a variable x.
y=3: assign value 3 to a variable y.
iii.
iv.
v.
vi.
vii.
viii.
ix.
x+y: add x and y. Then the result is displayed in the command window
x-y: subtract y from x and display the result.
x*y: multiply x and y. Also displays the result.
x/y: divide x by y and displays the result
x\y: divide y by x and displays the result
x^y: x raise to the power of y i.e. Performs xy and displays the result.
Rem(x,y) or mod(x,y):- displays the remainder after dividing x by y but
rem() function has sign of x while mod() function has sign of y.
b. Vector operation
i.
X = [1 2 3 4 5] or x= [1,2,3,4,5] :- initializes one-dimensional row vector.
ii.
X=[1;2;3;4;5]:- initializes one-dimensional column vector.
iii.
X=[1 2],y=[2 3],x+y:- adds matrix x and y.
iv.
X=[1,2],y=[1;2],x+y:- observe the command window.
v.
X=[1,2],y=[1,2],x*y:- observe the command window.
vi.
X=[1,2];y=[1,2];x.*y:- performs the element-wise multiplication.
vii.
X=[1,2];y=[1;2];x*y:- performs the array multiplication.
c. Some Matlab functions
i.
transpose(x) or x’:- transposes matrix x.
ii.
factorial(x):- finds the factorial of x.
iii.
input(‘x’):- prompt for the user input.
iv.
Sin(x):- gives the sine of element of x.
v.
Abs(x):- gives the absolute value of x.
vi.
Floor(x):- rounds the elements of x to the nearest integers towards minus
infinity.
vii.
Ceil(x):- rounds the elements of x to the nearest integers towards infinity.
viii. Round(x):- rounds the elements of x to the nearest integers.
ix.
Sqrt(x):- gives the square root of x.
x.
Real(x):- gives the real part of complex number x.
xi.
Imag(x):- gives the imaginary part of complex number x.
xii.
Conj(x):- gives the complex conjugate of x.
Exercises
1. Construct a sinusoidal signal with amplitude 5 units, frequency 4Hz.Then plot the
signal.
clc
close all
clear all
A=5;
f=4;
t=0:0.001:1;
x=A*sin(2*pi*f*t);
plot(t,x);
2. Construct a square wave with an amplitude of 5 units, frequency of 4Hz and duty cycle
of i)1%, ii)50% and iii)90%.
clc
close all
clear all
A=5;
f=4;
t=0:0.001:1;
x=A*square(2*pi*f*t,50);
plot(t,x);
axis([0 1 -5.5 5.5]);
3. Construct a sawtooth wave with amplitude of 5 units, frequency of 4Hz and width of i)
0.1, ii) 0.5 and iii)0.9
clc
close all
clear all
A=5;
f=4;
t=0:0.001:1;
x=A*sawtooth(2*pi*f*t,0.5);
plot(t,x);
4. Plot the signal
x(t)=K*exp(-t), for t>=0
=0, otherwise
where K=3.
clc
close all
clear all
N=10;
i=1;
for t=-N:0.001:N,
if t<0
x(i) = 0;
else
x(i)=3*exp(-t);
end
i=i+1;
end
t=-N:0.001:N;
plot(t,x);
Discussion and Conclusion
LAB 2: FUNDAMENTALS OF SIGNALS
Objectives


To know about LTI system and check for the linearity
To plot poles and zeros of the continuous-time system using tf2zpk () function and
obtain the transfer function back from the given poles and zeros using zp2tf ()
function.
Theory
Linear and Non-linear Systems
A system is said to be linear when it satisfies superposition principle (laws of additivity and
homogeneity). Consider two systems with inputs as x1(t), x2(t), and outputs as y1(t), y2(t)
respectively. Then, according to the laws of additivity and homogeneity,
T [a1 x1(t) + a2 x2(t)] = a1 T[x1(t)] + a2 T[x2(t)]
∴ T [a1 x1(t) + a2 x2(t)] = a1 y1(t) + a2 y2(t)
From the above expression, is clear that response of overall system is equal to response of
individual system.
Example:
(t) = x2(t)
Solution:
y1 (t) = T[x1(t)] = x12(t)
y2 (t) = T[x2(t)] = x22(t)
T [a1 x1(t) + a2 x2(t)] = [ a1 x1(t) + a2 x2(t)]2
Which is not equal to a1 y1(t) + a2 y2(t). Hence the system is said to be non-linear.
Time Variant and Time Invariant Systems
A system is said to be time variant if its input and output characteristics vary with time.
Otherwise, the system is considered as time invariant.
The condition for time invariant system is:
y (n,t) = y(n-t)
The condition for time variant system is:
y (n,t) ≠ y(n-t)
Where y (n,t) = T[x(n-t)] = input change
y (n-t) = output change
Example:
y(n) = x(-n)
y(n,t) = T[x(n-t)] = x(-n-t)
y(n-t) = x(-(n-t)) = x(-n + t)
∴y(n,t) ≠ y(n-t). Hence, the system is time variant.
Linear Time Invariant System
If a system is both linear and time invariant, then that system is called linear time invariant
(LTI) system.
Figure 1: Output of LTI system
Zeros and Poles of a Transfer function
For the given transfer function of a continuous time system in s domain:
𝑁(𝑠)




H(s) = 𝐷(𝑠) =
𝐴(𝑠−𝑧1 )(𝑠−𝑧2 )….(𝑠−𝑧𝑚)
(𝑠−𝑝1 )(𝑠−𝑝2 )….(𝑠−𝑝𝑛 )
The zeros of H(s) are the roots of the numerator, N(s).
The poles of H(s) are the roots of the denominator, D(s).
If n≥m, H(s) is a proper transfer function.
If n>m, H(s) is strictly proper transfer function.
If there are any complex poles, they always appear in conjugate pairs. The poles of H(s)
must lie in the left half of the s-plane if the response is to be bounded or stable. The zeros
may lie in either the right half or the left half of the s-plane.
Determination of system stability using the system poles:

If all of the poles are in the open left-half plane, the system is stable.


If all of the poles are in the left-half plane (includes the imaginary axis) and no
more than one at the origin, the system is marginally stable.
If any of the poles are in the right-half plane, the system is unstable.
Exercises
1. Determine whether the given system is linear or not. Plot the required signals to verify
the result.
Consider two signals: 𝑥1 [𝑛] = 𝑛 and 𝑥2 [𝑛] = sin(𝑛) and the systems are:
a. y[n]=x2[n]
b. y[n]=x[n2]
a.
clc;
clear all;
a1=3;
a2=-7;
n=-3:0.1:3;
x1=n;
x2=sin(n);
y1=x1.^2; %(.^ role is to give element-wise power)
y2=x2.^2;
y3=a1*y1 + a2*y2;
x3=a1*x1+a2*x2;
y4=x3.^2;
subplot(2,1,1);
stem(n,y3);
title('To verify linearity');
xlabel('n');
ylabel('y3[n]');
subplot(2,1,2);
stem(n,y4);
xlabel('n');
ylabel('y4[n]');
b.
clc;
clear all;
a1=3;
a2=-7;
n=-3:0.1:3;
x1=n;
x2=sin(n);
y1=n.^2;
y2=sin(n.^2);
y3=a1*y1 + a2*y2;
x3=a1*x1+a2*x2;
y4=a1*n.^2+a2*sin(n.^2);
c. y[n]=nx[n]
subplot(2,1,1);
stem(n,y3);
title('To verify linearity');
xlabel('n');
ylabel('y3[n]');
subplot(2,1,2);
stem(n,y4);
xlabel('n');
ylabel('y4[n]');
2. Find zeros, poles and gain of the given transfer functions using tf2zpk () function and
plot them.
7𝑠+5
a) G(s)= 𝑠2 +4𝑠+3
b) G(s)=
4𝑠−3
𝑠2 −6𝑠+5
2𝑠2 −3𝑠+9
c) G(s)= 2𝑠2 −7𝑠−6
clc
close all
clear all
num = [7 5]; % numerator of transfer function
den= [1 4 3]; % denominator of transfer function
[z,p,k]= tf2zp(num,den) % to find zeros, poles and gain
%sys=tf(num,den);
%pzmap(sys);
pzmap(p,z); % to plot zeros and poles of the given transfer function
grid on;
%sgrid;
3. Obtain the transfer functions by providing zeros, poles and gain using zp2tf ()
function. Use the poles and zeros of any two questions of question no. 2 and obtain
the required transfer function.
clc
close all
clear all
zz=input('enter zeros')
pp=input('enter poles')
kk=input('enter gain')
[num,den]=zp2tf(zz,pp,kk) % to find the coefficients of numerator and denominator
tf(num,den) % to obtain the required transfer function
Discussion and Conclusion
LAB 3: DESIGN OF IIR DIGITAL FILTER USING IMPULSE
INVARIANCE/BILINEAR METHOD
Objectives

To design IIR digital filter using Impulse Invariance/Bilinear Method
Theory
The infinite impulse response is a type of digital filter that is used in Digital Signal
Processing applications. A filter’s job is to allow certain types of signals to pass and block the
rest.
Infinite impulse response (IIR) is a property applying to many linear time-invariant
systems that are distinguished by having an impulse response h(t) which does not become
exactly zero past a certain point, but continues indefinitely.
The infinite impulse response filter is unique because it uses a feedback mechanism. It
requires current as well as past output data. Though they are harder to design, IIR filters are
computationally efficient and generally cheaper.
Figure 1: Block Diagram of an IIR Filter
Methods to design an IIR Filter
1. Impulse Invariance Method: It is a simple s-plane to z-plane mapping (many to
one). We can design this filter by finding out one very important piece of information
i.e., the impulse response of the analog filter. By sampling the response, we will get
the time-domain impulse response of the discrete filter.
2. Bilinear Transformation Method: It is an improvement over the impulse invariance
method. The many to one mapping in the impulse invariance method (s-domain to zdomain) causes the issue of aliasing, which is highly undesirable. Bilinear transform
removes that issue by using one-to-one mapping. Similarly, the Bilinear transform
helps in the design of certain high pass or band reject filters.
3. Direct Method: Designing analog filters and then converting them to digital.
4. Approximation Method
5. Spectral Transformation
Exercises
The Transfer Function is: H(s)=(s+0.1)/((s+0.1)2+9)
Impulse invariance
a. Convert the analog filter into a digital IIR filter by means of impulse invariance
method.
b. Plot the frequency response in s-domain and z-domain.
c. Plot the impulse response of the LTI model.
d. Plot the impulse response in z-domain.
clc
clear all
close all
b=[1 .1];
a=[1 .2 9.01];
figure;%creates a new figure window using default settings
freqs(b,a);%plots the frequency response in s-domain
figure;
freqz(b,a); %plots the frequency response in z-domain
figure;
subplot(411);
impulse(b,a);
[bz,az]=impinvar(b,a,2);%refer Note
subplot(412);
dimpulse(bz,az);% computes the impulse response of the discrete system model
[bz,az]=impinvar(b,a,10);
subplot(413);
dimpulse(bz,az);
[bz,az]=impinvar(b,a,20);
subplot(414);
dimpulse(bz,az);
Note: [bz,az]=impinvar(b,a,fs) creates a digital filter with numerator and denominator
coefficients bz and az, respectively, whose impulse response is equal to the impulse
response of the analog filter with coefficients b and a, scaled by 1/fs, where fs is the
sample rate.
Bilinear Transformation
a. Convert the analog filter into a digital IIR filter by means of bilinear
transformation method.
b. Plot the frequency response of the transformed filter by bilinear transformation
c. Plot the impulse response in z-domain.
d. Plot the step response of the LTI model.
e. Step response of discrete time linear systems.
clc
close all
clear all
b= [1 .1];
a= [1 .2 9.01];
[bz,az]=bilinear(b,a,2);
figure;
freqz(bz,az);
figure;
dimpulse(bz,az);
figure;
sys=tf(b,a);
step(sys);
figure;
dstep(bz,az);
Discussion and Conclusion
LAB 4: DESIGN OF BUTTERWORTH AND CHEBYSEHEV
FILTER
Objectives


To plot and design a Butterworth Filter using buttord() and butter() transfer function
To plot and design Chebyshev type I & II Filters.
Theory & Exercises
1. Low pass Butterworth filter
With the parameter pass band attenuation, stop band attenuation, pass band edge
frequency, stop band edge frequency and sampling frequency we can design a low
pass Butterworth filter in MATLAB by using following function:
 buttord: Butterworth filter order selection and normalized cut-off
frequency
[n,wn] = buttord(wp, ws, rp, rs) returns the order n of the lowest order
digital Butterworth filter which has a passband ripple of no more than rp
dB and a stopband attenuation of at least rs dB. wp and ws are the
passband and stopband edge frequencies multiplied by sampling frequency.
Also returns wn
 butter: Butterworth digital and analog filter design.
[b, a] = butter(n,wn) designs an nth order lowpass analog Butterworth filter
and returns the filter coefficients in length n+1 vectors num (numerator) and
den (denominator)

impinvar: Impulse invariance method for analog to digital filter
conversion. [bz,az] = impinvar(b,a,Fs) creates a digital filter with
numerator and denominator coefficients b and a respectively whose
impulse response is equal to the impulse response of the analog filter with
coefficients bz and az sampled at a frequency of Fs Hertz
Design of Butterworth Lowpass Filter
An IIR digital low pass filter is required to meet the following specifications:
Pass band attenuation≤ 4 dB
Stop band attenuation≤30 dB
Passband edge=400 Hz
Stopband edge=800Hz
Sample rate=2 KHz
i)
Find its order.
ii)
Plot its frequency response.
iii)
Plot its poles and zeros.
iv)
Plot its impulse response.
v)
Convert this filter into digital IIR filter by means of impulse invariance
method.
vi)
Plot the frequency response in z-domain.
vii)
viii)
Plot the impulse response in z-domain
Step response of the discrete time linear system
clc
close all
clear all
wp=400/2000;
ws=800/2000;
rp=4;
rs=30;
[n,wn]=buttord(wp,ws,rp,rs)
[b,a]=butter(n,wn);
sys=tf(b,a);
figure;
freqs(b,a);
figure;
pzmap(sys);
figure;
impulse(b,a);
[bz,az]=impinvar(b,a,10);
figure;
freqz(bz,az);
figure;
dimpulse(bz,az);
figure;
dstep(bz,az);
2. Chebyshev type I filter:
This filter can be design with the parameter; order of the filter and pass band ripple
in dB. By using following functions in MATLAB:

cheb1ord- Chebyshev Type I filter order
[n,wp] = cheb1ord(wp,ws,rp,rs) returns the lowest order n of the
Chebyshev Type I filter that loses no more than rp dB in the passband and
has at least rs dB of attenuation in the stopband. The scalar (or vector) of
corresponding cutoff frequencies wn is also returned.
 cheby1 - Chebyshev Type I filter design
[b,a] = cheby1(n,rp,wp) returns the transfer function coefficients of an nthorder lowpass digital Chebyshev Type I filter with normalized passband
edge frequency wn and rp decibels of peak-to-peak passband ripple.
3. Chebyshev type II filter
This filter can be design with the parameter; order of the filter and pass band ripple
in dB by using following functions in MATLAB:

cheb2ord- Chebyshev Type II filter order

cheby2 - Chebyshev Type II filter design
Design of Chebyshev I and II Low Pass Filter
Passband attenuation≤1dB
Stopband attenuation≤15dB
Passband edge frequency=0.2π rad/sec
Stopband edge frequency=0.3π rad/sec
i)
Find its order.
ii)
Plot its frequency response.
iii)
Plot its poles and zeros.
iv)
Plot its impulse response.
v)
Convert this filter into digital IIR filter by means of impulse invariance
method.
vi)
Plot the frequency response in z-domain.
vii)
Plot the impulse response in z-domain
viii) Step response of the discrete time linear system
Chebyshev Type I Filter
clc
close all
clear all
wp=0.2*pi;
ws=0.3*pi;
rp=1;
rs=15;
[n,wn]=cheb1ord(wp,ws,rp,rs)
[b,a]=cheby1(n,rp,wn);
sys=tf(b,a);
figure;
freqs(b,a);
figure;
pzmap(sys);
figure;
impulse(b,a);
[bz,az]=impinvar(b,a,10);
figure;
freqz(bz,az);
figure;
dimpulse(bz,az);
figure;
dstep(bz,az);
Chebyshev Type II Filter
clc
close all
clear all
wp=0.2*pi;
ws=0.3*pi;
rp=1;
rs=15;
[n,wn]=cheb2ord(wp,ws,rp,rs)
[b,a]=cheby2(n,rs,wn);
sys=tf(b,a);
figure;
freqs(b,a);
figure;
pzmap(sys);
figure;
impulse(b,a);
[bz,az]=impinvar(b,a,10);
figure;
freqz(bz,az);
figure;
dimpulse(bz,az);
figure;
dstep(bz,az);
Discussion and Conclusion
Subject: Filter Design (Practical)
Name: ______________________
Roll No: _______
MULTIPLE CHOICE QUESTIONS (MCQs)
F.M=10
P.M=4
Time: 10 min


Choose the correct answer(s) for each of the following questions
Each question carries one mark
1.
Which of the following isn’t true about MATLAB?
o MATLAB is capable of handling a huge library of mathematical functions.
o MATLAB has multi-platform deployment features.
o MATLAB is a procedural oriented programming language.
o MATLAB can handle complex graphics, data processing, machine learning, neural networks and many more.
2.
Which of the following commands is used to clear all the contents of command window in MATLAB?
clc
clear
clear all
close all
o
o
o
o
3.
subplot (547) means it plots a figure as:
4.
‘IR’ in FIR and IIR stands for:
o Infinite Response
o Immediate Response
o Immense Regret
o Impulse Response
5.
The method which implements many to one mapping while transforming analog filter to digital is:
o Bilinear Transformation Method
o Impulse Invariance Method
o Many to one Conversion Method
o Spectral Transformation Method
6.
If b and a are the numerator and denominator of the transfer function of an analog system, choose the correct MATLAB
function(s):
freqz(b,a);
impulse(b,a);
freqs(b,a);
dstep(b,a);
7.
If sampling rate is 80Hz and cut-off frequency is 10Hz, then the normalized frequency is given by:
0.25
0.5
0.75
0.8
o
o
o
o
8.
Which of the following functions is incorrect?
o [b,a]=butter(n,wn);
o [b,a]=cheby1(n,wn);
o dimpulse(bz,az);
o a=strcmp(s1,s2);
9.
Which of the following is true in case of Butterworth filters?
o Smooth pass band
o Wide transition band
o Not so smooth stop band
o All of the above
10. The following program results into:
clc
close all
clear all
n=5;
wn=1.2;
[b,a]=butter(n,wn);
figure;
freqs(b,a);
None of these
***ALL THE BEST***
Related documents
Download