Sie sind auf Seite 1von 109

DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING

COLLEGE OF ENGINEERING TRIKARIPUR


CHEEMENI, KASARAGOD

SIGNAL PROCESSING LAB


MANUAL
2
College of Engineering Trikaripur

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

Department Of ECE signal processing Lab Manual


3
College of Engineering Trikaripur

26.Applications of filters 82
27.Correlation 94
28.Finite wordlength effect 97
29.FFT and Spectral estimation 101

Department Of ECE signal processing Lab Manual


4
College of Engineering Trikaripur

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.

MATLAB utilizes the following arithmetic operators:

+ 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:

Department Of ECE signal processing Lab Manual


5
College of Engineering Trikaripur
abs - magnitude of a number (absolute value for real numbers)
angle - angle of a complex number, in radians
cos - cosine function, assumes argument is in radians
sin - sine function, assumes argument is in radians
exp - exponential function(can be used on complex numbers).

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];

creates the matrix

M = [1 2 4]
[3 6 8]
There are a number of special matrices that can be defined as follows.

Null matrix: M = [ ];

Department Of ECE signal processing Lab Manual


6
College of Engineering Trikaripur
nxm matrix of zeros: M = zeros(n,m);
nxm matrix of ones: M = ones(n,m);
nxn identity matrix: M = eye(n);

A particular element of a matrix can be assigned as,

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);

creates a vector x with elements equal to cos(2t) for t = 0, 1, 2, ..., 10.

Operations that need to be performed element-by-element can be accomplished by


preceding the operation by a ".". For example, to obtain a vector x that contains the
elements of x(t) = tcos(t) at specific points in time, you cannot simply multiply the vector
t with the vector cos(t). Instead you multiply their elements together:

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.

Department Of ECE signal processing Lab Manual


7
College of Engineering Trikaripur
M-files

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.

The following describes the use of M-files on a PC version of MATLAB.


MATLAB requires that the M-file must be stored either in the working directory or in a
directory that is specified in the MATLAB path list. For example, consider using
MATLAB on a PC with a user-defined M-file stored in a directory called
"\MATLAB\MFILES". Then to access that M-file, either changes the working directory
by typing cd\matlab\mfiles from within the MATLAB command window or by adding
the directory to the path. Permanent addition to the path is accomplished by editing the
\MATLAB\matlabrc.m file, while temporary modification to the path is accomplished by
typing addpath c:\matlab\mfiles from within MATLAB.

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.

T = input ('Input the value of T: ')

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.

How to get started??

Double click on icon for MATLAB 6.5. Within about 30 seconds MATLAB will
open, a screen like the picture below appears.

Department Of ECE signal processing Lab Manual


8
College of Engineering Trikaripur

This is the MATLAB screen. It has broken into 3 parts.

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.

Department Of ECE signal processing Lab Manual


9
College of Engineering Trikaripur

The M-file is executed using the Run command under the Tools menu. The output
signal appears in Figure Window.

Department Of ECE signal processing Lab Manual


10
College of Engineering Trikaripur
The out put data appears in Command Window.

Result:-

Familiarized with MATLAB software, functions and signal processing toolbox


commands.

Department Of ECE signal processing Lab Manual


11
College of Engineering Trikaripur

Experiment No: 2
Date:

GENERATION OF WAVEFORMS
Aim:-

Periodic Continuous Signals Aperiodic Continuous Signals Discrete Signals


i Sine Wave i Exponential Signal i Sine Wave
ii Cosine Wave ii Sinc ii Cosine Wave
iii Tangent Wave iii Signum iii Square Wave
iv Square Wave iv Triangular Pulse iv Sawtooth Wave
v Sawtooth Wave v Rectangular Pulse v Triangular Wave
vi Triangular Wave

%Program
clc;
clear all;
close all;

% Periodic Continuous Signals


t=0:0.01:6*pi;
f=1;
%sine wave
x=sin(2*pi*f*t);
subplot(3,2,1);
plot(t,x);
title('sine wave');
grid on

%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

Department Of ECE signal processing Lab Manual


12
College of Engineering Trikaripur
%square wave
t=0:0.001:1;
f=10;
a=square(2*pi*f*t);
subplot(3,2,2);
plot(t,a);
title('square wave');

%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');

Department Of ECE signal processing Lab Manual


13
College of Engineering Trikaripur

%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');

Department Of ECE signal processing Lab Manual


14
College of Engineering Trikaripur

Observation

Result:-

Written and executed a MATLAB program to generate the following waveforms:


unit impulse signal, unit step signal, ramp signal and exponential signal and verified the
output

Department Of ECE signal processing Lab Manual


15
College of Engineering Trikaripur

Experiment No: 3
Date:

AM & FM GENERATION

Aim: -

To write a MATLAB program to generate AM and FM waves.

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)));

Department Of ECE signal processing Lab Manual


16
College of Engineering Trikaripur
subplot(3,1,1);
plot(x,m);
Pg no:6
ylabel('Amplitude');xlabel('Time');title('FM');
subplot(3,1,2);
plot(x,z);
ylabel('Amplitude');xlabel('Time');title('Carrier');
subplot(3,1,3);
plot(x,y);
ylabel('Amplitude');xlabel('Time');title('Message');

Observation

Inputs:-

Enter carrier amplitude(V):5


Enter carrier frequency(Hz):1000
Enter message amplitude(V):2
Enter message frequency(Hz):100

Department Of ECE signal processing Lab Manual


17
College of Engineering Trikaripur

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:-

Written and executed a MATLAB program to generate AM and FM waves and


verified the output.

Department Of ECE signal processing Lab Manual


18
College of Engineering Trikaripur

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);

Department Of ECE signal processing Lab Manual


