Beruflich Dokumente
Kultur Dokumente
INDEX
1. Introduction To Matlab 4
2. Generation Of Waveforms 6
3. AM & FM Generation 10
4. AM & FM Demodulation 13
5. Impulse Response 17
6. Linear Convolution 20
7. Circular Convolution 23
8. Circular Convolution (Using DFT) 27
9. Verification Of Sampling Theorem 30
10. Upsampling And Downsampling 35
11. FFT And IFT Of A Given Sequence 38
12. IIR Butterworth Lowpass Filter 41
13. IIR Butterworth Highpass Filter 44
14. IIR Butterworth Bandpass Filter 47
15. IIR Butterworth Bandstop Filter 49
16. IIR Chebyshev Type-1 Lowpass Filter 51
17. IIR Chebyshev Type-1 Highpass Filter 54
18. IIR Chebyshev Type-1 Bandpass Filter 57
19. IIR Chebyshev Type-1 Bandstop Filter 59
20. FIR Low Pass Filter 61
21. FIR High Pass Filter 66
22. Low Pass Filter Using Kaiser Window 68
23. High Pass Filter Using Kaiser Window 70
24. Band Pass Filter Using Kaiser Window 72
25.Properties of Dft 74
26.Applications of filters 82
27.Correlation 94
28.Finite wordlength effect 97
29.FFT and Spectral estimation 101
Experiment No: 1
Date:
INTRODUCTION TO MATLAB
Aim:-
To familiarize with MATLAB software, functions and signal processing toolbox
commands.
Theory:-
MATLAB is an interactive program for doing matrix calculations and has now
grown to a high level mathematical language that can solve integrals and differential
equations numerically and plot a wide variety of two and three dimensional graphs.
Definition of Variables
Variables are assigned numerical values by typing the expression directly. The
answer will not be displayed when a semicolon is put at the end of an expression.
+ Addition
- Subtraction
* Multiplication
/ Division
^ Power operator
' Transpose
A variable can be assigned using a formula that utilizes these operators and either
numbers or previously defined variables. To determine the value of a previously defined
quantity, type the quantity by itself. If your expression does not fit on one line, use an
ellipsis (three or more periods at the end of the line) and continue on the next line. There
are several predefined variables which can be used at any time, in the same manner as
user defined variables:
i - sqrt(-1)
j - sqrt(-1)
pi - 3.1416...
There are also a number of predefined functions that can be used when defining a
variable. Some common functions that are used in this text are:
Definition of Matrices
MATLAB is based on matrix and vector algebra; even scalars are treated as 1x1
matrices. Therefore, vector and matrix operations are as simple as common calculator
operations.
Vectors can be defined in two ways. The first method is used for arbitrary elements.
v = [1 3 5 7];
Creates a 1x4 vector with elements 1, 3, 5 and 7. Note that commas could have
been used in place of spaces to separate the elements. Additional elements can be added
to the vector,
v(5) = 8;
yields the vector v = [1 3 5 7 8]. Previously defined vectors can be used to define a new
vector.
The second method is used for creating vectors with equally spaced elements.
t = 0:0.1:10;
creates a 1x11 vector with the elements 0, .1, .2, .3,..., 10. Note that the middle number
defines the increment. If only two numbers are given, then the increment is set to a
default of 1.
k = 0:10;
creates a 1x11 vector with the elements 0, 1, 2, ..., 10.Matrices are defined by entering the
elements row by row.
M = [1 2 4; 3 6 8];
M = [1 2 4]
[3 6 8]
There are a number of special matrices that can be defined as follows.
Null matrix: M = [ ];
M (1, 2) = 5;
places the number 5 in the first row, second column. Operations and functions that were
defined for scalars in the previous section can also be used on vectors and matrices.
Functions are applied element by element. For example,
t = 0:10;
x = cos(2*t);
t = 0:10;
x = t.*cos(t);
General Information
MATLAB is case sensitive so "a" and "A" are two different names. Comment
statements are preceded by a "%". On-line help for MATLAB can be reached by typing
help for the full menu or typing help followed by a particular function name or M-file
name. For example, help cos gives help on the cosine function.
The number of digits displayed is not related to the accuracy. To change the
format of the display, type format short e for scientific notation with 5 decimal places,
format long e for scientific notation with 15 significant decimal places and format bank
for placing two significant digits to the right of the decimal.
The commands who and whos give the names of the variables that have been
defined in the workspace. The command length(x) returns the length of a vector x and
size(x) returns the dimension of the matrix x.
M-files are macros of MATLAB commands that are stored as ordinary text files with
the extension "m", that is filename.m. An M-file can be either a function with input and
output variables or a list of commands.
MATLAB M-files are most efficient when written in a way that utilizes matrix or
vector operations. Loops and if statements are available, but should be used sparingly
since they are computationally inefficient. An if statement can be used to define
conditional statements.
The allowable comparisons between expressions are >=, <=, <, >, ==, and ~=.
Suppose that you want to run an M-file with different values of a variable T. The
following command line within the M-file defines the value.
Whatever comment is between the quotation marks are displayed to the screen
when the M-file is running, and the user must enter an appropriate value.
Double click on icon for MATLAB 6.5. Within about 30 seconds MATLAB will
open, a screen like the picture below appears.
Command Window This is where you can type commands and usually the answers
(or error messages) appear here too. You will see the cursor flickering after the >>
prompt. This means that MATLAB is waiting for further instructions.
Workspace if you define new quantities (called variables) there names should be
listed here.
Command History This is past commands are remembered. If you want to re-run a
previous command or to edit it you can drag it from this window to the command
window to re-run it.
To begin to use MATLAB, click New: M-file from the File menu. This opens a
blank window as shown below.
The M-file is executed using the Run command under the Tools menu. The output
signal appears in Figure Window.
Result:-
Experiment No: 2
Date:
GENERATION OF WAVEFORMS
Aim:-
%Program
clc;
clear all;
close all;
%cosine wave
y=cos(2*pi*f*t);
subplot(323);
plot(t,y);
title('cosine wave');
grid on
%tangent wave
t=-3*pi:0.01:3*pi;
z=tan(2*pi*f*t);
subplot(325);
plot(t,z);
title('tan wave');
grid on
%sawtooth wave
b=sawtooth(2*pi*f*t);
subplot(3,2,4);
plot(t,b);
title('sawtooth wave');
%triangular wave
c=sawtooth(2*pi*f*t,0.3);
subplot(3,2,6);
plot(t,c);
title('trinagular wave');
% Discrete Waveforms
n=0:1:100;
k=0.01;
%sine wave
x=sin(2*pi*k*n);
subplot(5,1,1);
stem(n,x);
title('sine wave');
%cosine wave
y=cos(2*pi*k*n);
subplot(5,1,2);
stem(n,y);
title('cosine wave');
%square wave
z=square(2*pi*k*n);
subplot(5,1,3);
stem(n,z);
title('square wave');
%sawtooth wave
a=sawtooth(2*pi*k*n);
subplot(5,1,4);
stem(n,a);
title('sawtooth wave');
%triangular wave
b=sawtooth(2*pi*k*n,0.3);
subplot(5,1,5);
stem(n,b);
title('trinagular wave');
%Aperiodic Signals
%exponential signal
t=-5:.1:5;
x1=exp(-t);
subplot(3,2,1);
plot(t,x1);
title('exponential signal');
t=-10:.1:10;
x2=exp(-(t.^2)/2);
subplot(3,2,2);
plot(t,x2);
title('symmetric exponential signal');
%sinc signal
x3=sinc(t/2);
subplot(3,2,3);
plot(t,x3);
title('sinc signal');
axis([-10 10 -0.3 1]);
%signum signal
x4=sign(t);
subplot(3,2,4);
plot(t,x4);
title('signum signal');
%triangular pulse
x5=tripuls(t/10);
subplot(3,2,5);
plot(t,x5);
title('triangular pulse');
%rectangular pulse
x6=rectpuls(t/10);
subplot(3,2,6);
plot(t,x6);
title('rectangular pulse');
Observation
Result:-
Experiment No: 3
Date:
AM & FM GENERATION
Aim: -
Program:-
1. Generation of AM wave
x=0:0.00001:0.1;
vc=input('Enter carrier amplitude(V):');
fc=input('Enter carrier frequency(Hz):');
vm=input('Enter message amplitude(V):');
fm=input('Enter message frequency(Hz):');
M=vm/vc;
y=vc*sin(2*pi*fc*x);
z=vm*(sin(2*pi*fm*x));
m=(1+M*z).*y;
m1=y.*z
subplot(4,1,1);
plot(x,m);
ylabel('Amplitude');xlabel('Time');title('DSB FC AM');
subplot(4,1,2);
plot(x,m1);
ylabel('Amplitude');xlabel('Time');title('DSB SC AM');
subplot(4,1,3);
plot(x,z);
ylabel('Amplitude');xlabel('Time');title('Message');
subplot(4,1,4);
plot(x,y);
ylabel('Amplitude');xlabel('Time');title('Carrier');
2. Generation of FM wave
x=0:0.00001:0.05;
vc=input('Enter carrier amplitude(V):');
fc=input('Enter carrier frequency(Hz):');
vm=input('Enter message amplitude(V):');
fm=input('Enter message frequency(Hz):');
M=input('Enter modulation index:');
y=vc*sin(2*pi*fc*x);
z=vm*(sin(2*pi*fm*x));
m=vc*sin(2*pi*fc*x+(M.*sin(2*pi*fm*x)));
Observation
Inputs:-
Inputs:-
Enter carrier amplitude(V):5
Enter carrier frequency(Hz):500
Enter message amplitude(V):2
Enter message frequency(Hz):100
Enter modulation index:2
Result:-
Experiment No: 4
Date:
AM & FM DEMODULATION
Aim:-
To write a MATLAB program to implement AM & FM demodulation.
Program:-
AM demodulation:
vm=input('Vm=');
vc=input('Vc=');
fm=input('fm=');
fc=input('fc=');
mi=input('mod=');
t=(0:fm/900000:.05);
n=16;
Wn=2*fc/10000;
subplot(4,1,1);
Vm=vm*sin(2*pi*fm*t);
plot(t,Vm);
ylabel('message signal');
Vc=vc*sin(2*pi*fc*t);
subplot(4,1,2);
plot(t,Vc);
ylabel('carrier signal');
Y=Vc.*(1+mi*Vm);
subplot(4,1,3);
plot(t,Y);
ylabel('AM signal');
message=Y.*Vc;
[b,a]=butter(n,Wn);
message=filtfilt(b,a,message);
subplot(4,1,4);
plot(t,message);
ylabel('demodulated signal');
FM demodulation:
fm=input('fm=');
fc=input('fc=');
mi=input('Mi=');
t=(0:fm/750000:.05);
n=15;
Wn=2*fc/10000;
Vm=sin(2*pi*fm*t);
Observation
AM Demodulation:
Inputs:
Vm=1
Vc=2
fm=100
fc=1000
mod=.5
FM Demodulation:
Inputs:
fm=100
fc=1000
Mi=5
Result:-
Experiment No: 5
Date:
IMPULSE RESPONSE
Aim:-
Write a MATLAB program to find the Impulse Response of two sequences.
Algorithm:
Step 1: Start
Step 2: Input the output sequences y(n)
Step 3: Input the input sequence x(n)
Step 4: Deconvolve the two sequences to obtain impulse response using deconv
command
Step 5: Plot the input,output sequence and impulse response using stem command
Step 6: Stop
Program:
subplot(2,2,2);
subplot(2,1,2);
stem(h); % plots the output sequence as stems
xlabel({'TIME'; strcat('h(n) = [', num2str(h), ']')}); % label appears below xaxis
ylabel('h(n)'); % label appears beside yaxis
title('IMPULSE RESPONSE');
Observation
Ans =
1 0 0 0
Figure:
Result:-
Obtained the impulse response from the convoluted output sequence and verified.
Experiment No: 6
Date:
LINEAR CONVOLUTION
Aim:-
Write a MATLAB program to find the linear convolution of two sequences.
Theory:
In this equation, x1(k), x2(n-k) and y(n) represent the input to and output from the
system at timen. Here we could see that one of the input is shifted in time by a value
every time it is multipliedwith the other input signal. Linear Convolution is quite often
used as a method of implementingfilters of various types.
Algorithm:-
Step 1: Start
Step 2: Input the first sequences x(n)
Step 3: Input the second sequence h(n)
Step 4: Convolve the two sequence x(n) and h(n) to obtain output y(n)
Step 5: Plot h(n) using stem command
Step 6: Plot x(n) using stem command
Step 7: Plot y(n) using stem command
Step 8: Stop
Program:-
subplot(2,2,2);
stem(h); % plots the data sequence as stems
xlabel({'TIME'; strcat('h(n) = [', num2str(h), ']')}); % label appears below x axis
ylabel('h(n)'); % label appears beside y axis
title('SECOND INPUT SEQUENCE');
subplot(2,1,2);
stem(y); % plots the output sequence as stems
xlabel({'TIME'; strcat('y(n) = [', num2str(y), ']')}); % label appears below x axis
ylabel('y(n)'); % label appears beside y axis
title('LINEAR CONVOLUTION');
Observation:-
Enter the first sequence: [1 2 3 4]
Enter the second sequence: [1 0 0 0]
Ans =
1 2 3 4 0 0 0
Figure:
Result:-
Obtained the linear convolution of the two signals x and h and verified the
output.
Experiment No: 7
Date:
CIRCULAR CONVOLUTION
Aim:-
Write a MATLAB program to find the Circular Convolution of two sequences.
Theory:-
Circular convolution is another way of finding the convolution sum of two input
signals. Itresembles the linear convolution, except that the sample values of one of the
input signals isfolded and right shifted before the convolution sum is found. Also note
that circular convolutioncould also be found by taking the DFT of the two input signals
and finding the product of the twofrequency domain signals. The Inverse DFT of the
product would give the output of the signal inthe time domain which is the circular
convolution output.
The circular convolution is also an N-point sequence. If the length of any one of
the sequence is not N, sufficient number of zeros should be padded to it to make length
equal to N.
Algorithm:-
Step1: Start
Step 2: Input the first sequences g
Step 3: Input the second sequence h
Step 4: Calculate the length of each sequence
Let it be N1 and N2
Step 5: If N1> N2, put N=N1 and N3=N-N2. Pad N3 sequence to second sequence.
Else Put N=N2 and N3=N-N1. Pad N3 sequence to first sequence
Step 6: Increment M from 1 and put y(m)=0, with M as outerloop variable
Step 7: Increment the inner loop variable i from 1 and find j=m-j+1 and if j<=0,
Perform j=j+n
Also find y(m)=y(m)+g(1)*h(j)
Step 8: Do Step 7, until i=N
Step9 : Do Step 6, until m=N
Program:-
if N1<=N2
N=N2;
N3=N-N1;
g=[g,zeros(1,N3)];
else
N=N1;
N3=N-N2;
h=[h,zeros(1,N3)];
end
for M=1:N
y(M)=0;
for i=1:N
j=M-i+1;
if j<=0
j=N+j;
end
y(M)= y(M)+g(i)*h(j);
end
end
Result:-
Obtained the circular convolution of two sequences and verified
Experiment No: 8
Date:
CIRCULAR CONVOLUTION (USING DFT)
Aim:-
Algorithm:-
Step 1: Start
Step 2: Input the first sequence g
Step 3: Input the second sequence h
Step 4: Find the length of two sequence using the command length(), and find out
which is maximum
Step 5: Find the FFT of both sequences
Step 6: Multiply the FFT of sequences and find inverse FFT of the product.
Step 5: Plot the input and output sequence using stem command
Step 6: Stop
Program:-
Observation:-
18 13 16 19
Figure:
Result:-
Obtained the circular convolution using DFT and output verified
Experiment No: 9
Date:
Theory:-
Algorithm:-
Step 1: Start
Step 2: Form a cosine signal y
Step 3: Input the sampling frequency fs
Step 4: Find sampling period ts from fs
Step 5: Form the sampling instants from 0 to 1 using ts
Step 6: Find the sampled values of y at the sampling instants; store it in Ys
Step 7: Form the recovered signal from Ys
Step 8: Plot the continuous signal, sampled values and recovered signal
Step 9: Stop
PROGRAM:-
Observation:-
Figure:
Figure:
Figure:
Result:-
Experiment No: 10
Date:
UPSAMPLING AND DOWNSAMPLING
Aim:-
To write a MATLAB program to implement upsampling and downsampling of a
sequence.
Program:-
%TIME DOMAIN
%DOWNSAMPLING
Xd=zeros(1,l);
for i=0:(l-1)/m
Xd(i+1)=x(m*i+1);
end
subplot(313);
stem(Xd);
title('Downsampling');
ylabel('Xd(n)');
xlabel('------> n');
%FREQUENCY DOMAIN
clear all;
Observation:-
Time domain:
Inputs:-
Enter the sequence [1 2 3 4 5 6 7]
Enter the scale factor 3
Observation:-
Frequency domain:
Inputs:-
Enter the sequence[1 2 3 4 5 6]
Enter the scaling factor 3
Result: -
Written and executed a MATLAB program to implement upsampling and
downsampling of a sequence and verified the output.
Experiment No: 11
Date:
FFT AND IFT OF A GIVEN SEQUENCE
Aim:-
Algorithm:-
Step 1: Start
Step 2: Input the sequence x
Step 3: Input the length of sequence
Step 4: Find the FFT
Step 5: Find the FFT of both sequences
Step 6: Multiply the FFT of sequences and find inverse FFT of the product.
Step 5: Plot the input and output sequence using stem command
Step 6: Stop
Program:-
Observation:-
Enter the input sequence: [4 5 6 7]
y=
yinv =
Figure:
Result:-
Experiment No: 12
Date:
Algorithm:-
Step 1: Start
Step 2: Enter the passband ripple rp, stopband ripple rs, passband frequency in Hz cop,
Sampling
frequency in Hz fs, Stopband frequency cos
Step 3: Compute the frequency in radians
Step 4: Find cutoff frequency and order of filter using command word buttord
Step 5: Find the coefficients of filter using command word butter
Step 6: Find the frequency response of filter using the coefficients with command word
freqs.
Let it be h and omega.
Step 7: Find the magnitude and phase of filter output h
Step 8: Plot the magnitude and phase response of filter
Step 9: Stop
Program:-
clc;
rp=input('Enter the passband ripple:');
rs=input('Enter the stopband ripple:');
wp=input('Enter the passband frequency:');
ws=input('Enter the stopband frequency:');
fs=input('Enter the sampling frequency:');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=buttord(w1,w2,rp,rs);
[b,a]=butter(n,wn);
w=[0:.01:pi];
[h,omega]=freqz(b,a,w);
m=20*log10(abs(h));
subplot(2,1,2);
plot(omega/pi,an);
xlabel('Normalised Frequency');
ylabel('Phase in Radians');
title('Phase response');
Observation:-
Result:-
Experiment No: 13
Date:
Algorithm:-
Step 1: Start
Step 2: Enter the passband ripple rp, stopband ripple rs, passband frequency in Hz cop,
Sampling
frequency in Hz fs, Stopband frequency cos
Step 3: Compute the frequency in radians
Step 4: Find cutoff frequency and order of filter using command word buttord
Step 5: Find the coefficients of filter using command word butter with one of its
parameter
being the order n, cutoff frequency wn, and to designate for high pass as high
Step 6: Find the frequency response of filter using the coefficients with command word
freqs.
Let it be h and omega.
Step 7: Find the magnitude and phase of filter output h
Step 8: Plot the magnitude and phase response of filter
Step 9: Stop
Program:-
clc;
rp=input('Enter the passband ripple:');
rs=input('Enter the stopband ripple:');
wp=input('Enter the passband frequency:');
ws=input('Enter the stopband frequency:');
fs=input('Enter the sampling frequency:');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=buttord(w1,w2,rp,rs);
[b,a]=butter(n,wn,high);
w=[0:.01:pi];
subplot(2,1,1);
plot(omega/pi,m);
xlabel('Normalised Frequency');
ylabel('Gain in dB');
title('Amplitude Response');
Observation:-
Figure:
Result:-
Obtained and verified the amplitude and phase response of IIR butterworth
high pass filter .
Experiment No: 14
Date:
Program:-
clc;
rp=input('Enter the passband ripple:');
rs=input('Enter the stopband ripple:');
wp=input('Enter the passband frequency:');
ws=input('Enter the stopband frequency:');
fs=input('Enter the sampling frequency:');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=buttord(w1,w2,rp,rs);
[b,a]=butter(n,wn,'bandpass');
w=[0:.01:pi];
[h,omega]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
% Plot amplitude response
subplot(2,1,1);
plot(omega/pi,m);
xlabel('Normalised Frequency');
ylabel('Gain in dB');
title('Amplitude Response');
Figure:
Result:-
Obtained and verified the amplitude and phase response of IIR butterworth band
pass filter .
Experiment No: 15
Date:
Aim:-
Write a MATLAB program to design IIR Butterworth bandstrop filter
Algorithm:-
Step 1: Start
Step 2: Enter the passband ripple rp, stopband ripple rs, passband frequency wp,
Sampling
frequency in ws, Sampling frequency fs
Program:-
clc;
rp=input('Enter the passband ripple:');
rs=input('Enter the stopband ripple:');
wp=input('Enter the passband frequency:');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=buttord(w1,w2,rp,rs);
Observation:-
Enter the passband ripple: 0.5
Enter the stopband ripple: 40
Enter the passband frequency: [3000 7000]
Enter the stopband frequency: [4000 6000]
Enter the sampling frequency: 20000
Result:-
Obtained and verified the amplitude and phase response of IIR butterworth
bandstop filter.
Experiment No: 16
Date:
Algorithm:-
Step 1: Start
Step 2: Enter the passband ripple rp, stopband ripple rs, passband frequency in Hz wp,
Sampling
frequency in Hz fs, Stopband frequency ws
Step 3: Compute the frequency in radians
Step 4: Find cutoff frequency and order of filter using command word cheb1ord
Step 5: Find the coefficients of filter using command word cheby1
Step 6: Find the frequency response of filter using the coefficients with command word
freqs.
Let it be h and omega.
Step 7: Find the magnitude and phase of filter output h
Step 8: Plot the magnitude and phase response of filter
Program:-
clc;
rp=input('Enter the passband ripple:');
rs=input('Enter the stopband ripple:');
wp=input('Enter the passband frequency:');
ws=input('Enter the stopband frequency:');
fs=input('Enter the sampling frequency:');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=cheb1ord(w1,w2,rp,rs);
[b,a]=cheby1(n,rp,wn);
w=[0:.01:pi];
[h,omega]=freqz(b,a,w);
m=20*log10(abs(h));
OBSERVATION:-
Enter the passband ripple: 0.2
Enter the stopband ripple: 45
Enter the passband frequency: 1500
Enter the stopband frequency: 1700
Enter the sampling frequency: 10000
Result:-
Obtained the result and verified the amplitude and phase response of IIR
chebyshev type-1 low pass filter .
Experiment No: 17
Date:
Aim:-
Write a MATLAB program to design IIR Chebyshev type-1 highpass filter
Algorithm:-
Step 1: Start
Step 2: Enter the passband ripple rp, stopband ripple rs, passband frequency in Hz wp,
Sampling
frequency in Hz fs, Stopband frequency ws
Step 3: Compute the frequency in radians
Step 4: Find cutoff frequency and order of filter using command word cheb1ord
Step 5: Find the coefficients of filter using command word cheby1 with one of its
parameter
being the order n, cutoff frequency wn, and to designate for high pass as
high along
with rp the decibel of peak to peak ripple in the passband
Step 6: Find the frequency response of filter using the coefficients with command word
freqs.
Let it be h and omega.
Step 7: Find the magnitude and phase of filter output h
Step 8: Plot the magnitude and phase response of filter
Step 9: Stop
Program:-
clc;
rp=input('Enter the passband ripple:');
rs=input('Enter the stopband ripple:');
wp=input('Enter the passband frequency:');
ws=input('Enter the stopband frequency:');
fs=input('Enter the sampling frequency:');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=cheb1ord(w1,w2,rp,rs);
subplot(2,1,2);
plot(omega/pi,an);
xlabel('Normalised Frequency');
ylabel('Phase in Radians');
title('Phase response');
Observation:-
Enter the passband ripple: 0.5
Enter the stopband ripple: 40
Enter the passband frequency: 4500
Enter the stopband frequency: 4400
Enter the sampling frequency: 10000
Figure:
Result:-
Obtained and verified the amplitude and phase response of IIR chebyshev type-1
high pass filter.
Experiment No: 18
Date:
Program:-
clc;
rp=input('Enter the passband ripple:');
rs=input('Enter the stopband ripple:');
wp=input('Enter the passband frequency:');
ws=input('Enter the stopband frequency:');
fs=input('Enter the sampling frequency:');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=cheb1ord(w1,w2,rp,rs);
[b,a]=cheby1(n,rp,wn,'bandpass');
w=[0:.01:pi];
[h,omega]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
% Plot amplitude response
subplot(2,1,1);
plot(omega/pi,m);
xlabel('Normalised Frequency');
ylabel('Gain in dB');
title('Amplitude Response');
%Plot phase response
subplot(2,1,2);
plot(omega/pi,an);
xlabel('Normalised Frequency');
Observation:-
Result:-
Obtained the result and verified the amplitude and phase response of IIR
chebyshev type-1band pass filter.
Experiment No: 19
Date:
Aim:-
Write a MATLAB program to design IIR Chebyshev type-1 bandstop filter
Algorithm:-
Step 1: Start
Step 2: Enter the passband ripple rp, stopband ripple rs, passband frequency in wp,
Stopband frequency ws , Sampling frequency fs.
Step 3: Compute the frequency in radians/sec
Step 4: Find cut off frequency and order of filter using command word cheb1ord
Step 5: Find the coefficients of filter using command word cheby1 with one of its
parameter being the order n, wn, rp and designate bandstop a stop.
Step 6: Find the frequency response of filter using the coefficients with command word
freqs. Let it be h and omega.
Step 7: Find the magnitude and phase of filter output h
Step 8: Plot the magnitude and phase response of filter
Step 9: Stop
Program:-
clc;
rp=input('Enter the passband ripple:');
rs=input('Enter the stopband ripple:');
wp=input('Enter the passband frequency:');
ws=input('Enter the stopband frequency:');
fs=input('Enter the sampling frequency:');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=cheb1ord(w1,w2,rp,rs);
[b,a]=cheby1(n,rp,wn,'bandstop');
w=[0: 0.01:pi];
Observation:-
Result:-
Obtained the and verified the amplitude and phase response of IIR
chebyshev type-1band stop filter .
Experiment No: 20
Date:
FIR LOW PASS FILTER
Aim:-
Write a MATLAB program to generate FIR low pass filter response using
(a) Rectangular Window
(b) Hamming Window
(c) Blackman Window
(d) Barlett Window
Program:-
clc;
fc=0.5;
fs=10000;
N=17;
b=fir1(N-1,fc,boxcar(N));
[H,f]=freqz(b,1,512,fs);
m=20*log10(abs(H));
plot(f,m);
grid on;
xlabel('frequency(Hz)');
ylabel('Magnitude(dB)');
Title('HAMMING WINDOW');
2.% HAMMING WINDOW OF FIR LPF
clc;
fc=0.5;
fs=10000;
N=17;
ham=fir1(N-1,fc,hamming(N));
plot(f,m);
grid on;
xlabel('frequency(Hz)');
ylabel('Magnitude(dB)');
Title('HAMMING WINDOW');
clc;
fc=0.5;
fs=10000;
N=28;
bart=fir1(N-1,fc,bartlett(N));
plot(f,m);
grid on;
xlabel('frequency(Hz)');
ylabel('Magnitude(dB)');
Title('BARTLETT WINDOW');
Observation:-
Figures:
1. Rectangular Window
2. Hamming Window
3. Blackman Window
4.Bbarlett Window
Result:-
Obtained and verified the generation of FIR low pass filter using rectangular
window,hamming window,blackmann window and bartlett
Experiment No: 21
Date:
FIR HIGH PASS FILTER
Aim:-
Write a MATLAB program to generate FIR high pass filter response using
(a) Rectangular Window
(b) Hamming Window
(c) Blackman Window
(d) Barlett Window
Program:-
RESULT:-
Obtained and verified the generation of FIR high pass filter using rectangular
window,hamming window,blackmann window and Bartlett windows.
Experiment No: 22
Date:
Aim:-
To write a MATLAB program to plot frequency response of a Low Pass filter
using Kaiser Window.
Program:-
clear all;
clc;
rp=input('Enter the pass band ripple(in dB):');
rs=input('Enter the stop band ripple(in dB):');
Wp=input('Enter the pass band edge:');
Ws=input('Enter the stop band edge:');
fs=input('Enter the sampling frequency:');
wp=2*Wp/fs;
ws=2*Ws/fs;
tr_wdth=ws-wp
m=ceil(((rs-7.95)*2*pi)/(14.36*tr_wdth) +1)+1;
if rs>=50
beta=0.1102*(rs-8.7);
elseif rs>21
beta=0.5842*((rs-21^0.4)+0.07886*(rs-21));
elseif rs<=21
beta=0;
end
y=kaiser(m,beta);
n=m-1;
b=fir1(n,wp,y);
w=0:0.01:pi;
[h,w]=freqz(b,1,512);
db=20*log10(abs(h));
an=angle(h);
subplot(211);
plot(w/pi,db);
xlabel('Normalised frequency');
ylabel('Gain(dB)');
subplot(212);
plot(w/pi,an);
ylabel('Phase(Rad)');
xlabel('Normalised frequency');
Input:-
Observation:-
Result:-
Experiment No: 23
Date:
Aim:-
Program:-
clear all;
clc;
rp=input('Enter the pass band ripple(in dB):');
rs=input('Enter the stop band ripple(in dB):');
Wp=input('Enter the pass band edge:');
Ws=input('Enter the stop band edge:');
fs=input('Enter the sampling frequency:');
wp=2*Wp/fs;
ws=2*Ws/fs;
tr_wdth=wp-ws
m=ceil(((rs-7.95)*2*pi)/(14.36*tr_wdth) +1)+1;
if rs>=50
beta=0.1102*(rs-8.7);
elseif rs>21
beta=0.5842*((rs-21^0.4)+0.07886*(rs-21));
elseif rs<=21
beta=0;
end
y=kaiser(m,beta);
n=m-1;
b=fir1(n,wp,high,y);
w=0:0.01:pi;
[h,w]=freqz(b,1,512);
db=20*log10(abs(h));
an=angle(h);
subplot(211);
plot(w/pi,db);
xlabel('Normalised frequency');
ylabel('Gain(dB)');
subplot(212);
plot(w/pi,an);
ylabel('Phase(Rad)');
xlabel('Normalised frequency');
Input:-
Enter the pass band ripple(in dB):0.01
Enter the stop band ripple(in dB):25
Enter the pass band edge:1500
Enter the stop band edge:1000
Enter the sampling frequency:10000
Observation:-
Result:-
Experiment No: 24
Date:
Program:-
clear all;
clc;
rp=input('Enter the pass band ripple(in dB):');
rs=input('Enter the stop band ripple(in dB):');
Wp=input('Enter the pass band edge:');
Ws=input('Enter the stop band edge:');
fs=input('Enter the sampling frequency:');
wp=2*Wp/fs;
ws=2*Ws/fs;
tr_wdth=min((wp(1)-ws(1)),(ws(2)-wp(2)))
m=ceil(((rs-7.95)*2*pi)/(14.36*tr_wdth) +1)+1;
if rs>=50
beta=0.1102*(rs-8.7);
elseif rs>21
beta=0.5842*((rs-21^0.4)+0.07886*(rs-21));
elseif rs<=21
beta=0;
end
y=kaiser(m,beta);
n=m-1;
b=fir1(n,wp,bandpass,y);
w=0:0.01:pi;
[h,w]=freqz(b,1,512);
db=20*log10(abs(h));
an=angle(h);
subplot(211);
plot(w/pi,db);
xlabel('Normalised frequency');
ylabel('Gain(dB)');
subplot(212);
plot(w/pi,an);
ylabel('Phase(Rad)');
xlabel('Normalised frequency');
Observation:-
Input:-
Enter the pass band ripple(in dB):0.01
Enter the stop band ripple(in dB):25
Enter the pass band edge:[1500 2000]
Enter the stop band edge:[1000 2500]
Enter the sampling frequency:20000
Result:-
Written and executed a MATLAB program to plot frequency response of a Band
Pass filter using Kaiser. Window and verified the output.
Experiment No: 25
Date:
PROPERTIES OF DFT
Aim:-
To prove the following properties of DFT
i)linearity ii)Duality iii)Time shifting iv)Time reversal v)Frequency shifting
vi)Symmetry property vii)circular convolution
Program:-
clc;
clear all;
close all;
x1=input('enter first sequnce:');
x2=input('enter second sequnce:');
n1=length(x1);
n2=length(x2);
p=max(n1,n2);
x1=[x1 zeros(1,p-n1)];
x2=[x2 zeros(1,p-n2)];
x1k=fft (x1,n1);
x2k=fft(x2,n2);
%linearity property:
a=input('enter the value for a:');
b=input('enter the value for b:');
c=fft(a*x1+b*x2);
d=a*x1k+b*x2k;
disp('linearity property');
disp('dft(a*x1+b*x2):');
disp(c);
disp('a*x1k+b*x2k):');
disp(d);
%duality property
e=fft (x1k);
f=n1*circshift(fliplr(x1),[0,1]);
disp('duality property');
disp('dft of x1k:');
disp(e);
disp('n*x1[(-k)n]:');
disp(f);
%circular convolution:
p=max(n1,n2);
x3=[x1 zeros(1,p-n1)];
x4=[x2 zeros(1,p-n2)];
for i=0:p-1
q(i+1)=0;
for j=0:p-1
k=mod(i-j,p);
q(i+1)=q(i+1)+(x3(j+1)*x4(k+1));
end;
end;
r=fft(q);
s=x1k.*x2k;
disp('dft [x1(n) conv x2(n)=x1(k)*x2(k):');
disp('dft[x1(n)conv x2(n):');
disp(r);
%dft(x1(n)*x2(n))=1/n(x1(k)convx2(k);
f=fft(x1.*x2);
x3=[x1k zeros(1,p-n1)];
x4=[x2k zeros(1,p-n2)];
for i=0:p-1
q(i+1)=0;
for j=0:p-1
k=mod(i-j,p);
q(i+1)=q(i+1)+(x3(j+1)*x4(k+1));
end;
end;
disp('dft [x1(n)* x2(n)=1/n(x1(k)conv x2(k):');
g=q/p;
disp('dft[x1(n)* x2(n):');
disp(f);
disp('1/n(x1(k) conv x2(k):');
disp(g);
%symmetry property
a=real (x1k);
b=real (circshift(fliplr(x1k),[0,1]));
disp('symmetry property:real x(k)=real(x(-k))');
disp('real x(k)');
disp(a);
disp('real (x(-k))');
disp(b);
%|(x(k))| = |(x(-k))|
g3 =abs (x1k);
h3=abs(circshift (fliplr (x1k),[0,1]));
disp('abs x(k) = abs x(-k)');
disp('abs x(k)');
disp(g3);
disp('abs (x(-k))');
%<x(k) = <x(-k)n
m1=angle (x1k);
n1=-angle (circshift (fliplr(x1k),[0,1]));
disp('angle x(k) = angle x(-k)n');
disp('angle x(k)');
disp(m1);
disp('angle (x(-k)n');
disp(n1);
Observations
a*x1k+b*x2k):
8.000000000000000 0.500000000000000 + 0.866025403784439i
0.500000000000000 - 0.866025403784439i
duality property
dft of x1k:
3.000000000000000 3.000000000000000 0.000000000000000
n*x1[(-k)n]:
3 3 0
x(-k)n:
2.000000000000000 0.500000000000000 - 0.866025403784439i
0.500000000000000 + 0.866025403784439i
wn^km x[k]
2.000000000000000 0.500000000000000 + 0.866025403784439i
0.500000000000000 - 0.866025403784438i
x(k-l):
0.500000000000000 - 0.866025403784439i 2.000000000000000
0.500000000000000 + 0.866025403784439i
x1(k)*x2(k):
6 0 0
conj x(-k):
2.000000000000000 0.500000000000000 + 0.866025403784439i
0.500000000000000 - 0.866025403784439i
dft(jim(x(n))=oddpart of x(k)
dft(jim(x(n)):
0 0 0
re x(k):
2.000000000000000 0.500000000000000 0.500000000000000
jim x(k):
0 0 + 0.866025403784439i 0-
0.866025403784439i
real (x(-k))
2.000000000000000 0.500000000000000 0.500000000000000
imag (x(k))=-imag(x(-k))
imag (x(k))
0 0.866025403784439 -0.866025403784439
-imag (x(-k))
0 0.866025403784439 -0.866025403784439
abs (x(-k))
angle (x(-k)n
0 1.047197551196598 -1.047197551196598
>>
Experiment No: 26
Date:
APPLICATIONS OF FILTERS
Aim:-
To write a MATLAB program to verify the following applications of filters
i)Noise removal of LPF
ii)AM demodulation using LPF
iii)LP,HP,BP filtering and sum of three sine waves
iv)High Pass filtering a square wave
v)Low Pass filtering a square wave
vi)Carrier recovery using band pass filter
Program:-
clc;
clear all;
close all;
figure(1);
subplot(211);
plot(t,x);
subplot(212);
plot(t,y);
figure(2);
subplot(211);
plot(w,abs(h));
title('magnitude response');
subplot(212);
plot(w,angle(h));
figure(3);
subplot(221);
plot(t,m);
subplot(222);
plot(t,c);
subplot(223);
plot(t,am1);
subplot(224);
plot(t,y);
figure(4);
subplot(211);
plot(w,abs(h));
title('magnitude response');
subplot(212);
plot(w,angle(h));
title('phase response');
figure(5);
subplot(221);
plot(t,m);
subplot(222);
plot(t,c);
subplot(223);
plot(t,am1);
subplot(224);
plot(t,y);
figure(6);
subplot(211);
plot(w,abs(h));
title('magnitude response');
subplot(212);
plot(w,angle(h));
title('phase response');
figure(7);
subplot(211);
plot(t,x);
figure(8);
subplot(211);
plot(w,abs(h));
title('magnitude response');
subplot(212);
plot(w,angle(h));
title('phase response');
[n1 wc1]=buttord(wp1,ws1,ap,as);
[b1 a1]=butter(n1,wc1);
[h1 w1]=freqz(b1,a1,512,fs);
[n2 wc2]=buttord(wp2,ws2,ap,as);
[b2 a2]=butter(n2,wc2);
[h2 w2]=freqz(b2,a2,512,fs);
[n3 wc3]=buttord(wp3,ws3,ap,as);
[b3 a3]=butter(n3,wc3);
[h3 w3]=freqz(b3,a3,512,fs);
y1=filter(b1,a1,x);
y2=filter(b2,a2,x);
y3=filter(b3,a3,x);
figure(9);
subplot(221);
plot(t,x1);
subplot(222);
figure(10);
subplot(231);
plot(t,x1);
subplot(232);
plot(t,x2);
subplot(233);
plot(t,x3);
subplot(234);
plot(t,y1);
subplot(235);
plot(t,y2);
subplot(236);
plot(t,y3);
figure(11);
subplot(231);
plot(w1,abs(h1));
title('magnitude response');
subplot(232);
plot(w2,angle(h2));
title('magnitude response');
subplot(233);
plot(w3,abs(h3));
title('magnitude response');
subplot(234);
plot(w1,angle(h1));
title('phase response');
subplot(235);
plot(w2,angle(h2));
title('phase response');
subplot(236);
plot(w3,angle(h3));
title('phase response');
fs=1000;
t=-1:1/fs:1;
fm=5;
figure(12);
subplot(221);
plot(t,x);
subplot(222);
plot(t,n0);
subplot(223);
plot(t,x-n0);
subplot(224);
plot(t,y);
figure(13);
subplot(211);
plot(w,abs(h));
title('magnitude response');
subplot(212);
plot(w,angle(h));
title('phase response');
Result
Wrote a MATLAB program to verify the applications of filters
Experiment No: 27
Date:
CORRELATION
Aim:-
To write a MATLAB program to find auto correlation and cross correlation of
random and deterministic signals.
Theory:-
Program:-
clc;
clear all;
close all;
figure(1);
subplot(411);
stem(x);
title('first sequence');
subplot(412);
stem(y);
title('second sequence');
subplot(413);
stem(z);
title('cross correlated sequence');
subplot(414);
n=50;
x=rand (1,n);
y=rand (1,n);
z=xcorr(x,y);
p=xcorr(x);
figure(2);
subplot(411);
plot(x);
title('first sequence');
subplot(412);
plot(y);
title('second sequence');
subplot(413);
plot(z);
title('cross correlated sequence');
subplot(414);
plot(p);
title('auto correlated sequence');
Observations:-
Enter first sequence [1 2 3]
Enter second sequence [4 5 6]
Cross correlation
6 17 32 23 12
Auto correlation
3.0000 8.0000 14.0000 8.0000 3.0000
Result
Experiment No: 28
Date:
Theory:-
Program:-
%finite wordlength effect
clc;
clear all;
format long;
n=1:30;
b=1;
a1=[1 2/3];
a2=[1 .7];
a3=[1 .67];
a4=[1 .667];
g1=tf(b,a1,-1);
g2=tf(b,a2,-1);
g3=tf(b,a3,-1);
g4=tf(b,a4,-1);
h1=step(g1,30);
h2=step(g2,30);
figure(1);
stairs(n,h);
title('step response with different feedback factors');
legend(ax);
figure(2);
subplot(221);
stairs(n,h1);
title('step response with different feedback factor=ax(1,:)');
subplot(222);
stairs(n,h2);
title('step response with different feedback factor=ax(2,:)');
subplot(223);
stairs(n,h3);
title('step response with different feedback factor=ax(3,:)');
subplot(224);
stairs(n,h4);
title('step response with different feedback factor=ax(4,:)');
disp('');
disp('');
disp('the o/p with different feed back factor are');
disp('');
disp('');
disp('transpose(str2num(ax))');
disp('');
disp(h);
Observation:-
the o/p with different feed back factor are
transpose(str2num(ax))
0 0 0 0
1.000000000000000 1.000000000000000 1.000000000000000 1.000000000000000
0.333333333333333 0.300000000000000 0.330000000000000 0.333000000000000
0.777777777777778 0.790000000000000 0.778900000000000 0.777889000000000
0.481481481481482 0.447000000000000 0.478137000000000 0.481148037000000
0.679012345679012 0.687100000000000 0.679648210000000 0.679074259321000
0.547325102880659 0.519030000000000 0.544635699300000 0.547057469032893
0.635116598079561 0.636679000000000 0.635094081469000 0.635112668155060
0.576588934613626 0.554324700000000 0.574486965415770 0.576379850340575
0.615607376924249 0.611972710000000 0.615093733171434 0.615554639822837
>>
Result
Aim:-
To estimate the spectrum for a sinc and rectangular pulse of different signal frequencies
on time and frequency domain.
Program:-
clc;
clear all;
close all;
n=input('length of the sequnce');
N=input('no. of fft coefficient');
fs=input('sampling frequncy');
fm=input('msg signal frquncy');
t=-n:1/fs:n;
f=-fs/2:(fs/N):(fs/2.-fs/N);
wave1=sin(2*pi*fm*t);
wave2=rectpuls(fm*t);
wf1=fftshift(fft(wave1,N));
wf2=fftshift(fft(wave2,N));
figure(1);
subplot(221);
plot(t,wave1);
title('spectrum of sinc');
subplot(222);
plot(f,abs(wf1));
title('spectrum of sine pulse');
subplot(223);
plot(t,wave2);
title('rect pulse');
subplot(224);
plot(f,abs(wf2));
title('spectrum of rect pulse');
Observation:-
length of the sequnce 4
no. of fft coefficient 5
sampling frequncy 10
msg signal frquncy 0.1
Result