Академический Документы
Профессиональный Документы
Культура Документы
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
DIGITALSIGNALPROCESSING
LAB MANUAL
PREPARED BY:
JAFERKHAN.P
ASSISTANT PROFESSOR IN ECE
DEPT:ECE
JAFERKHAN.P
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
COLLEGE OF ENGINEERING
KOTTARAKKARA
DEPT: ELECTRONICS AND COMMUNICATION
Aim: To familiarise with MATLAB software, general functions and signal processing toolbox
functions.
The name MATLAB stands for MATrix LABoratory produced by Mathworks Inc.,
USA.
It is a matrix-based powerful software package for scientific
and
engineering
computation and visualization. Complex numerical problems can be solved in a fraction of the time
that required with other high level languages. It provides an interactive environment with
hundreds of built -in functions for technical computation, graphics and animation. In addition to
built-in-functions, user can create his own functions.
MATLAB offers several optional toolboxes, such as signal processing, control
systems, neural networks etc. It is command driven software and has online help facility.
MATLAB has three basic windows normally; command window, graphics window
and edit window. Command window is characterized by the prompt >>.
All commands and the ready to run program filename can be typed here. Graphic window gives the
display of the figures as the result of the program. Edit window is to create program files with an
extension .m.
Some important commands in MATLAB
Help
List topics on which help is available
Help command name
Provides help on the topic selected
Demo
Runs the demo program
Who
Lists variables currently in the workspace
Whos
Lists variables currently in the workspace with their size
Clear
Clears the workspace, all the variables are removed
Clear x,y,z
Clears only variables x,y,z
Quit
Quits MATLAB
Some of the frequently used built-in-functions in Signal Processing Toolbox
filter(b.a.x)
Syntax of this function is Y = filter(b.a.x)
It filters the data in vector x with the filter described by vectors
a and b to create the filtered data y.
fft (x)
DEPT:ECE
JAFERKHAN.P
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
ifft (x)
conv (a,b)
deconv(b,a)
butter(N,Wn)
Cheby1(N,R,Wn,'high')
corresponding
to half the sample rate.
DEPT:ECE
JAFERKHAN.P
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
abs(x)
angle(H)
freqz(b,a,N)
Syntax of this function is [h,w] = freqz(b,a,N) returns the Npoint frequency vector w in radians and the N-point complex
response vector h of the filter b/a.
stem(y)
stem(x,y)
ploy(x,y)
title(text)
xlabel(text)
ylabel(text)
DEPT:ECE
JAFERKHAN.P
frequency
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
ALGORITHM:-
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
MATLAB CODE:clc;
clear all;
close all;
t=0:.001:1;
f=input('Enter the value of frequency');
a=input('Enter the value of amplitude');
subplot(3,3,1);
y=a*sin(2*pi*f*t);
plot(t,y,'r');
xlabel('time');
ylabel('amplitude');
title('sine wave')
grid on;
subplot(3,3,2);
z=a*cos(2*pi*f*t);
plot(t,z);
xlabel('time');
ylabel('amplitude');
title('cosine wave')
DEPT:ECE
JAFERKHAN.P
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
grid on;
subplot(3,3,3);
s=a*square(2*pi*f*t);
plot(t,s);
xlabel('time');
ylabel('amplitude');
title('square wave')
grid on;
subplot(3,3,4);
plot(t,t);
xlabel('time');
ylabel('amplitude');
title('ramp wave')
grid on;
subplot(3,3,5);
plot(t,a,'r');
xlabel('time');
ylabel('amplitude');
title('unit step wave')
grid on;
amplitude
0
1
0.5
time
rampwave
0.5
0
0.5
time
cosinewave
amplitude
sinewave
amplitude
amplitude
amplitude
FIGURE:-
0
1
0.5
1
time
unitstepwave
squarewave
1
0
1
0.5
time
1
0
0.5
time
RESULTS:- Thus the generation of continues time signals using matlab was verified
DEPT:ECE
JAFERKHAN.P
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
ALGORITHM:-
MATLAB CODE:clc;
clear all;
close all;
n=0:1:50;
f=input('Enter the value of frequency');
a=input('Enter the value of amplitude');
N=input('Enter the length of unit step');
subplot(3,3,1);
y=a*sin(2*pi*f*n);
stem(n,y,'r');
xlabel('time');
ylabel('amplitude');
title('sine wave')
grid on;
subplot(3,3,2);
DEPT:ECE
JAFERKHAN.P
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
z=a*cos(2*pi*f*n);
stem(n,z);
xlabel('time');
ylabel('amplitude');
title('cosine wave')
grid on;
subplot(3,3,3);
s=a*square(2*pi*f*n);
stem(n,s);
xlabel('time');
ylabel('amplitude');
title('square wave')
grid on;
subplot(3,3,4);
stem(n,n);
xlabel('time');
ylabel('amplitude');
title('ramp wave')
grid on;
x=0:N-1;
d=ones(1,N);
subplot(3,3,5);
stem(x,d,'r');
xlabel('time');
ylabel('amplitude');
title('unit step wave')
grid on;
amplitude
0
1
0
time
rampwave
50
50
50
time
DEPT:ECE
JAFERKHAN.P
cosinewave
amplitude
sinewave
amplitude
amplitude
amplitude
FIGURE:-
0
1
50
time
unitstepwave
squarewave
1
0
1
50
time
0.5
0
5
time
10
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
RESULTS:- Thus the generation of discrete time signals using matlab was verified
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
ALGORITHM:-
MATLAB CODE:clc;
clear all;
close all;
N=input('Enter the required length of impulse response N=');
n=0:N-1;
b=input('Enter the co-efficients of x(n),b=');
a=input('Enter the co=efficients of y(n),a=');
x=[1,zeros(1,N-1)];
y=filter(b,a,x);
stem(n,y);
DEPT:ECE
JAFERKHAN.P
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
xlabel('time');
ylabel('amplitude');
title('IMPULSE RESPONSE');
grid on;
FIGURE:IMPULSERESPONSE
1.5
amplitude
0.5
0.5
10
15
20
time
25
30
35
40
SAMPLE INPUT:Y[n]+0.7y[n-1]-0.45y[n-2]-0.6y[n-3]=0.8x[n]-0.44x[n-1]+0.36x[n-2]+0.2x[n-3]
Enter the required length of impulse response N=40
Enter the co-efficients of x(n),b=[0.8 -0.44 0.36 0.02]
Enter the co=efficients of y(n),a=[1 0.7 -0.45 -0.6]
RESULTS:- Thus the program for impulse response of an LTI system is written using
MATLAB and verified.
DEPT:ECE
JAFERKHAN.P
10
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
ALGORITHM:
MATLAB CODE:clc;
clear all;
close all;
a=input('Enter the starting point of x[n]=');
b=input('Enter the starting point of h[n]=');
x=input('Enter the co-efficients of x[n]=');
h=input('Enter the co-efficients of h[n]=');
DEPT:ECE
JAFERKHAN.P
11
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
y=conv(x,h);
subplot(3,1,1);
p=a:(a+length(x)-1);
stem(p,x);
grid on;
xlabel('Time');
ylabel('Amplitude');
title('INPUT x(n)');
subplot(3,1,2);
q=b:(b+length(h)-1);
stem(q,h);
grid on;
xlabel('Time');
ylabel('Amplitude');
title('IMPULSE RESPONSE h(n)');
subplot(3,1,3);
n=a+b:length(y)+a+b-1;
stem(n,y);
grid on;
disp(y)
xlabel('Time');
ylabel('Amplitude');
title('LINEAR CONVOLUTION');
FIGURE:INPUTx(n)
Amplitude
3
2
1
0
0.2
0.4
0.6IMPULSERESPONSEh(n)
0.8
1
1.2
1.4
Time
1.6
1.8
0
1
6
0.8
0.6
0.4 LINEARCONVOLUTION
0.2
0
0.2
0.4
Time
0.6
0.8
0.5
Amplitude
Amplitude
4
2
0
1
0.5
0.5
1
Time
1.5
2.5
SAMPLE INPUT:-Enter
Enter
Enter
Enter
the
the
the
the
1
RESULTS :- Thus the program for linear convolution is written using MATLAB and verified.
DEPT:ECE
JAFERKHAN.P
12
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
ALGORITHM:
MATLAB CODE:clc;
clear all;
close all;
a=input('Enter the starting point of x[n]=');
DEPT:ECE
JAFERKHAN.P
13
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
FIGURE:INPUTx[n]
AMPLITUDE
3
2
1
0
0.2
0.4
0.6
AMPLITUDE
1.4
1.6
1.8
4
2
0
1
1
AMPLITUDE
0.8OUTPUTy[n]
1
1.2
TIME
0.5
0.5 IMPULSEh[n]
1
1.5
TIME
2.5
0.5
0
1
0.8
0.6
DEPT:ECE
JAFERKHAN.P
0.4
0.2
0
TIME
0.2
0.4
0.6
0.8
14
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
SAMPLE INPUT:-Enter
Enter
Enter
Enter
the
the
the
the
1
RESULTS :- Thus the program for de- convolution is written using MATLAB and verified.
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
ALGORITHM:
DEPT:ECE
JAFERKHAN.P
15
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
n2=length(h);
N=max(n1,n2);
x=[x,zeros(1,N-n1)];
h=[h,zeros(1,N-n2)];
for n=0:N-1;
y(n+1)=0;
for k=0:N-1;
j= mod(n-k,N);
y(n+1)=y(n+1)+x(k+1)*h(j+1);
end
end
MATLAB CODE:clc;
clear all;
close all;
x=input('Enter the co-efficients of x1[n]=');
h=input('Enter the co-efficients of x2[n]=');
y=crconc(x,h);
subplot(3,1,1);
n=0:(length(x)-1);
stem(n,x);
grid on;
xlabel('TIME');
ylabel('AMPLITUDE');
title('x1[n]');
subplot(3,1,2);
n=0:(length(h)-1);
stem(n,h);
grid on;
xlabel('TIME');
ylabel('AMPLITUDE');
title('x2[n]');
subplot(3,1,3);
n=0:(length(y)-1);
stem(n,y);
grid on;
disp(y)
xlabel('TIME');
ylabel('AMPLITUDE');
DEPT:ECE
JAFERKHAN.P
16
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
title('OUTPUTx3[n]');
FIGURE:x1[n]
AMPLITUDE
3
2
1
0
0.2
0.4
0.6
0.8
1.2
1.4
1.6
1.8
0.1
0.2
0.3
0.4OUTPUTx3[n]
0.5
0.6
TIME
0.7
0.8
0.9
0.2
0.4
0.6
0.8
1.4
1.6
1.8
AMPLITUDE
2
1
0
10
AMPLITUDE
1
x2[n]
TIME
5
0
1
TIME
1.2
RESULTS :- Thus the program for circular convolution is written using MATLAB and
verified.
DEPT:ECE
JAFERKHAN.P
Open MATLAB
Open new M-file
Type the program
Save in current directory
17
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
ALGORITHM:-
MATLAB CODE:-
clc;
clear all;
close all;
rp=input('enter the passband attenuation:');
rs=input('enter the stop band attenuation:');
wp=input('enter the pass band frequency:');
ws=input('enter the stop band frequency:');
[N,wn]=buttord(wp/pi,ws/pi,rp,rs);
[b,a]=butter(N,wn);
freqz(b,a);
FIGURE:-
Magnitude(dB)
100
0
100
200
300
400
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
Phase(degrees)
0
200
400
600
18
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
ALGORITHM:-
DEPT:ECE
JAFERKHAN.P
19
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
MATLAB CODE:clc;
clear all;
close all;
rp=input ('Enter the pass band attenuation:');
rs=input ('Enter the stop band attenuation:');
wp=input ('Enter the pass band frequency:');
ws=input ('Enter the stop band frequency:');
[N,wn]=buttord(wp/pi,ws/pi,rp,rs);
[b,a]=butter(N,wn,'high');
freqz(b,a);
FIGURE:-
Magnitude(dB)
0
50
100
SAMPLE INPUT:-
150
200
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
Phase(degrees)
0
100
200
300
400
Enter
Enter
Enter
Enter
the
the
the
the
pass
stop
pass
stop
band
band
band
band
attenuation:0.4
attenuation:30
frequency:0.6*pi
frequency:0.2*pi
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
ALGORITHM:-
DEPT:ECE
JAFERKHAN.P
20
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
MATLAB CODE:-
clc;
clear all;
close all;
rp=input('enter the passband attenuation:');
rs=input('enter the stop band attenuation:');
wp=input('enter the pass band frequency:');
ws=input('enter the stop band frequency:');
[N,wn]=buttord(wp/pi,ws/pi,rp,rs);
[b,a]=butter(N,wn);
freqz(b,a);
FIGURE:-
Magnitude(dB)
0
50
100
150
200
250
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
Phase(degrees)
0
200
400
600
800
DEPT:ECE
JAFERKHAN.P
21
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
SAMPLE INPUT:enter
enter
enter
enter
the
the
the
the
passband attenuation:0.2
stop band attenuation:20
pass band frequency:[0.2*pi,0.4*pi]
stop band frequency: [0.1*pi,0.5*pi]
RESULTS:- Thus the Amplitude response and phase response of Butter worth band pass
filter was verified
ALGORITHM:DEPT:ECE
JAFERKHAN.P
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
22
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
MATLAB CODE:-
clc;
clear all;
close all;
rp=input('enter the passband attenuation:');
rs=input('enter the stop band attenuation:');
wp=input('enter the pass band frequency:');
ws=input('enter the stop band frequency:');
[N,wn]=buttord(wp/pi,ws/pi,rp,rs);
[b,a]=butter(N,wn,stop);
freqz(b,a);
FIGURE:-
Magnitude(dB)
100
0
100
200
300
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
Phase(degrees)
0
500
1000
1500
SAMPLE INPUT:enter
enter
enter
enter
the
the
the
the
passband attenuation:0.2
stop band attenuation:20
pass band frequency:[0.1*pi,0.5*pi]
stop band frequency:[0.2*pi,0.4*pi]
RESULTS:- Thus the Amplitude response and phase response of Butter worth band stop
filter was verified
DEPT:ECE
JAFERKHAN.P
23
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
DEPT:ECE
JAFERKHAN.P
Open MATLAB
Open new M-file
24
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
ALGORITHM:-
MATLAB CODE:-
clc;
clear all;
close all;
rp=input ('Enter the pass band attenuation:');
rs=input ('Enter the stop band attenuation:');
wp=input ('Enter the pass band frequency:');
ws=input ('Enter the stop band frequency:');
[N,wn]=cheb1ord(wp/pi,ws/pi,rp,rs);
[b,a]=cheby1(N,rp,wn);
freqz(b,a);
FIGURE:-
Magnitude(dB)
0
100
200
300
400
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
Phase(degrees)
0
100
200
300
400
500
SAMPLE INPUT:Enter
Enter
Enter
Enter
the
the
the
the
pass
stop
pass
stop
DEPT:ECE
JAFERKHAN.P
band
band
band
band
attenuation:20
attenuation:50
frequency:0.3*pi
frequency:0.4*pi
25
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
RESULTS:- Thus the Amplitude response and phase response of chebyshev type 1 Low
pass filter was verified
26
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
PROCEDURE:
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
ALGORITHM:-
MATLAB CODE:-
clc;
clear all;
close all;
rp=input ('Enter the pass band attenuation:');
rs=input ('Enter the stop band attenuation:');
wp=input ('Enter the pass band frequency:');
ws=input ('Enter the stop band frequency:');
[N,wn]=cheb1ord(wp/pi,ws/pi,rp,rs);
[b,a]=cheby1(N,rp,wn,'high');
freqz(b,a);
FIGURE:Magnitude(dB)
0
100
200
300
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
Phase(degrees)
100
0
100
200
300
400
DEPT:ECE
JAFERKHAN.P
27
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
SAMPLE INPUT:Enter
Enter
Enter
Enter
the
the
the
the
pass
stop
pass
stop
band
band
band
band
attenuation:20
attenuation:50
frequency:0.4*pi
frequency:0.3*pi
RESULTS:- Thus the Amplitude response and phase response of chebyshev type 1 high
pass filter was verified
28
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
AIM: - TO write a MATLAB program to plot magnitude response and phase response of digital
Chebyshev type-1 Band pass filter
PROCEDURE:
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
ALGORITHM:-
MATLAB CODE:-
clc;
clear all;
close all;
rp=input ('Enter the pass band attenuation:');
rs=input ('Enter the stop band attenuation:');
wp=input ('Enter the pass band frequency:');
ws=input ('Enter the stop band frequency:');
[N,wn]=cheb1ord(wp/pi,ws/pi,rp,rs);
[b,a]=cheby1(N,rp,wn);
freqz(b,a);
FIGURE:-
Magnitude(dB)
0
100
200
300
400
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
Phase(degrees)
0
200
400
600
800
DEPT:ECE
JAFERKHAN.P
29
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
SAMPLE INPUT:Enter
Enter
Enter
Enter
the
the
the
the
pass
stop
pass
stop
band
band
band
band
attenuation:20
attenuation:98
frequency:[0.3*pi,0.5*pi]
frequency:[0.1*pi,0.8*pi]
RESULTS:- Thus the Amplitude response and phase response of chebyshev type 1 band
pass filter was verified
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
ALGORITHM:-
MATLAB CODE:clc;
clear all;
close all;
rp=input('Enter the pass band attenuation:');
rs=input('Enter the stop band attenuation:');
wp=input('Enter the pass band frequency:');
ws=input('Enter the stop band frequency:');
DEPT:ECE
JAFERKHAN.P
30
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
[N,wn]=cheb1ord(wp/pi,ws/pi,rp,rs);
[b,a]=cheby1(N,rp,wn,'stop');
freqz(b,a);
FIGURE:-
Magnitude(dB)
SAMPLE INPUT:-
100
200
300
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
Phase(degrees)
0
200
the
the
the
the
pass
stop
pass
stop
band
band
band
band
attenuation:20
attenuation:98
frequency:[0.1*pi,0.8*pi]
frequency:[0.3*pi,0.5*pi]
400
600
800
Enter
Enter
Enter
Enter
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
31
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
ALGORITHM:-
MATLAB CODE:-
clc;
clear all;
close all;
rp=input ('Enter the pass band attenuation:');
rs=input ('Enter the stop band attenuation:');
wp=input ('Enter the pass band frequency:');
ws=input ('Enter the stop band frequency:');
[N,wn]=cheb2ord(wp/pi,ws/pi,rp,rs);
[b,a]=cheby2(N,rp,wn);
freqz(b,a);
FIGURE:-
Magnitude(dB)
0
20
40
60
80
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
Phase(degrees)
100
0
100
200
300
DEPT:ECE
JAFERKHAN.P
32
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
RESULTS:- Thus the Amplitude response and phase response of chebyshev type 2 Low
pass filter was verified
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
ALGORITHM:-
MATLAB CODE:-
clc;
clear all;
close all;
rp=input ('Enter the pass band attenuation:');
rs=input ('Enter the stop band attenuation:');
wp=input ('Enter the pass band frequency:');
ws=input ('Enter the stop band frequency:');
[N,wn]=cheb2ord(wp/pi,ws/pi,rp,rs);
[b,a]=cheby2(N,rp,wn,'high');
freqz(b,a);
DEPT:ECE
JAFERKHAN.P
33
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
FIGURE:Magnitude(dB)
0
20
40
60
80
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
Phase(degrees)
300
200
100
0
100
SAMPLE INPUT:Enter
Enter
Enter
Enter
the
the
the
the
pass
stop
pass
stop
band
band
band
band
attenuation:20
attenuation:70
frequency:0.4*pi
frequency:0.3*pi
RESULTS:- Thus the Amplitude response and phase response of chebyshev type 2 high
pass filter was verified
DEPT:ECE
JAFERKHAN.P
34
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
DIGITAL CHEBYSHEV(TYPE-2) BAND PASS FILTER
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
ALGORITHM:-
MATLAB CODE:clc;
clear all;
close all;
rp=input ('Enter the pass band attenuation:');
rs=input ('Enter the stop band attenuation:');
wp=input ('Enter the pass band frequency:');
ws=input ('Enter the stop band frequency:');
[N,wn]=cheb2ord(wp/pi,ws/pi,rp,rs);
[b,a]=cheby2(N,rp,wn);
freqz(b,a);
DEPT:ECE
JAFERKHAN.P
35
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
FIGURE:-
Magnitude(dB)
0
10
20
30
40
50
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
Phase(degrees)
200
100
0
100
200
SAMPLE INPUT:Enter
Enter
Enter
Enter
the
the
the
the
pass
stop
pass
stop
band
band
band
band
attenuation:2
attenuation:20
frequency:[0.3*pi,0.4*pi]
frequency:[0.1*pi,0.5*pi]
RESULTS:- Thus the Amplitude response and phase response of chebyshev type 2 band
pass filter was verified
DEPT:ECE
JAFERKHAN.P
36
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
ALGORITHM:-
MATLAB CODE:clc;
clear all;
close all;
rp=input('Enter the pass band attenuation:');
rs=input('Enter the stop band attenuation:');
wp=input('Enter the pass band frequency:');
ws=input('Enter the stop band frequency:');
[N,wn]=cheb2ord(wp/pi,ws/pi,rp,rs);
[b,a]=cheby2(N,rp,wn,'stop');
freqz(b,a);
DEPT:ECE
JAFERKHAN.P
37
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
FIGURE:-
Magnitude(dB)
0
10
20
30
40
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
Phase(degrees)
200
100
0
100
200
SAMPLE INPUT:Enter
Enter
Enter
Enter
the
the
the
the
pass
stop
pass
stop
band
band
band
band
attenuation:2
attenuation:20
frequency:[0.1*pi,0.5*pi]
frequency:[0.3*pi,0.4*pi]
RESULTS:- Thus the Amplitude response and phase response of chebyshev type 2 band
stop pass filter was verified
DEPT:ECE
JAFERKHAN.P
38
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
ALGORITHM:-
MATLAB CODE:clc;
clear all;
close all;
N=input('Enter the value of N:');
wc=input('Enter cutoff frequency:');
h=fir1(N,wc/pi,hanning(N+1));
freqz(h);
FIGURE:-
DEPT:ECE
JAFERKHAN.P
39
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
Magnitude(dB)
50
0
50
100
150
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
Phase(degrees)
0
500
1000
1500
2000
RESULTS:- Thus the magnitude response and phase response of fir Low pass filter using
hanning window
was verified.
FIR HIGHPASS FILTER USING HANNING WINDOW
Experiment No: - 09(b)
AIM: - TO write a MATLAB program to plot magnitude response and phase response of digital FIR
HP filter
using Hanning window
PROCEDURE:-
ALGORITHM:-
MATLAB CODE:-
DEPT:ECE
JAFERKHAN.P
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
40
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
clc;
clear all;
close all;
N=input('Enter the value of N:');
wc=input('Enter cutoff frequency:');
h=fir1(N,wc/pi,'high',hanning(N+1));
freqz(h);
FIGURE:-
Magnitude(dB)
50
0
50
100
150
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
Phase(degrees)
500
0
500
1000
1500
RESULTS:- Thus the magnitude response and phase response of fir High pass filter using
hanning window
was verified.
DEPT:ECE
JAFERKHAN.P
41
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
ALGORITHM:-
MATLAB CODE:clc;
clear all;
close all;
N=input('Enter the value of N:');
wc=input('Enter cutoff frequency:');
DEPT:ECE
JAFERKHAN.P
42
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
h=fir1(N,wc/pi,hanning(N+1));
freqz(h);
FIGURE:-
Magnitude(dB)
50
0
50
100
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
Phase(degrees)
500
0
500
1000
1500
RESULTS:- Thus the magnitude response and phase response of fir band pass filter using
hanning window
was verified.
ALGORITHM:-
DEPT:ECE
JAFERKHAN.P
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
43
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
MATLAB CODE:clc;
clear all;
close all;
N=input('Enter the value of N:');
wc=input('Enter cutoff frequency:');
h=fir1(N,wc/pi,stop,hanning(N+1));
freqz(h);
FIGURE:-
Magnitude(dB)
50
0
50
100
150
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
Phase(degrees)
0
500
1000
1500
DEPT:ECE
JAFERKHAN.P
44
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
RESULTS:- Thus the magnitude response and phase response of fir band stop filter using
hanning window
was verified.
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
ALGORITHM:-
DEPT:ECE
JAFERKHAN.P
45
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
MATLAB CODE:clc;
clear all;
close all;
N=input('Enter the value of N:');
wc=input('Enter cutoff frequency:');
h=fir1(N,wc/pi,hamming(N+1));
freqz(h);
FIGURE:-
Magnitude(dB)
50
0
50
100
150
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
Phase(degrees)
0
500
1000
1500
2000
RESULTS:- Thus the magnitude response and phase response of fir Low pass filter using
hamming window
was verified.
FIR HIGHPASS FILTER USING HAMMING WINDOW
Experiment No: - 10(b)
AIM: - TO write a MATLAB program to plot magnitude response and phase response of digital FIR
HP filter
using Hanning window
PROCEDURE:DEPT:ECE
JAFERKHAN.P
46
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
ALGORITHM:-
MATLAB CODE:clc;
clear all;
close all;
N=input('Enter the value of N:');
wc=input('Enter cutoff frequency:');
h=fir1(N,wc/pi,'high',hamming(N+1));
freqz(h);
FIGURE:-
Magnitude(dB)
50
0
50
100
150
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
Phase(degrees)
500
0
500
1000
1500
SAMPLE INPUT:DEPT:ECE
JAFERKHAN.P
47
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
RESULTS:- Thus the magnitude response and phase response of fir High pass filter using
hamming window
was verified.
FIR BAND PASS FILTER USING HAMMING WINDOW
Experiment No: - 10(c)
AIM: - TO write a MATLAB program to plot magnitude response and phase response of digital FIR
BP filter
using Hamming window
PROCEDURE:
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
ALGORITHM:-
MATLAB CODE:clc;
clear all;
close all;
N=input('Enter the value of N:');
wc=input('Enter cutoff frequency:');
h=fir1(N,wc/pi,hamming(N+1));
freqz(h);
FIGURE:-
DEPT:ECE
JAFERKHAN.P
48
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
Magnitude(dB)
50
100
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
Phase(degrees)
500
0
500
1000
1500
RESULTS:- Thus the magnitude response and phase response of fir band pass filter using
hamming window
was verified.
49
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
ALGORITHM:-
MATLAB CODE:clc;
clear all;
close all;
N=input('Enter the value of N:');
wc=input('Enter cutoff frequency:');
h=fir1(N,wc/pi,stop,hamming(N+1));
freqz(h);
FIGURE:-
Magnitude(dB)
50
100
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
Phase(degrees)
0
500
1000
1500
2000
DEPT:ECE
JAFERKHAN.P
50
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
RESULTS:- Thus the magnitude response and phase response of fir band stop filter using
hamming window
was verified.
FIR LOW PASS FILTER USING BLACKMAN WINDOW
Experiment No: - 11(a)
AIM: - TO write a MATLAB program to plot magnitude response and phase response of digital FIR
LP filter
using blackman window
PROCEDURE:
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
ALGORITHM:-
MATLAB CODE:clc;
clear all;
close all;
N=input('Enter the value of N:');
wc=input('Enter cutoff frequency:');
h=fir1(N,wc/pi,blackman(N+1));
freqz(h);
FIGURE:DEPT:ECE
JAFERKHAN.P
51
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
Magnitude(dB)
50
0
50
100
150
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
Phase(degrees)
0
500
1000
1500
2000
RESULTS:- Thus the magnitude response and phase response of fir Low pass filter using
blackman window
was verified.
DEPT:ECE
JAFERKHAN.P
52
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
FIR HIGHPASS FILTER USING BLACKMAN WINDOW
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
ALGORITHM:-
MATLAB CODE:clc;
clear all;
close all;
N=input('Enter the value of N:');
wc=input('Enter cutoff frequency:');
h=fir1(N,wc/pi,'high',blackman(N+1));
freqz(h);
FIGURE:-
DEPT:ECE
JAFERKHAN.P
53
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
Magnitude(dB)
50
0
50
100
150
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
Phase(degrees)
1000
0
1000
2000
RESULTS:- Thus the magnitude response and phase response of fir High pass filter using
blackman window
was verified.
FIR BAND PASS FILTER USING BLACKMAN WINDOW
Experiment No: - 11(c)
AIM: - TO write a MATLAB program to plot magnitude response and phase response of digital FIR
BP filter
using blackman window
PROCEDURE:
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
ALGORITHM:-
MATLAB CODE:DEPT:ECE
JAFERKHAN.P
54
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
clc;
clear all;
close all;
N=input('Enter the value of N:');
wc=input('Enter cutoff frequency:');
h=fir1(N,wc/pi,blackman(N+1));
freqz(h);
FIGURE:-
Magnitude(dB)
0
50
100
150
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
Phase(degrees)
1000
0
1000
2000
3000
RESULTS:- Thus the magnitude response and phase response of fir band pass filter using
blackman window
was verified.
DEPT:ECE
JAFERKHAN.P
55
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
ALGORITHM:-
MATLAB CODE:clc;
clear all;
close all;
N=input('Enter the value of N:');
wc=input('Enter cutoff frequency:');
h=fir1(N,wc/pi,stop,blackman(N+1));
freqz(h);
DEPT:ECE
JAFERKHAN.P
56
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
FIGURE:-
Magnitude(dB)
50
0
50
100
150
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
Phase(degrees)
0
1000
2000
3000
RESULTS:- Thus the magnitude response and phase response of fir band stop filter using
blackman window
was verified.
FIR LOW PASS FILTER USING RECTANGULAR WINDOW
Experiment No: - 12(a)
AIM: - TO write a MATLAB program to plot magnitude response and phase response of digital FIR
LP filter
using rectangular window
PROCEDURE:-
ALGORITHM:DEPT:ECE
JAFERKHAN.P
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
57
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
MATLAB CODE:clc;
clear all;
close all;
N=input('Enter the value of N:');
wc=input('Enter cutoff frequency:');
h=fir1(N,wc/pi,rectwin(N+1));
freqz(h);
FIGURE:-
Magnitude(dB)
50
0
50
100
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
Phase(degrees)
0
500
1000
1500
RESULTS:- Thus the magnitude response and phase response of fir Low pass filter using
rectangular window
was verified.
DEPT:ECE
JAFERKHAN.P
58
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
ALGORITHM:-
MATLAB CODE:-
DEPT:ECE
JAFERKHAN.P
59
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
clc;
clear all;
close all;
N=input('Enter the value of N:');
wc=input('Enter cutoff frequency:');
h=fir1(N,wc/pi,'high',rectwin(N+1));
freqz(h);
FIGURE:-
Magnitude(dB)
50
0
50
100
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
Phase(degrees)
500
0
500
1000
1500
RESULTS:- Thus the magnitude response and phase response of fir High pass filter using
rectangular window
was verified.
60
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
ALGORITHM:-
MATLAB CODE:clc;
clear all;
close all;
N=input('Enter the value of N:');
wc=input('Enter cutoff frequency:');
h=fir1(N,wc/pi,rectwin(N+1));
freqz(h);
FIGURE:
Magnitude(dB)
50
0
50
100
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
Phase(degrees)
500
0
500
1000
1500
SAMPLE INPUT:DEPT:ECE
JAFERKHAN.P
61
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
RESULTS:- Thus the magnitude response and phase response of fir band pass filter using
rectangular window
was verified.
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
ALGORITHM:-
DEPT:ECE
JAFERKHAN.P
62
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
MATLAB CODE:clc;
clear all;
close all;
N=input('Enter the value of N:');
wc=input('Enter cutoff frequency:');
h=fir1(N,wc/pi,stop,rectwin(N+1));
freqz(h);
FIGURE:
Magnitude(dB)
50
0
50
100
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
NormalizedFrequency(rad/sample)
0.9
Phase(degrees)
0
500
1000
1500
RESULTS:- Thus the magnitude response and phase response of fir band stop filter using
rectangular window
was verified.
DISCRETE FOURIER TRANSFORM
Experiment No: - 13
AIM: - TO write a MATLAB program to find the DFT of a sequence
DEPT:ECE
JAFERKHAN.P
63
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
PROCEDURE:
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
ALGORITHM:-
MATLAB CODE:clc;
clear all;
close all;
N=input('Enter the value of N');
x=input('Enter the input sequence X(n):');
t=0:N-1;
subplot(2,1,1);
stem(t,x);
xlabel('TIME');
ylabel('AMPLITUDE');
title('INPUT SIGNAL');
grid on;
y=fft(x,N)
subplot(2,1,2);
stem(t,y);
xlabel('TIME');
ylabel('AMPLITUDE');
title('OUTPUT SIGNAL');
grid on;
FIGURE:-
DEPT:ECE
JAFERKHAN.P
64
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
INPUTSIGNAL
AMPLITUDE
4
3
2
1
0
0.5
1.5
TIME
OUTPUTSIGNAL
2.5
0.5
1.5
TIME
2.5
AMPLITUDE
10
5
0
-2.0000 + 2.0000i
-2.0000
-2.0000 - 2.0000i
RESULTS:- Thus the program for dft is written using MATLAB and verified.
DEPT:ECE
JAFERKHAN.P
Open MATLAB
Open new M-file
Type the program
Save in current directory
65
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
ALGORITHM:-
MATLAB CODE:clc;
clear all;
close all;
N=input('Enter the value of N=');
y=input('Enter the sequence y[n]=');
t=0:N-1;
subplot(2,1,1);
stem(t,y);
xlabel('TIME');
ylabel('AMPLITUDE');
title('INPUT SIGNAL');
grid on;
x=ifft(y,N)
subplot(2,1,2);
stem(t,x);
xlabel('TIME');
ylabel('AMPLITUDE');
title('OUTPUT SIGNAL');
grid on;;
FIGURE:-
DEPT:ECE
JAFERKHAN.P
66
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
INPUTSIGNAL
AMPLITUDE
10
5
0
5
0.5
1.5
TIME
OUTPUTSIGNAL
2.5
0.5
1.5
TIME
2.5
AMPLITUDE
4
3
2
1
0
RESULTS:- Thus the program for idft is written using MATLAB and verified.
67
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
AIM: - TO write a MATLAB program to find the linear convolution of two sequence using
PROCEDURE:
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
ALGORITHM:-
MATLAB CODE:clc;
clear all;
close all;
x=input('Enter the sequence x(n):');
h=input('Enter the sequence h(n):');
l1=length(x);
l2=length(h);
x=[x,zeros(1,l2-1)];
h=[h,zeros(1,l1-1)];
l3=length(x);
c=0:l3-1;
subplot(3,1,1);
stem(c,x);
grid on;
xlabel('TIME');
ylabel('AMPLITUDE');
title('X(n)');
subplot(3,1,2);
stem(c,h);
xlabel('TIME');
DEPT:ECE
JAFERKHAN.P
68
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
ylabel('AMPLITUDE');
grid on;
title('h(n)');
q=fft(x,l3);
r=fft(h,l3);
s=(r).*q;
y=ifft(s,l3)
subplot(3,1,3);
stem(c,y);
xlabel('TIME');
ylabel('AMPLITUDE');
grid on;
title('y(n)');
FIGURE:X(n)
AMPLITUDE
3
2
1
0
0.5
1.5
2
h(n)
TIME
2.5
3.5
0.5
1.5
2
y(n)
TIME
2.5
3.5
0.5
1.5
2
TIME
2.5
3.5
AMPLITUDE
1
0.5
0
AMPLITUDE
6
4
2
0
3.0000
6.0000
5.0000
3.0000
RESULTS:- Thus the program for linear convolution using dft is written using MATLAB
and verified.
DEPT:ECE
JAFERKHAN.P
69
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
ALGORITHM:-
MATLAB CODE:clc;
clear all;
close all;
x=input('Enter the sequence x(n):');
h=input('Enter the sequence h(n):');
l1=length(x);
l2=length(h);
a=0:l1-1;
b=0:l2-1;
l3=max(l1,l2);
c=0:l3-1;
subplot(3,1,1);
stem(a,x);
grid on;
xlabel('TIME');
ylabel('AMPLITUDE');
title('X(n)');
subplot(3,1,2);
DEPT:ECE
JAFERKHAN.P
70
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
stem(b,h);
xlabel('TIME');
ylabel('AMPLITUDE');
grid on;
title('h(n)');
q=fft(x,l3);
r=fft(h,l3);
s=(r).*q;
t=ifft(s,l3)
subplot(3,1,3);
stem(c,t);
xlabel('TIME');
ylabel('AMPLITUDE');
grid on;
title('y(n)');
FIGURE:
X(n)
AMPLITUDE
3
2
1
0
0.2
0.4
0.6
0.8
AMPLITUDE
1.2
1.4
1.6
1.8
1
0
0.5
1.5
y(n)
TIME
2.5
0.5
1.5
TIME
2.5
10
AMPLITUDE
1
h(n)
TIME
5
0
10
10
RESULTS:- Thus the program for circular convolution using dft is written using MATLAB
and verified.
DEPT:ECE
JAFERKHAN.P
71
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
DEPT:ECE
JAFERKHAN.P
72
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
DEPT:ECE
JAFERKHAN.P
73
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
DEPT:ECE
JAFERKHAN.P
74
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
75
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
DEPT:ECE
JAFERKHAN.P
76
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
DEPT:ECE
JAFERKHAN.P
77
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
LINEAR CONVOLUTION
Experiment No: - 01
AIM: - TO write a C- program to find linear convolution of given two sequences
78
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
y[i]+=x[j]*h[i-j];
}
for(i=0;i<m+n-1;i++)
printf("%d \n",y[i]);
}
RESULTS:- Thus the C- Program for Linear convolution was written and the output was
verified
OUTPUT:4
10
20
35
56
70
76
73
60
36
DEPT:ECE
JAFERKHAN.P
79
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
GRAPH PROPERTY
OUTPUT PLOT
DEPT:ECE
JAFERKHAN.P
80
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
DEPT:ECE
JAFERKHAN.P
81
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
DEPT:ECE
JAFERKHAN.P
82
COLLEGE OF
ENGINEERING ,KOTTARAKKARA
DEPT:ECE
JAFERKHAN.P
83