19
College of Engineering Trikaripur
subplot(4,1,1);
plot(t,Vm);
ylabel('message signal');
Vc=sin(2*pi*fc*t);
subplot(4,1,2);
plot(t,Vc);
Pg no:8
ylabel('carrier signal');
Y=sin(2*pi*fc*t+mi*sin(2*pi*fm*t));
subplot(4,1,3);
plot(t,Y);
ylabel('FM signal');
ang=unwrap(angle(hilbert(Y).*exp(-j*2*pi*fc*t)));
AM=ang.*Y;
message=Y.*AM;
[b,a]=butter(n,Wn);
message=filtfilt(b,a,message);
subplot(4,1,4);
plot(t,message);
ylabel('demodulated signal');

Department Of ECE signal processing Lab Manual


20
College of Engineering Trikaripur

Observation

AM Demodulation:
Inputs:
Vm=1
Vc=2
fm=100
fc=1000
mod=.5

Department Of ECE signal processing Lab Manual


21
College of Engineering Trikaripur

FM Demodulation:
Inputs:
fm=100
fc=1000
Mi=5

Result:-

Written and executed a MATLAB program to implement AM & FM demodulation


and verified the output.

Department Of ECE signal processing Lab Manual


22
College of Engineering Trikaripur

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:

% Program for Impulse Response


clc;
x=input('Enter the first sequence :'); % input first sequence
y=input('Enter the second sequence :'); % input second sequence
h=deconv(y,x); % deconvolves the vector y and x
Ans=h % shows the answer

% Plot the first input sequence


subplot(2,2,1);
stem(x); % plots the data sequence as stems
xlabel({'TIME'; strcat('x(n) = [', num2str(x), ']')}); % label appears below x axis
ylabel('x(n)'); % label appears beside y axis
title('FIRST INPUT SEQUENCE');

% Plot the second input sequence

subplot(2,2,2);

Department Of ECE signal processing Lab Manual


23
College of Engineering Trikaripur
stem(y); % plots the data sequence as stems
xlabel({'TIME'; strcat('y(n) = [', num2str(y), ']')}); % label appears below xaxis
ylabel('y(n)'); % label appears beside yaxis
title('SECOND INPUT SEQUENCE');

% Plot the output sequence

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

Enter the first sequence : [1 2 3 4]


Enter the second sequence: [1 2 3 4 0 0 0]

Ans =

1 0 0 0

Department Of ECE signal processing Lab Manual


24
College of Engineering Trikaripur

Figure:

Result:-
Obtained the impulse response from the convoluted output sequence and verified.

Department Of ECE signal processing Lab Manual


25
College of Engineering Trikaripur

Experiment No: 6
Date:
LINEAR CONVOLUTION

Aim:-
Write a MATLAB program to find the linear convolution of two sequences.

Theory:

Convolution is a formal mathematical operation, just as multiplication, addition,


and integration.Addition takes two numbers and produces a third number, while
convolution takes two signalsand produces a third signal. Convolution is used in the
mathematics of many fields, such asprobability and statistics. In linear systems,
convolution is used to describe the relationshipbetween three signals of interest: the input
signal, the impulse response, and the output signal.

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

Department Of ECE signal processing Lab Manual


26
College of Engineering Trikaripur

Program:-

% Program for Linear Convolution


clc;
x=input('enter the first sequence :'); % input first sequence
h=input('enter the second sequence :'); % input second sequence
y=conv(x,h); % convolves the vector x and h
ans=y % shows the answer

% Plot the first input sequence


subplot(2,2,1);
stem(x); % plots the data sequence as stems
xlabel({'TIME'; strcat('x(n) = [', num2str(x), ']')}); % label appears below x axis
ylabel('x(n)'); % label appears beside y axis
title('FIRST INPUT SEQUENCE');

% Plot the second input sequence

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');

% Plot the output 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');

Department Of ECE signal processing Lab Manual


27
College of Engineering Trikaripur

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.

Department Of ECE signal processing Lab Manual


28
College of Engineering Trikaripur

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

Department Of ECE signal processing Lab Manual


29
College of Engineering Trikaripur
Step 10:Plot the first, second and output sequence
Step 11:Stop

Program:-

% Program for Circular Convolution


clc;
g=input(Enter The input Sequence:);
h= input(Enter The Second Sequence:);
N1=length(g); %Returns the length of vector
N2=length(h);

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

Department Of ECE signal processing Lab Manual


30
College of Engineering Trikaripur
Ans=y

% Plot the first input sequence


subplot(3,1,1);
stem(g);
title('FIRST INPUT SEQUENCE');
xlabel({'time'; strcat('g(n) = [', num2str(g), ']')});
ylabel('g(n)');

% Plot the second input sequence


subplot(3,1,2);
stem(h);
title('SECOND INPUT SEQUENCE');
xlabel({'time'; strcat('h(n) = [', num2str(h), ']')});
ylabel('h(n)');

% Plot the output sequence


subplot(3,1,3);
stem(y);
title('CIRCULAR CONVOLUTION OF TWO SEQUENCE');
xlabel({'time'; strcat('y(n) = [', num2str(y), ']')});
ylabel('y(n)');

Department Of ECE signal processing Lab Manual


31
College of Engineering Trikaripur
Observation:-

Enter the first input sequence:[4 5 6 7]


Enter the second input sequence:[1 2]
Ans =
18 13 16 19 0 0 0
Figure:

Result:-
Obtained the circular convolution of two sequences and verified

Department Of ECE signal processing Lab Manual


32
College of Engineering Trikaripur

Experiment No: 8
Date:
CIRCULAR CONVOLUTION (USING DFT)

Aim:-

Write a MATLAB program to find the Circular Convolution of two sequences.

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:-

% Program for Circular Convolution


