DSP File
DSP File
What Is MATLAB?
MATLAB is an interactive system whose basic data element is an array that does not
require dimensioning. This allows you to solve many technical computing problems,
especially those with matrix and vector formulations, in a fraction of the time it would
take to write a program in a scalar noninteractive language such as C or Fortran.
The name MATLAB stands for matrix laboratory. MATLAB was originally written to
provide easy access to matrix software developed by the LINPACK and EISPACK
projects, which together represent the state-of-the-art in software for matrix
computation.
MATLAB has evolved over a period of years with input from many users. In
university environments, it is the standard instructional tool for introductory and
advanced courses in mathematics, engineering, and science. In industry, MATLAB is
the tool of choice for high-productivity research, development, and analysis.
1
MATLAB features a family of application-specific solutions called toolboxes. Very
important to most users of MATLAB, toolboxes allow you to learn and apply
specialized technology. Toolboxes are comprehensive collections of MATLAB
functions (M-files) that extend the MATLAB environment to solve particular classes
of problems. Areas in which toolboxes are available include signal processing, control
systems, neural networks, fuzzy logic, wavelets, simulation, and many others.
Handle Graphics.
This is the MATLAB graphics system. It includes high-level commands for two-
dimensional and three-dimensional data visualization, image processing, animation,
and presentation graphics. It also includes low-level commands that allow you to fully
customize the appearance of graphics as well as to build complete Graphical User
Interfaces on your MATLAB applications.
2
The MATLAB mathematical function library.
This is a vast collection of computational algorithms ranging from elementary
functions like sum, sine, cosine, and complex arithmetic, to more sophisticated
functions like matrix inverse, matrix eigenvalues, Bessel functions, and fast Fourier
transforms.
To view the online documentation, select MATLAB Help from the Help menu in
MATLAB. Online help appears in the Help browser, providing task-oriented and
reference information about MATLAB features. For more information about using the
Help browser, including typographical conventions used in the documentation.
←
Desktop Tools and Development Environment — Startup and shutdown, the
desktop, and other tools that help you use MATLAB
←
Mathematics — Mathematical operations
←
Data Analysis — Data analysis, including data fitting, Fourier analysis, and
time-series tools
←
Programming — The MATLAB language and how to develop MATLAB
applications
3
←
Graphics — Tools and techniques for plotting, graph annotation, printing, and
programming with Handle Graphics®
←
3-D Visualization — Visualizing surface and volume data, transparency, and
viewing and lighting techniques
←
Creating Graphical User Interfaces — GUI-building tools and how to write
callback functions
←
External Interfaces — MEX-files, the MATLAB engine, and interfacing to
Java, COM, and the serial port
← C and Fortran API Reference — Covers those functions used by the MATLAB
external interfaces, providing information on syntax in the calling language,
description, arguments, return values, and examples
Summary by Version
This table provides quick access to what's new in each version. For clarification, see
About Release Notes.
4
Version New Version Fixed Bugs Related
(Release) Features Compatibility and Known Documentation at
and Considerations Problems Web Site
Changes
(R2007b) documentation
V7.4 Yes Yes Bug Reports No
(R2007a) Details Summary Includes fixes
V7.3 Yes Yes Bug Reports No
(R2006b) Details Summary Includes fixes
V7.2 Yes Yes Bug Reports No
(R2006a) Details Summary Includes fixes
V7.1 Yes Yes Bug Reports No
(R14SP3) Details Summary Includes fixes
V7.0.4 Yes Yes Bug Reports No
(R14SP2) Details Summary Includes fixes
V7.0.1 Yes Yes Fixed bugs No
(R14SP1) Details Summary
V7 (R14) Yes Yes Fixed bugs No
Details Summary
Use release notes when upgrading to a newer version to learn about new features and
changes, and the potential impact on your existing files and practices. Release notes
are also beneficial if you use or support multiple versions.
If you are not upgrading from the most recent previous version, review release notes
for all interim versions, not just for the version you are installing. For example, when
upgrading from V1.0 to V1.2, review the New Features and Changes, Version
Compatibility Considerations, and Bug Reports for V1.1 and V1.2.
These include:-
5
1. New functionality
Compatibility issues that are reported after the product has been released are added to
Bug Reports at the MathWorks Web site. Because bug fixes can sometimes result in
incompatibilities, also review fixed bugs in Bug Reports for any compatibility impact.
Access Bug Reports at the MathWorks Web site using your MathWorks Account. If
you are not logged in to your MathWorks Account when you link to Bug Reports, you
are prompted to log in or create an account. You then can view bug fixes and known
problems for R14SP2 and more recent releases.
The Bug Reports database was introduced for R14SP2 and does not include
information for prior releases. You can access a list of bug fixes made in prior versions
via the links in the summary table.
6
EXPERIMENT NO.-1
AIM
Write a program to represent basic signals (unit step, unit impulse ramp, exponential,
sine & cosine)
REQUIREMENT
THEORY
.
, 1 otherwise
7
ALGORITHM
1. Enter the in values for unit step sequence and the length of ramp sequence
or exponential sequence.
2. Determine the function.
3. Plot the values as given by the function.
4. Stop.
PROGRAM
8
subplot(2,2,3);
stem(t,t);
ylabel('Amplitude -- >');
xlabel('(c) n -- >');
9
FIGURES
Amplitude -- > 1 1
Amplitude -- >
0.5 0.5
0 0
-2 -1 0 1 2 0 5 10
(a) n -- > (b) n -- >
4
x 10
10 3
Amplitude -- >
Amplitude -- >
2
5
1
0 0
0 5 10 0 5 10
(c) n -- > (d) n -- >
(Figures for unit Impulse, unit step, ramp function & exponential functi
1
Amplitude -- >
0.5
-0.5
-1
0 0.5 1 1.5 2 2.5 3 3.5
(a) n -- >
0.5
Amplitude -- >
-0.5
-1
0 0.5 1 1.5 2 2.5 3 3.5
(b) n -- >
10
EXPERIMENT NO.- 2
AIM
REQUIREMENT
ALGORITHM
For Correlation:-
1. Get two signals x(m) & h(p) in matrix form.
2. The correlated signal is denoted as y(n).
3. Y(n) is given by formula
4. Stop.
For convolution:-
1. Get two signals x(m) & h(p) in matrix form.
2. The convoluted signal is denoted as y(n).
3. Y(n) is given by formula
4. Stop.
PROGRAM
11
subplot (3,2,3);
stem (c);
INPUTS
enter the first sequence:[1 2 3 4]
enter the second sequence:[4 3 2 1
FIGURES
PROGRAM
clc;
clear all ;
close all;
x= input ('enter the 1st sequence');
h=input ('enter the 2nd sequence');
y=conv (x,h);
figure;subplot (3,1,1);
stem(x);ylabel ('amplitude-->');
12
xlabel ('(a)n-->');
subplot (3,1,2);
stem (h);ylabel ('amplitude-->');
xlabel ('(b)n-->');
subplot (3,1,3);
stem(y);ylabel ('amplitude-->');
xlabel ('(c)n-->');
disp ('the resultant signal is');
INPUTS
enter the 1st sequence[1 2 ]
enter the 2nd sequence[1 2 4]
the resultant signal is y=1 4 8 8
FIGURE
13
14
EXPERIMENT NO.- 3
AIM:
To Understand Stability Test.
REQUIREMENT:
THEORY: The stability of discrete time LTI system is equivalent to its impulse
response being absolutely summable, i.e.,
In this case the DTFT of h(n) converges and the ROC of transfer function H(Z) must
include the unit circle |Z|=1. A discrete time LTI system is stable if and only if ROC of
its transfer function H(Z) include the unit circle |Z|=1.
It is perfectly possible for a system to be stable and not causal. For causal systems,
stability can easily be checked by examining the locations of poles in transfer function
H(Z). for a causal discrete time LTI system with rational transfer function H(Z), the
ROC is outside the outermost pole. A causal discrete time LTI system with rational
transfer function H(Z), is stable if and only if all of the poles of H(Z) lie inside the
unit circle |Z|=1.
PROGRAM :
Clc;
clear all;
close all;
b=input('Enter the denominator coefficients of the filter');
k=poly2rc(b);
knew=fliplr(k);
s=all(abs(knew));
15
if(s==1);
disp('"Stable system"');
else
disp('"Non stable system"');
end
RESULT:
Enter the denominator coefficients of the filter [1 -1 .5]
b =1.0000 -1.0000 0.5000
“Stable system”
CONCLUSION:
The MATLAB program for stability test is written and stability is verified.
16
EXPERIMENT NO.-4
AIM
To design Butterworth Digital IIR Filter (Low Pass, High Pass,Band Pass & Band
Stop).
REQUIREMENT
MATLAB Software 7R14
ALGORITHM
1. Get the passband & stopband ripples.
2. Get the passband & stopband edge frequencies.
3. Get the sampling frequency.
4. Calculate the order of the filter
5. Find the filter coefficients.
6. Draw the magnitude & Phase response.
PROGRAM
17
[b,a]=butter(n,wn);
w=0:.01:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(om/pi,m);
ylabel('gain in db ----->');
xlabel ('normalized frequency---->');
subplot(2,1,2);
plot(om/pi,an);
xlabel('normalized ferquency ->');
ylabel('phase in radians->');
18
xlabel ('normalized frequency---->');
subplot(2,1,2);
plot(om/pi,an);
xlabel('normalized ferquency ->');
ylabel('phase in radians->');
clc;
clear all;
close all;
rp= input('enter the pass band ripple');
rs= input('enter the stop band ripple');
wp= input('enter the pass band frequency');
ws= input('enter the stop band frequency');
fs= input('enter the sampling frequency');
w1= 2*wp/fs;
w2= 2*ws/fs;
[n]= buttord(w1,w2,rp,rs);
wn=[w1 w2];
[b,a]=butter(n,wn,'bandpass');
w=0:0.1:pi;
[h,om]= freqz (b,a,w);
m=20*log10(abs (h));
an=angle(h);
subplot(2,1,1);
plot(om/pi,m);
xlabel('freq');
ylabel('gain');
title('butterworth gain response');
subplot(2,1,2);
19
plot(om/pi,an);
xlabel('freq');
ylabel('angle');
title('butterworth phase response');
clc;
clear all;
close all;
rp= input('enter the pass band ripple');
rs= input('enter the stop band ripple');
wp= input('enter the pass band frequency');
ws= input('enter the stop band frequency');
fs= input('enter the sampling frequency');
w1= 2*wp/fs;
w2= 2*ws/fs;
[n]= buttord(w1,w2,rp,rs);
wn=[w1 w2];
[b,a]=butter(n,wn,'stop');
w=0:0.1:pi;
[h,om]= freqz(b,a,w);
m=20*log10(abs (h));
an=angle(h);
subplot(2,1,1);
plot(om/pi,m);
xlabel('freq');
ylabel('gain');
title('butterworth gain response');
subplot(2,1,2);
20
plot(om/pi,an);
xlabel('freq');
ylabel('angle');
title('butterworth phase response');
INPUT
Low pass:-
enter the passband ripple 0.5
enter the passband ripple 50
enter the passband frequency 1200
enter the stopband frequency 2400
enter the sampling frequeny 10000
High pass:-
enter the passband ripple 0.5
enter the passband ripple 50
enter the passband frequency 1200
enter the stopband frequency 2400
enter the sampling frequeny 10000
Band pass:-
enter the pass band ripple 0.3
enter the stop band ripple 40
enter the pass band frequency 1500
enter the stop band frequency 2000
enter the sampling frequency 9000
Band stop:-
enter the pass band ripple 4
enter the stop band ripple 46
enter the pass band frequency 1100
enter the stop band frequency 2200
enter the sampling frequency 6000
21
FIGURES
100
0
gain
-100
-200
-300
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normalised freq
2
phase in rad
-2
-4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normalised freq
22
-20
gain in db ----->
-40
-60
-80
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normalized frequency---->
4
phase in radians->
-2
-4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normalized ferquency ->
23
butterworth gain response
0
-200
gain
-400
-600
-800
0 0.2 0.4 0.6 0.8 1
freq
butterworth phase response
4
2
angle
-2
-4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
freq
.
(Band pass Filter Graph)
0
gain
-50
-100
-150
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
freq
butterworth phase response
4
2
angle
-2
-4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
freq
24
EXPERIMENT NO.-5
AIM
Write a MATLAB program to design Chebyshev Type-I (Low pass filter, High
pass,Band pass& Band stop filter)
REQUIREMENT
MATLAB Software 7R14
ALGORITHM
1. Get the passband & stopband ripples.
2. Get the passband & stopband edge frequencies.
3. Get the sampling frequency.
4. Calculate the order of the filter
5. Find the filter coefficients.
6. Draw the magnitude & Phase response.
PROGRAM
%WRITE A MATLAB PROGRAM TO DESIGN CHEBYSHEV TYPE-I LOW PASS
FILTER
clc;
close all;
clear all;
format long
rp= input ('enter the passband ripple....');
rs= input ('enter the stopband ripple....');
wp= input ('enter the passband freq....');
ws= input ('enter the stopband freq....');
fs= input ('enter the sampling freq....');
w1=2*wp/ fs;
25
w2=2*ws/ fs;
[n, wn]=cheb1ord (w1,w2,rp,rs,'s');
[b,a]=cheby1(n,rp,wn,'s');
w=0: .01:pi;
[h,om] = freqz(b,a,w);
m=20*log10(abs(h));
an=angle (h);
subplot (2,1,1); plot (om/pi,m);
ylabel('Gain in dB-->'); xlabel('(a) Normalised frequency-->');
subplot (2,1,2); plot (om/pi,an);
ylabel('Phase in radians-->'); xlabel('(b) Normalised frequency-->');
%WRITE A MATLAB PROGRAM TO DESIGN CHEBYSHEV TYPE-I HIGHPASS
FILTER
clc;
close all;
clear all;
format long
rp= input ('enter the passband ripple....');
rs= input ('enter the stopband ripple....');
wp= input ('enter the passband freq....');
ws= input ('enter the stopband freq....');
fs= input ('enter the sampling freq....');
w1=2*wp/ fs;
w2=2*ws/ fs;
[n, wn]=cheb1ord (w1,w2,rp,rs);
[b,a]=cheby1(n,rp,wn,'high');
w=0: .01/pi:pi;
[h,om] = freqz(b,a,w);
m=20*log10(abs(h));
an=angle (h);
subplot (2,1,1); plot (om/pi,m);
26
ylabel('Gain in dB-->'); xlabel('(a) Normalised frequency-->');
subplot (2,1,2); plot (om/pi,an);
ylabel('Phase in radians-->'); xlabel('(b) Normalised frequency-->');
27
%WRITE A MATLAB PROGRAM TO DESIGN CHEBYSHEV TYPE-I LOW BAND
STOP FILTER
clc;
close all;
clear all;
format long
rp= input ('enter the passband ripple....');
rs= input ('enter the stopband ripple....');
wp= input ('enter the passband freq....');
ws= input ('enter the stopband freq....');
fs= input ('enter the sampling freq....');
w1=2*wp/ fs;
w2=2*ws/ fs;
[n]=cheb1ord (w1,w2,rp,rs);
wn=[w1,w2];
[b,a]=cheby1(n,rp,wn,'stop');
w=0: .01:pi;
[h,om] = freqz(b,a,w);
m=20*log10(abs(h));
an=angle (h);
subplot (2,1,1); plot (om/pi,m);
ylabel('Gain in dB-->'); xlabel('(a) Normalised frequency-->');
subplot (2,1,2); plot (om/pi,an);
ylabel('Phase in radians-->'); xlabel('(b) Normalised frequency-->');
28
INPUTS
Low pass:-
enter the passband ripple....0.23
enter the stopband ripple....47
enter the passband freq....1300
enter the stopband freq....1550
enter the sampling freq....7800
High pass:-
Band Pass:-
enter the passband ripple.....4
enter the stopband ripple....35
enter the passband freq....2000
enter the stopband freq....2500
enter the sampling freq....10000
Band Stop:-
enter the passband ripple.....25
enter the stopband ripple....40
enter the passband freq....2500
enter the stopband freq....2750
enter the sampling freq....7000
29
FIGURES
LOW PASS
30
0
-100
Gain in dB-->
-200
-300
-400
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
(a) Normalised frequency-->
4
Phase in radians-->
-2
-4 31
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
(b) Normalised frequency-->
HIGH PASS
BAND PASS
0
Gain in dB-->
-200
-400
-600
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
(a) Normalised frequency-->
4
Phase in radians-->
-2
-4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
(b) Normalised frequency-->
32
BANDSTOP
-50
Gain in dB-->
-100
-150
-200
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
(a) Normalised frequency-->
4
Phase in radians-->
-2
-4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
(b) Normalised frequency-->
EXPERIMENT NO.- 6
AIM
Write a MATLAB program to design an FIR Low pass,High pass,Band pass, Band
stop filter using Rectangular window.
33
REQUIREMENT
MATLAB Software 7R14
ALGORITHM
1. Get the passband & stopband ripples.
2. Get the passband & stopband edge frequencies.
3. Get the sampling frequency.
4. Calculate the order of the filter
5. Find the filter coefficients.
6. Draw the magnitude & Phase response.
PROGRAM
% PROGRAM TO DESIGN FIR LOW PASS FILTER AND HIGH PASS FILTER
USING RECTANGULAR WINDOW
clc;
clear all;
close all;
rp=input('enter the passband ripple');
rs=input('enter the stopband ripple');
34
n=ceil(num/dem);
n1= n+1;
if (rem(n,2)~=0)
n1=n;
n=n-1
end
y=boxcar(n1);
m=20*log10(abs(h));
subplot (2,2,2);
plot(o/pi,m);
ylabel('Gain in dB-->');
xlabel('(b)Normalized frequency-->');
35
wn=[wp,ws];
b= fir1(n,wn,y);
[h,o]= freqz(b,1,256);
m=20*log10(abs(h));
subplot (2,2,3);
plot(o/pi,m);
ylabel('Gain in dB-->');
xlabel('(c) Normalized frequency-->');
INPUT
enter the passband ripple0.05
enter the stopband ripple0.04
enter the passband frequency1500
enter the stopband frequency2000
enter the sampling frequency9000
FIGURES
36
Gain in dB--> 50 50
Gain in dB-->
0 0
-50 -50
-100 -100
0 0.5 1 0 0.5 1
(a) Normalized frequency--> (b) Normalized frequency-->
50 10
Gain in dB-->
0 Gain in dB--> 0
-50 -10
-100 -20
0 0.5 1 0 0.5 1
(c) Normalized frequency--> (d) Normalized frequency-->
EXPERIMENT NO.-7
AIM
To develop a program to design a FIR Low Pass, High Pass, Band Pass & Band Stop
Filter using Kaiser window.
37
REQUIREMENT
MATLAB Software 7R14
ALGORITHM
1. Get the passband & stopband ripples.
2. Get the passband & stopband edge frequencies.
3. Get the sampling frequency.
4. Calculate the order of the filter.
5. Find the filter coefficients.
6. Draw the magnitude & Phase response.
PROGRAM
%PROGRAM FOR THE DESIGN OF FIR LOW PASS, HIGH PASS, BAND PASS &
BAND STOP FILTERS USING KAISER WINDOW
clc;
clear all;
close all;
rp = input ('enter the passband ripple');
rs = input ('enter the stopband ripple');
fp = input ('enter the passband frequency');
fs = input ('enter the stopband frequency');
f = input ('enter the sampling frequency');
beta= input ('enter the beta value');
wp=2*fp/f; ws=2*fs/f;
num= -20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n= ceil(num/dem);
n1= n+1;
if (rem(n,2)~=0)
n1=n;
38
n=n-1;
end
y=kaiser(n1, beta);
b= fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,2);
plot(o/pi, m);
ylabel('Gain in dB-->');
xlabel('(b) Normalized Frequency');
%BANDPASS FILTER
wn=[wp ws];
b= fir1(n,wn,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
39
subplot(2,2,3);
plot(o/pi, m);
ylabel('Gain in dB-->');
xlabel('(c)Normalized Frequency');
%BANDSTOP FILTER
b= fir1(n,wn,'stop',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,4);
plot(o/pi, m);
ylabel('Gain in dB-->');
xlabel('(d)Normalized Frequency');
INPUT
enter the passband ripple0.02
enter the stopband ripple0.01
enter the passband frequency1000
enter the stopband frequency1500
enter the sampling frequency10000
enter the beta value5.8
FIGURES
40
41
EXPERIMENT NO.-8
AIM
To develop a program to design a FIR Low Pass, High Pass, Band Pass & Band Stop
Filter using Bartlett window.
REQUIREMENT
MATLAB Software 7R14
ALGORITHM
1. Get the passband & stopband ripples.
2. Get the passband & stopband edge frequencies.
3. Get the sampling frequency.
4. Calculate the order of the filter.
5. Find the filter coefficients.
6. Draw the magnitude & Phase response.
PROGRAM
%PROGRAM FOR THE DESIGN OF FIR LOW PASS, HIGH PASS, BAND PASS &
BAND STOP FILTERS USING BARTLETT WINDOW
clc;
clear all;
close all;
rp = input ('enter the passband ripple');
rs = input ('enter the stopband ripple');
fp = input ('enter the passband frequency');
fs = input ('enter the stopband frequency');
f = input ('enter the sampling frequency');
beta= input ('enter the beta value');
wp=2*fp/f; ws=2*fs/f;
42
num= -20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n= ceil(num/dem);
n1= n+1;
if (rem(n,2)~=0)
n1=n;
n=n-1;
end
y=bartlett(n1);
b= fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,1);
plot(o/pi, m);
ylabel('Gain in dB-->');
xlabel('(a) Normalized Frequency');
b= fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,2);
plot(o/pi, m);
ylabel('Gain in dB-->');
xlabel('(b) Normalized Frequency');
43
%BANDPASS FILTER
wn=[wp ws];
b= fir1(n,wn,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,3);
plot(o/pi, m);
ylabel('Gain in dB-->');
xlabel('(c) Normalized Frequency');
%BANDSTOP FILTER
b= fir1(n,wn,'stop',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,4);
plot(o/pi, m);
ylabel('Gain in dB-->');
xlabel('(d) Normalized Frequency');
INPUT
enter the passband ripple .04
enter the stopband ripple .02
enter the passband frequency 1500
enter the stopband frequency 2000
enter the sampling frequency 8000
44
FIGURES
0 10
-10 0
Gain in dB-->
Gain in dB-->
-20 -10
-30 -20
-40 -30
0 0.5 1 0 0.5 1
(a) Normalized Frequency (b) Normalized Frequency
20 5
Gain in dB-->
Gain in dB-->
0 0
-20 -5
-40 -10
0 0.5 1 0 0.5 1
(c) Normalized Frequency (d) Normalized Frequency
45
EXPERIMENT NO.-9
AIM
To develop a program to design a FIR Low Pass, High Pass, Band Pass & Band Stop
Filter using Hanning window.
REQUIREMENT
MATLAB Software 7R14
ALGORITHM
1. Get the passband & stopband ripples.
2. Get the passband & stopband edge frequencies.
3. Get the sampling frequency.
4. Calculate the order of the filter.
5. Find the filter coefficients.
6. Draw the magnitude & Phase response.
PROGRAM
%PROGRAM FOR THE DESIGN OF FIR LOW PASS, HIGH PASS, BAND PASS &
BAND STOP FILTERS USING HANNING WINDOW
clc;
clear all;
close all;
rp=input('enter the passband ripple');
rs=input('enter the stopband ripple');
fp=input('enter the passband frequency');
fs=input('enter the stopband frequency');
f=input('enter the sampling frequency');
wp=2*fp/f;
46
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n=ceil(num/dem);
n1=n+1;
if(rem(n,2)~=0)
n1=n;
n=n-1;
end
y=hanning(n1);
b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs (h));
subplot(2,2,1);
plot(o/pi,m);
ylabel('Gain in dB-->');
xlabel('(a) Normalized Frequency');
b= fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,2);
plot(o/pi, m);
ylabel('Gain in dB-->');
xlabel('(b) Normalized Frequency');
%BANDPASS FILTER
47
wn=[wp ws];
b= fir1(n,wn,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,3);
plot(o/pi, m);
ylabel('Gain in dB-->');
xlabel('(c) Normalized Frequency');
%BANDSTOP FILTER
b= fir1(n,wn,'stop',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,4);
plot(o/pi, m);
ylabel('Gain in dB-->');
xlabel('(d) Normalized Frequency');
INPUT
enter the passband ripple .03
enter the stopband ripple .01
enter the passband frequency 1400
enter the stopband frequency 2000
enter the sampling frequency 8000
48
FIGURES
50 50
Gain in dB-->
Gain in dB-->
0 0
-50 -50
-100 -100
0 0.5 1 0 0.5 1
(a) Normalized Frequency (b) Normalized Frequency
0 5
0
Gain in dB-->
Gain in dB-->
-50
-5
-100
-10
-150 -15
0 0.5 1 0 0.5 1
(c) Normalized Frequency (d) Normalized Frequency
EXPERIMENT NO.-10
49
AIM
To develop a program to design a FIR Low Pass, High Pass, Band Pass & Band Stop
Filter using Blackman window.
REQUIREMENT
MATLAB Software 7R14
ALGORITHM
1. Get the passband & stopband ripples.
2. Get the passband & stopband edge frequencies.
3. Get the sampling frequency.
4. Calculate the order of the filter.
5. Find the filter coefficients.
6. Draw the magnitude & Phase response.
PROGRAM
%PROGRAM FOR THE DESIGN OF FIR LOW PASS, HIGH PASS, BAND PASS &
BAND STOP FILTERS USING BLACKMAN WINDOW
clc;
clear all;
close all;
50
wp=2*fp/f; ws=2*fs/f;
num= -20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n= ceil(num/dem);
n1= n+1;
if (rem(n,2)~=0)
n1=n;
n=n-1;
end
y=blackman(n1);
b= fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,1);
plot(o/pi, m);
ylabel('Gain in dB-->');
51
b= fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,2);
plot(o/pi, m);
ylabel('Gain in dB-->');
%BANDPASS FILTER
wn=[wp ws];
b= fir1(n,wn,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,3);
plot(o/pi, m);
ylabel('Gain in dB-->');
xlabel('(c)Normalized Frequency');
%BANDSTOP FILTER
b= fir1(n,wn,'stop',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,4);
plot(o/pi, m);
ylabel('Gain in dB-->');
52
xlabel('(d) Normalized Frequency');
INPUT
enter the passband ripple .03
enter the stopband ripple.01
enter the passband frequency2000
enter the stopband frequency2500
enter the sampling frequency7000
FIGURES
50 50
0 0
Gain in dB-->
Gain in dB-->
-50 -50
-100 -100
-150 -150
0 0.5 1 0 0.5 1
(a) Normalized Frequency (b) Normalized Frequency
0 5
Gain in dB-->
Gain in dB-->
-50 0
-100 -5
-150 -10
0 0.5 1 0 0.5 1
(c) Normalized Frequency (d) Normalized Frequency
EXPERIMENT NO.-11
53
AIM
To develop a program to design a FIR Low Pass, High Pass, Band Pass & Band Stop
Filter using Hamming window.
REQUIREMENT
MATLAB Software 7R14
ALGORITHM
1. Get the passband & stopband ripples.
2. Get the passband & stopband edge frequencies.
3. Get the sampling frequency.
4. Calculate the order of the filter.
5. Find the filter coefficients.
6. Draw the magnitude & Phase response.
PROGRAM
%PROGRAM FOR THE DESIGN OF FIR LOW PASS, HIGH PASS, BAND PASS &
BAND STOP FILTERS USING HAMMING WINDOW
clc;
clear all;
close all;
rp = input ('enter the passband ripple');
rs = input ('enter the stopband ripple');
fp = input ('enter the passband frequency');
fs = input ('enter the stopband frequency');
f = input ('enter the sampling frequency');
wp=2*fp/f; ws=2*fs/f;
num= -20*log10(sqrt(rp*rs))-13;
54
dem=14.6*(fs-fp)/f;
n= ceil(num/dem);
n1= n+1;
if (rem(n,2)~=0)
n1=n;
n=n-1;
end
y=hamming(n1);
%BANDPASS FILTER
wn=[wp ws];
b= fir1(n,wn,y);
[h,o]=freqz(b,1,256);
55
m=20*log10(abs(h));
subplot(2,2,3);
plot(o/pi, m);
ylabel('Gain in dB-->');
xlabel('(c) Normalized Frequency');
%BANDSTOP FILTER
b= fir1(n,wn,'stop',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,4);
plot(o/pi, m);
ylabel('Gain in dB-->');
xlabel('(d) Normalized Frequency');
INPUT
enter the passband ripple .02
enter the stopband ripple .01
enter the passband frequency1200
enter the stopband frequency1700
enter the sampling frequency9000
56
FIGURES
50 50
0
Gain in dB-->
Gain in dB-->
0
-50
-50
-100
-150 -100
0 0.5 1 0 0.5 1
(a) Normalized Frequency (b) Normalized Frequency
0 5
0
Gain in dB-->
Gain in dB-->
-50
-5
-100
-10
-150 -15
0 0.5 1 0 0.5 1
(c) Normalized Frequency (d) Normalized Frequency
57