clc;
g=input('Enter the first input sequence:');
h=input('Enter the second input sequence:');
N1=length(g); %Returns the length of vector
N2=length(h);
N=max(N1,N2);
a1=fft(g,N);
a2=fft(h,N);
y=ifft(a1.*a2);
Ans=y

Department Of ECE signal processing Lab Manual


33
College of Engineering Trikaripur

% Plot the first input sequence


subplot(3,1,1);
stem(g);
title('FIRST INPUT SEQUENCE');
xlabel({'time'; strcat('g(n) = [', num2str(g), ']')});
ylabel('g(n)');

% Plot the second input sequence


subplot(3,1,2);
stem(h);
title('SECOND INPUT SEQUENCE');
xlabel({'time'; strcat('h(n) = [', num2str(h), ']')});
ylabel('h(n)');

% Plot the output sequence


subplot(3,1,3);
stem(y);
title('CIRCULAR CONVOLUTION OF TWO SEQUENCE');
xlabel({'time'; strcat('y(n) = [', num2str(y), ']')});
ylabel('y(n)');

Observation:-

Enter the first input sequence: [4 5 6 7]


Enter the second input sequence: [1 2]
Ans =

18 13 16 19

Department Of ECE signal processing Lab Manual


34
College of Engineering Trikaripur

Figure:

Result:-
Obtained the circular convolution using DFT and output verified

Department Of ECE signal processing Lab Manual


35
College of Engineering Trikaripur

Experiment No: 9
Date:

VERIFICATION OF SAMPLING THEOREM


Aim:-

Write a MATLAB program to verify the sampling theorem.

Theory:-

In signal processing, sampling is the reduction of a continuous signal to a discrete


signal. A sample refers to a value or set of values at a point in time and/or space. A band
limited signal is converted to discrete time signal using sampling process. A signal or
function is bandlimited if it contains no energy at frequencies higher than some bandlimit
or bandwidthB.The sampling frequency should be at least twice the highest frequency
contained in the signal.nbOr in mathematical terms:Nyquist sampling theorem shows that
a bandlimitedanalog signal that has been sampled can be perfectly reconstructed from an
infinite sequence of samples if the sampling rate exceeds 2B samples per second, where B
is the highest frequency in the original signal.

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

Department Of ECE signal processing Lab Manual


36
College of Engineering Trikaripur

PROGRAM:-

% Program for verifying sampling theorem


clc;
t=[0:0.001:.1];
y=cos(2*pi*50*t);
fs=input('Enter the sampling frequency :');
ts=1/fs;
tx=[0:ts:.1];
ys=cos(2*pi*50*tx);

% Plot the original signal


subplot(3,1,1);
plot(t,y);
ylabel('Amplitude');
xlabel('Time');
title('ORIGINAL SIGNAL');

% Plot the sampled signal


subplot(3,1,2);
stem(tx,ys);
ylabel('Amplitude');
xlabel('Time');
title('SAMPLED SIGNAL');

% Plot the recovered signal


subplot(3,1,3);
plot(tx,ys);
ylabel('Amplitude');
xlabel('Time');
title('RECOVERED SIGNAL');

Department Of ECE signal processing Lab Manual


37
College of Engineering Trikaripur

Observation:-

Enter the sampling frequency: 500 (fs>2fm)

Figure:

Department Of ECE signal processing Lab Manual


38
College of Engineering Trikaripur

Enter the sampling frequency: 100 (fs=2fm)

Figure:

Enter the sampling frequency: 75 (fs<2fm)

Department Of ECE signal processing Lab Manual


39
College of Engineering Trikaripur

Figure:

Result:-

Verified the sampling theorem

Department Of ECE signal processing Lab Manual


40
College of Engineering Trikaripur

Experiment No: 10
Date:
UPSAMPLING AND DOWNSAMPLING

Aim:-
To write a MATLAB program to implement upsampling and downsampling of a
sequence.

Program:-

%TIME DOMAIN

x=input('Enter the sequence');


m=input('Enter the scale factor');
l=length(x);
subplot(311);
stem(x);
title('Input sequence');
ylabel('x(n)');
xlabel('------> n');
%UPSAMPLING
Xu=zeros(1,m*(l-1)+1);
for i=0:l-1
Xu(m*i+1)=x(i+1);
end
subplot(312);
stem(Xu);
title('Upsampling');
ylabel('Xu(n)');
xlabel('------> n');

%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;

Department Of ECE signal processing Lab Manual


41
College of Engineering Trikaripur
x=input('Enter the sequence');
N=length(x);
M=input('Enter the scaling factor ');
%DOWNSAMPLING
L=ceil(N/M);
x1=[x zeros(1,(L*M-N))];
X=fft(x1);
Y=zeros(1,L);
for k=1:L
for l=0:M-1
Y(k)=Y(k)+X(k+L*l);
end
end
Y=(1/M)*Y;
y=ifft(Y);
subplot(3,1,1);
stem(x);
title('input');
xlabel('n');
ylabel('Amplitude');
subplot(3,1,2);
stem(y);
title('downsampled output');
xlabel('n');
ylabel('Amplitude');
%UPSAMPLING
Xk=fft(x);
Y=[];
Xk
for m=1:M
Y=[Y Xk];
end
Y
d=ifft(Y);
subplot(3,1,3);
stem(d);
title('upsampled output');
xlabel('n');
ylabel('Amplitude');

Department Of ECE signal processing Lab Manual


42
College of Engineering Trikaripur

Observation:-

Time domain:
Inputs:-
Enter the sequence [1 2 3 4 5 6 7]
Enter the scale factor 3

Department Of ECE signal processing Lab Manual


43
College of Engineering Trikaripur

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.

Department Of ECE signal processing Lab Manual


44
College of Engineering Trikaripur

Experiment No: 11
Date:
FFT AND IFT OF A GIVEN SEQUENCE
Aim:-

Write a MATLAB program to find FFT and IFT of a given sequence.

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:-

% Program to find FFT and inverse FFT


clc;
x=input('Enter the input sequence: ');
n=input('Enter the length of Sequence: ');
y=fft(x,n); % Find the FFT of sequence
yinv=ifft(y); % Find the inverse FFT of sequence
y=abs(y) % shows the absolute value of y
yinv=abs(yinv) % shows the absolute value of yinv

% Plot the input sequence


subplot(3,1,1);
ylabel('x(n)');
stem(x);
title('INPUT SEQUENCE');

Department Of ECE signal processing Lab Manual


45
College of Engineering Trikaripur
xlabel('n');

% Plot the FFT of sequence


subplot(3,1,2);
stem(abs(y));
title('FFT OF SEQUENCE');
xlabel('K');
ylabel('y(k)');

% Plot the inverse FFT of sequence


subplot(3,1,3);
stem(yinv);
title('INVERSE FFT');
xlabel('n');
ylabel('x');

Observation:-
Enter the input sequence: [4 5 6 7]

Enter the length of Sequence: 8

y=

22.0000 14.7143 2.8284 5.9574 2.0000 5.9574 2.8284 14.7143

yinv =

4.0000 5.0000 6.0000 7.0000 0 0.0000 0 0.0000

Department Of ECE signal processing Lab Manual


46
College of Engineering Trikaripur

Figure:

Result:-

Obtained FFT and IFT of the given sequences and verified

Department Of ECE signal processing Lab Manual


47
College of Engineering Trikaripur

Experiment No: 12
Date:

IIR BUTTERWORTH LOWPASS FILTER


Aim:-
Write a MATLAB program to design IIR Butterworth filter

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));

Department Of ECE signal processing Lab Manual


48
College of Engineering Trikaripur
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');
ylabel('Phase in Radians');
title('Phase response');

Observation:-

Enter the passband ripple: 0.5


Enter the stopband ripple: 50
Enter the passband frequency: 1200
Enter the stopband frequency: 2400
Enter the sampling frequency: 10000

Department Of ECE signal processing Lab Manual


49
College of Engineering Trikaripur
Figure:

Result:-

Obtained and verified the amplitude and phase response of IIR


butterworth low pass filter .

Department Of ECE signal processing Lab Manual


50
College of Engineering Trikaripur

Experiment No: 13
Date:

IIR BUTTERWORTH HIGHPASS FILTER


Aim:-
Write a MATLAB program to design IIR Butterworth filter

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];

Department Of ECE signal processing Lab Manual


51
College of Engineering Trikaripur
[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');
ylabel('Phase in Radians');
title('Phase response');

Observation:-

Enter the passband ripple: 0.5


Enter the stopband ripple: 50
Enter the passband frequency: 1200
Enter the stopband frequency: 2400
Enter the sampling frequency: 10000

Department Of ECE signal processing Lab Manual


52
College of Engineering Trikaripur

Figure:

Result:-

Obtained and verified the amplitude and phase response of IIR butterworth
high pass filter .

Department Of ECE signal processing Lab Manual


53
College of Engineering Trikaripur

Experiment No: 14
Date:

IIR BUTTERWORTH BANDPASS FILTER


AIM:-
Write a MATLAB program to design IIR Butterworth 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]=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');

%Plot phase response


subplot(2,1,2);
plot(omega/pi,an);
xlabel('Normalised Frequency');
ylabel('Phase in Radians');

Department Of ECE signal processing Lab Manual


54
College of Engineering Trikaripur
title('Phase response');
Observation:-
Enter the passband ripple: 0.2
Enter the stopband ripple: 40
Enter the passband frequency: [4800 5200]
Enter the stopband frequency: [4500 5500]
Enter the sampling frequency: 20000

Figure:

Result:-

Obtained and verified the amplitude and phase response of IIR butterworth band
pass filter .

Department Of ECE signal processing Lab Manual


55
College of Engineering Trikaripur

Experiment No: 15
Date:

IIR BUTTERWORTH BANDSTOP FILTER

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

Step 3: Compute the frequency in radians/sec


Step 4: Find out the 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, cut off frequency wn, and to designate for stopband filter as
stop
Step 6: Find the frequency response of filter using the coefficients with command word
freqs.
Step 7: Find the magnitude and phase of filter
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);

Department Of ECE signal processing Lab Manual


56
College of Engineering Trikaripur
[b,a]=butter(n,wn,'stop');
w=[0:0.01:pi];
[h,omega]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(omega/pi,m);
xlabel('Normalised Frequency');
ylabel(gain in dB);
title('Amplitude response');
Subplot(2,1,2);
Plot (omega/pi,m);
xlabel('Normalised Frequency');
ylabel(phase inRadian');
title('Phase response');

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.

Department Of ECE signal processing Lab Manual


57
College of Engineering Trikaripur

Experiment No: 16
Date:

IIR CHEBYSHEV TYPE-1 LOWPASS FILTER


Aim:-
Write a MATLAB program to design IIR Chebyshev type-1 lowpass 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
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));

Department Of ECE signal processing Lab Manual


58
College of Engineering Trikaripur
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');
ylabel('Phase in Radians');
title('Phase response');

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

Department Of ECE signal processing Lab Manual


59
College of Engineering Trikaripur
Figure:

Result:-

Obtained the result and verified the amplitude and phase response of IIR
chebyshev type-1 low pass filter .

Department Of ECE signal processing Lab Manual


60
College of Engineering Trikaripur

Experiment No: 17
Date:

IIR CHEBYSHEV TYPE-1 HIGHPASS FILTER

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);

Department Of ECE signal processing Lab Manual


61
College of Engineering Trikaripur
[b,a]=cheby1(n,rp,wn,'high');
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');
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

Department Of ECE signal processing Lab Manual


62
College of Engineering Trikaripur

Figure:

Result:-

Obtained and verified the amplitude and phase response of IIR chebyshev type-1
high pass filter.

Department Of ECE signal processing Lab Manual


63
College of Engineering Trikaripur

Experiment No: 18
Date:

IIR CHEBYSHEV TYPE-1 BANDPASS FILTER


Aim:-
Write a MATLAB program to design IIR Chebyshev type-1 bandpass 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,'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');

Department Of ECE signal processing Lab Manual


64
College of Engineering Trikaripur
ylabel('Phase in Radians');
title('Phase response');

Observation:-

Enter the passband ripple:0.5


Enter the stopband ripple:40
Enter the passband frequency:[4500 5500]
Enter the stopband frequency:[4800 5200]
Enter the sampling frequency:20000
Figure:

Result:-
Obtained the result and verified the amplitude and phase response of IIR
chebyshev type-1band pass filter.

Department Of ECE signal processing Lab Manual


65
College of Engineering Trikaripur

Experiment No: 19
Date:

IIR CHEBYSHEV TYPE-1 BANDSTOP FILTER

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];

Department Of ECE signal processing Lab Manual


66
College of Engineering Trikaripur
[h,omega]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(omega/pi,m);
xlabel('Normalised Frequency');
ylabel('Gain in dB');
title('Amplitude Response');
subplot(2,1,1);
plot(omega/pi,an);
xlabel('Normalised Frequency');
ylabel('Gain in dB');
title('Phase response');

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 the and verified the amplitude and phase response of IIR
chebyshev type-1band stop filter .

Department Of ECE signal processing Lab Manual


67
College of Engineering Trikaripur

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:-

1.% RECTANGULAR WINDOW OF FIR LPF

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 the filter response

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));

Department Of ECE signal processing Lab Manual


68
College of Engineering Trikaripur
[Hm,f]=freqz(ham,1,512,fs);
m=20*log10(abs(Hm));

% Plot the filter response

plot(f,m);
grid on;
xlabel('frequency(Hz)');
ylabel('Magnitude(dB)');
Title('HAMMING WINDOW');

3. % BLACKMAN WINDOW OF FIR LPF


clc;
fc=0.5;
fs=10000;
N=28;
black=fir1(N-1,fc,blackman(N));
[Hb,f]=freqz(black,1,512,fs);
m=20*log10(abs(Hb));
% Plot the filter response
plot(f,m);
grid on;
xlabel('frequency(Hz)');
ylabel('Magnitude(dB)');
Title('BLACKMAN WINDOW');
4. % BARLETT WINDOW OF FIR LPF

clc;
fc=0.5;
fs=10000;
N=28;
bart=fir1(N-1,fc,bartlett(N));

Department Of ECE signal processing Lab Manual


69
College of Engineering Trikaripur
[Hb,f]=freqz(bart,1,512,fs);
m=20*log10(abs(Hb));

% Plot the filter response

plot(f,m);
grid on;
xlabel('frequency(Hz)');
ylabel('Magnitude(dB)');
Title('BARTLETT WINDOW');

Observation:-

Figures:

1. Rectangular Window

Department Of ECE signal processing Lab Manual


70
College of Engineering Trikaripur

2. Hamming Window

3. Blackman Window

Department Of ECE signal processing Lab Manual


71
College of Engineering Trikaripur

4.Bbarlett Window

Result:-

Obtained and verified the generation of FIR low pass filter using rectangular
window,hamming window,blackmann window and bartlett

Department Of ECE signal processing Lab Manual


72
College of Engineering Trikaripur

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:-

1.% RECTANGULAR WINDOW OF FIR LPF


fc=0.5;
fs=10000;
N=17;
b=fir1(N-1,fc,highboxcar(N)); %boxcar(N)-coputes rectangular window.
[H,f]=freqz(b,1,512,fs);
plot(f, 20*log10(abs(H));
grid on;
xlabel('frequency in (Hz)');
ylabel('Magnitude in (dB)');
Title('Truncated ideal');
% HAMMING WINDOW
fc=0.5;
fs=10000;
N=17;
ham=fir1(N-1,fc, highhamming(N)); % hamming(N)computes a hamming window.
[Hm,f]=freqz(ham,1,512,fs);
plot(f,20*log10(abs(Hm))
grid on;
xlabel('frequency in (Hz)');
ylabel('Magnitude in (dB)');
Title('HAMMING ');

Department Of ECE signal processing Lab Manual


73
College of Engineering Trikaripur
% blackmann window
fc=0.5;
fs=10000;
N=27;
b=fir1(N-1,fc,blackman(N)); % blackman(N) computes a blackmann window
[Hb,f]=freq (b,1,512,fs)
plot(f,20*log10(abs(Hb))
grid on;
xlabel('frequency in (Hz)');
ylabel('Magnitude in (dB)');
Title('BLACKMAN);
% BARLETT WINDOW OF FIR LPF
fc=0.5;
fs=10000;
N=27;
bart=fir1(N-1,fc,bartlett(N)); % bartlett(N) computes a Bartlett window.
[Hb,f]=freqz(bart,1,512,fs);
plot(f,20*log10(abs(Hb));
grid on;
xlabel('frequency in (Hz)');
ylabel('Magnitude in (dB)');
Title('BARTLETT ');

RESULT:-

Obtained and verified the generation of FIR high pass filter using rectangular
window,hamming window,blackmann window and Bartlett windows.

Department Of ECE signal processing Lab Manual


74
College of Engineering Trikaripur

Experiment No: 22
Date:

LOW PASS FILTER USING KAISER WINDOW

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');

Department Of ECE signal processing Lab Manual


75
College of Engineering Trikaripur

Input:-

Enter the pass band ripple(in dB):0.01


Enter the stop band ripple(in dB):40
Enter the pass band edge:1000
Enter the stop band edge:1500
Enter the sampling frequency:10000

Observation:-

Result:-

Written and executed a MATLAB program plot frequency response of a Low


Pass filter using Kaiser Window and verified the output.

Department Of ECE signal processing Lab Manual


76
College of Engineering Trikaripur

Experiment No: 23
Date:

HIGH PASS FILTER USING KAISER WINDOW

Aim:-

To write a MATLAB program to plot frequency response of a High 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=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');

Department Of ECE signal processing Lab Manual


77
College of Engineering Trikaripur

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:-

Written and executed MATLAB program to plot frequency response of a High


Pass filter using Kaiser Window.

Department Of ECE signal processing Lab Manual


78
College of Engineering Trikaripur

Experiment No: 24
Date:

BAND PASS FILTER USING KAISER WINDOW


Aim:-
To write a MATLAB program to plot frequency response of a Band 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=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');

Department Of ECE signal processing Lab Manual


79
College of Engineering Trikaripur

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.

Department Of ECE signal processing Lab Manual


80
College of Engineering Trikaripur

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);

%time revesal property:

Department Of ECE signal processing Lab Manual


81
College of Engineering Trikaripur
g1=fft(circshift(fliplr(x1),[0,1]));
g2=circshift(fliplr(x1k),[0,1]);
disp('time revesal property');
disp('dft of x(-n):');
disp(g1);
disp('x(-k)n:');
disp(g2);

%time shifting property


m=input('enter the value of m:');
k=0:n1-1;
g=fft(circshift(x1,[0,m]));
h=exp((-1i*2*pi*k*m)/n1).*x1k(k+1);
disp('time shifting property');
disp('dft of x(n-m)n:');
disp(g);
disp('wn^km x[k]');
disp(h);

%frequncy shifting property


l=input('enter a value of l:');
n=0:n1-1;
o=fft(exp((1i *2*pi*l*n)/n1).*x1(n+1));
p=circshift(x1k,[0,1]);
disp('freequncy shifting property');
disp('dft of wn^lnx(n):');
disp(o);
disp('x(k-l):');
disp(p);

%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);

Department Of ECE signal processing Lab Manual


82
College of Engineering Trikaripur
disp('x1(k)*x2(k):');
disp(s);

%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);

%complex conjugate property


v=fft(conj(x1));
N=conj(circshift(fliplr(x1k),[0,1]));
disp('dft(conj x(n)=conj x(-k)');
disp('dft(conj x(n):');
disp(v);
disp('conj x(-k):');
disp(N);

%dft [re x(n)]=even part of x(k)


x=fft (real (x1));
g= (x1k + conj(circshift (fliplr (x1k),[0,1])))/2;
disp('dft (re x(n))=even part of x(k)')
disp('dft (re x(n)):');
disp(x);
disp('even part of x(k):');
disp(g);

%dft (jim(x(n))=odd part of x(k)


x=fft(1i*imag(x1));
g=(x1k - conj(circshift(fliplr(x1k),[0,1])))/2; c
disp('dft(jim(x(n))=oddpart of x(k)');
disp('dft(jim(x(n)):');
disp(x);
disp('odd part of x(k):');

Department Of ECE signal processing Lab Manual


83
College of Engineering Trikaripur
disp(g);

%dft of even part of x(n)=re x(k)


a1=fft(x1+conj(circshift(fliplr(x1),[0,1])))/2;
b1=real(x1k);
disp('dft of even part of x(n)=re x(k)');
disp('dft of even part of x(n):');
disp(a1);
disp('re x(k):');
disp(b1);

%dft of odd part of x(n)=jim x(k)


c1=fft(x1-conj(circshift(fliplr(x1),[0,1])))/2;
d1=1i*imag (x1k);
disp('dft of odd part of x(n)=jim x(k)');
disp('dft of odd part of x(n):');
disp(c1);
disp('jim x(k):');
disp(d1);

%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);

%imag (x(k))= -imag (x(-k))


a=imag (x1k);
b=-imag (circshift(fliplr(x1k),[0,1]));
disp('imag (x(k))=-imag(x(-k))');
disp('imag (x(k))');
disp(a);
disp('-imag (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))');

Department Of ECE signal processing Lab Manual


84
College of Engineering Trikaripur
disp(h3);

%<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

enter first sequnce: [1 0 1]


enter second sequnce:[1 1 1]
enter the value for a:1
enter the value for b:2
linearity property
dft(a*x1+b*x2):
8.000000000000000 0.500000000000000 + 0.866025403784439i
0.500000000000000 - 0.866025403784439i

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

time revesal property


dft of x(-n):
2.000000000000000 0.500000000000000 - 0.866025403784439i
0.500000000000000 + 0.866025403784439i

x(-k)n:
2.000000000000000 0.500000000000000 - 0.866025403784439i
0.500000000000000 + 0.866025403784439i

enter the value of m:3


time shifting property
dft of x(n-m)n:
2.000000000000000 0.500000000000000 + 0.866025403784439i

Department Of ECE signal processing Lab Manual


85
College of Engineering Trikaripur
0.500000000000000 - 0.866025403784439i

wn^km x[k]
2.000000000000000 0.500000000000000 + 0.866025403784439i
0.500000000000000 - 0.866025403784438i

enter a value of l:4


freequncy shifting property
dft of wn^lnx(n):
0.499999999999998 - 0.866025403784438i 2.000000000000000 -
0.000000000000002i 0.500000000000002 + 0.866025403784439i

x(k-l):
0.500000000000000 - 0.866025403784439i 2.000000000000000
0.500000000000000 + 0.866025403784439i

dft [x1(n) conv x2(n)=x1(k)*x2(k):


dft[x1(n)conv x2(n):
6 0 0

x1(k)*x2(k):
6 0 0

dft [x1(n)* x2(n)=1/n(x1(k)conv x2(k):


dft[x1(n)* x2(n):
2.000000000000000 0.500000000000000 + 0.866025403784439i
0.500000000000000 - 0.866025403784439i

1/n(x1(k) conv x2(k):


2.000000000000000 0.500000000000000 + 0.866025403784439i
0.500000000000000 - 0.866025403784439i

dft(conj x(n)=conj x(-k)


dft(conj x(n):
2.000000000000000 0.500000000000000 + 0.866025403784439i
0.500000000000000 - 0.866025403784439i

conj x(-k):
2.000000000000000 0.500000000000000 + 0.866025403784439i
0.500000000000000 - 0.866025403784439i

dft (re x(n))=even part of x(k)


dft (re x(n)):
2.000000000000000 0.500000000000000 + 0.866025403784439i
0.500000000000000 - 0.866025403784439i

Department Of ECE signal processing Lab Manual


86
College of Engineering Trikaripur
even part of 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

odd part of x(k):


0 0 0

dft of even part of x(n)=re x(k)


dft of even part of x(n):
2.000000000000000 0.500000000000000 0.500000000000000

re x(k):
2.000000000000000 0.500000000000000 0.500000000000000

dft of odd part of x(n)=jim x(k)


dft of odd part of x(n):
0 0 + 0.866025403784439i 0-
0.866025403784439i

jim x(k):
0 0 + 0.866025403784439i 0-
0.866025403784439i

symmetry property:real x(k)=real(x(-k))


real x(k)
2.000000000000000 0.500000000000000 0.500000000000000

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) = abs x(-k)


abs x(k)
2.000000000000000 1.000000000000000 1.000000000000000

abs (x(-k))

Department Of ECE signal processing Lab Manual


87
College of Engineering Trikaripur
2.000000000000000 1.000000000000000 1.000000000000000

angle x(k) = angle x(-k)n


angle x(k)
0 1.047197551196598 -1.047197551196598

angle (x(-k)n
0 1.047197551196598 -1.047197551196598

>>

Result:- Verified the properties of DFT.

Department Of ECE signal processing Lab Manual


88
College of Engineering Trikaripur

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;

%high pass filtering a square wave


fs=1000;
t=-0.1:1/fs:0.1;
fm=100;
x=square (2*pi*fm*t);
x1=x;
wp=(5*fm)/fs;
ws=(1*fm)/fs;
ap=2;
as=30;
[n wc]=buttord(wp,ws,ap,as);
[b a]=butter(n,wc,'high');
[h w]=freqz(b,a,512,fs);
y=filter(b,a,x1);

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));

Department Of ECE signal processing Lab Manual


89
College of Engineering Trikaripur
title('phase response');

%am modulation using lpf;


fs=1000;
t=-0.1:1/fs:0.1;
fm=10;
fc=100;
k=0.5;
m=sin(2*pi*fm*t);
c=sin(2*pi*fc*t);
am1=c.*(1+k*m);
am2=am1.*c;
[n wc]=buttord(wp,ws,ap,as);
[b a]=butter(n,wc);
[h w]=freqz(b,a,512,fs);
y=filter(b,a,am2);

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');

%carrier recovery using bpf


clc;
clear all;
fs=1000;
fc=100;
t=-0.4:1/fs:0.4;
fm=10;
k=0.5;
m=-cos(2*pi*fm*t);
c=sin(2*pi*fc*t);
am1=c.*(1+k*m);

Department Of ECE signal processing Lab Manual


90
College of Engineering Trikaripur
am2=am1.*c;
wp=2*[0.98*fc 1.02*fc]/fs;
ws=2*[0.95*fc 1.075*fc]/fs;
ap=2;
as=30;
[n wc]=buttord(wp,ws,ap,as);
[b a]=butter(n,wc,'bandpass');
[h w]=freqz(b,a,512,fs);
y=filter(b,a,am1);

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');

%lowpass filtering a square wave


fs=1000;
fm=2;
t=-1:1/fs:1;
x=square(2*pi*fm*t);
x1=x;
ap=2;
as=30;
wp=(20*fm)/fs;
ws=(40*fm)/fs;
[n wc]=buttord(wp,ws,ap,as);
[b a]=butter(n,wc);
[h w]=freqz(b,a,512,fs);
y=filter(b,a,x1);

figure(7);
subplot(211);
plot(t,x);

Department Of ECE signal processing Lab Manual


91
College of Engineering Trikaripur
subplot(212);
plot(t,y);

figure(8);
subplot(211);
plot(w,abs(h));
title('magnitude response');
subplot(212);
plot(w,angle(h));
title('phase response');

%lp,hp,bp filtering on sum of 3 sine waves


fs=1000;
t=-0.1:1/fs:0.1;
fm=2;
x1=sin(2*pi*fm*t);
x2=sin(2*pi*2*fm*t);
x3=sin(2*pi*4*fm*t);
x=x1+x2+x3;
wp1=(2*fm)/fs;
ws1=(4*fm)/fs;
wp2=[3*fm 4*fm]/fs;
ws2=[2*fm 6*fm]/fs;
wp3=(8*fm)/fs;
ws3=(5*fm)/fs;
ap=2;
as=30;

[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);

Department Of ECE signal processing Lab Manual


92
College of Engineering Trikaripur
plot(t,x2);
subplot(223);
plot(t,x3);
subplot(224);
plot(t,x);

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');

%noise removel using lpf

fs=1000;
t=-1:1/fs:1;
fm=5;

Department Of ECE signal processing Lab Manual


93
College of Engineering Trikaripur
x=sin(2*pi*fm*t);
n0=0.5*(rand(1,length(x))-0.5);
%n0=x+n0;
%x=n0;
wp=(2*fm)/fs;
wr=(4*fm)/fs;
ap=2;
as=30;
[n wc]=buttord(wp,ws,ap,as);
[b a]=butter(n,wc);
[h w]=freqz(b,a,512,fs);
y=filter(b,a,x-n0);

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');

Department Of ECE signal processing Lab Manual


94
College of Engineering Trikaripur
Observation:-

i) High Pass filtering a square wave

ii) Low Pass filtering a square wave

Department Of ECE signal processing Lab Manual


95
College of Engineering Trikaripur
iii) AM demodulation using low pass filter

Department Of ECE signal processing Lab Manual


96
College of Engineering Trikaripur

iv)carrier recovery using BPF

Department Of ECE signal processing Lab Manual


97
College of Engineering Trikaripur

v)Low pass filtering a square wave

Department Of ECE signal processing Lab Manual


98
College of Engineering Trikaripur

vi) LP,HP,BP filtering and sum of three sine waves

Department Of ECE signal processing Lab Manual


99
College of Engineering Trikaripur
vii) Noise removal using low pass filter

Result
Wrote a MATLAB program to verify the applications of filters

Department Of ECE signal processing Lab Manual


100
College of Engineering Trikaripur

Experiment No: 27
Date:

CORRELATION

Aim:-
To write a MATLAB program to find auto correlation and cross correlation of
random and deterministic signals.

Theory:-

Correlation is a measure of degree to which two signals are similar.


Cross correlation:- correlation between two different signals
Auto correlation:- correlation between a signal and its delayed version.

Program:-
clc;
clear all;
close all;

x = input ('enter first sequence');


y = input ('enter second sequence');
z = xcorr(x,y);
disp('cross correlation');
disp (z);
p = xcorr(x);
disp('auto correlation');
disp (p);

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);

Department Of ECE signal processing Lab Manual


101
College of Engineering Trikaripur
stem(p);
title('auto correlated sequence');

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

Department Of ECE signal processing Lab Manual


102
College of Engineering Trikaripur
Figures

Department Of ECE signal processing Lab Manual


103
College of Engineering Trikaripur

Result

The autocorrelation and cross correlation of the signal is done.

Department Of ECE signal processing Lab Manual


104
College of Engineering Trikaripur

Experiment No: 28
Date:

FINITE WORDLENGTH EFFECT


Aim:-
To write a MATLAB program which effectively represent finite word length in
digital filter & to plot step response with different feedback factors.

Theory:-

Effects due to finite precision representation of numbers in digital systems are


commonly referred to as finite wordlength effect. The following are some of the finite
wordlength effect in digital filters
1. Errors due to quantization of input data by an output.
2. Errors due to quantization of filter coefficients
3. Errors due to rounding the production multiplications.
4. Errors due to overflow in addition
In digital computation the input and output data (sum and product) are quantized by
rounding or truncation to convert them to a finite word size. This creates errors or
oscillations in output .This effects due to finite precision representation of numbers in
digital system are called finite wordlength effect.

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);

Department Of ECE signal processing Lab Manual


105
College of Engineering Trikaripur
h3=step(g3,30);
h4=step(g4,30);
ax=['2/3','.7','.67','.667'];
h=[h1,h2,h3,h4];

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

Department Of ECE signal processing Lab Manual


106
College of Engineering Trikaripur
0.589595082050500 0.571619103000000 0.587887198775139 0.589425055238168
0.606936611966333 0.599866627900000 0.606115576820657 0.606853488156142
0.595375592022445 0.580093360470000 0.593902563530160 0.595228723399853
0.603082938651704 0.593934647671000 0.602085282434793 0.602982441492298
0.597944707565531 0.584245746630300 0.596602860768689 0.597810711524637
0.601370194956313 0.591027977358790 0.600276083284979 0.601260255413067
0.599086536695792 0.586280415848847 0.597815024199064 0.598959409639484
0.600608975536139 0.589603708905807 0.599463933786627 0.600494073770464
0.599594016309241 0.587277403765935 0.598359164362960 0.599470452795100
0.600270655793840 0.588905817363846 0.599099359876817 0.600153207985668
0.599819562804107 0.587765927845308 0.598603428882533 0.599697810273560
0.600120291463929 0.588563850508284 0.598935702648703 0.600001560547536
0.599919805690714 0.588005304644201 0.598713079225369 0.599798959114794
0.600053462872857 0.588396286749059 0.598862236919003 0.599934094270433
0.599964358084762 0.588122599275658 0.598762301264268 0.599843959121621
0.600023761276825 0.588314180507039 0.598829258152940 0.599904079265879
0.599984159148783 0.588180073645073 0.598784397037530 0.599863979129659
0.600010560567478 0.588273948448449 0.598814453984855 0.599890725920518
0.599992959621681 0.588208236086086 0.598794315830147 0.599872885811015
0.600004693585546 0.588254234739740 0.598807808393801 0.599884785164053

>>

Department Of ECE signal processing Lab Manual


107
College of Engineering Trikaripur

Result

Program is executed and obtained the result

Department Of ECE signal processing Lab Manual


108
College of Engineering Trikaripur
Experiment No: 29
Date:

FFT AND SPECTRAL ESTIMATION

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

Department Of ECE signal processing Lab Manual


109
College of Engineering Trikaripur
>>

Result

Estimated the spectrum for a sinc and rectangular pulse.

Department Of ECE signal processing Lab Manual

Das könnte Ihnen auch gefallen