DSP Lab Manual New MLR15 PDF
DSP Lab Manual New MLR15 PDF
DSP Lab Manual New MLR15 PDF
Dundigal, hyderabad
LAB MANUAL
Digital Signal Processing
Department
Of
Electronics & Communication Engineering
MLR15
2
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
LIST OF EXPERIMENTNS
PART – A
PART – B
3
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
Experiment No: 1
Aim:-
: Generate various signals and sequences (Aperiodic), such as Unit Impulse, Unit Step,
Square, Saw Tooth, Triangular, Sinusoidal, Ramp, Sinc.
Equipment Required:-
1. MATLAB 8.6(2015b)
2. PC loaded with windows7 OS
Program:-
i. Generate Sinusoidal signal
clear all;
close all;
clc;
N = input('Enter the number of cycles ...:: ');
t = 0:0.05:N;
x = sin(2*pi*t);
subplot(1,2,1);
plot(t,x);
xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Sinusoidal');
subplot(1,2,2);
stem(t,x);
xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Sinusoidal');
OUTPUT
Enter the number cycles ...:: 2
4
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
of
ii. Generate Unit Impulse function
clc;
clear all;
close all;
disp('UNIT IMPULSE SIGNAL');
N=input('Enter Number of Samples: ');
n=-N:1:N;
x=[zeros(1,N) 1 zeros(1,N)];
stem(n,x);
xlabel('Time');
ylabel('Amplitude');
title('Impulse Response');
OUTPUT
UNIT IMPULSE SIGNAL
Enter Number of Samples: 5
5
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
clc;
clear all;
close all;
disp('UNIT STEP SIGNAL');
N=input(' Enter Number of Samples : ');
n=-N:1:N x=[zeros(1,N) 1 ones(1,N)]
stem(n,x);
xlabel('Time');
ylabel('Amplitude');
title('Unit Step Response');
OUTPUT
UNIT STEP SIGNAL
Enter Number of Samples: 6
6
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
clear all;
close all;
clc;
t = 0:25;
y = t;
subplot(1,2,1);
plot(t,y);
xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Ramp function');
7
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
subplot(1,2,2);
stem(t,y);
xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Ramp function');
OUTPUT
clear all;
close all;
clc;
t1 = 0:25;
t = [];
for i = 1:N,
t = [t,t1];
end;
8
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
subplot(2,1,1);
plot(t);
xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Sawtooth waveform');
subplot(2,1,2);
stem(t);
xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Sawtooth waveform');
OUTPUT
clear all;
close all;
clc;
9
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
t = [];
for i = 1:N,
t = [t,t1,t2,t3,t4];
end;
subplot(1,2,1);
plot(t);
xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Triangular waveform');
subplot(1,2,2);
stem(t);
xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Triangular waveform');
OUTPUT
close all;
clear all;
clc;
10
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
plot(t,y);
xlabel('time')
ylabel('amplitude')
subplot(2,1,2)
stem(t,y)
xlabel('time')
ylabel('amplitude')
OUTPUT
Enter the amplitude of the square wave A = 4
clear all;
close all;
clc;
t = -3:0.1:3;
x = sin(pi*t)./(pi*t);
11
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
subplot(1,2,1); plot(x);
xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Sinc function');
axis([0,100,-0.5,1.0]);
subplot(1,2,2); stem(x);
xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Sinc function');
axis([0,100,-0.5,1.0]);
OUTPUT
Result:-
Experiment No:2
Operations on signals and Sequences such as addition, Multiplication, scaling, Shifting,
folding, computation of energy and average power
Aim:-
12
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
Equipment Required:-
1. MATLAB 8.6(2015b)
2. PC loaded with windows7 OS
Program:-
clear all;
close all;
clc;
subplot(2,2,1);
stem(x);
xlabel('---->Time ');
ylabel('---->Amplitude ');
title('Input sequence 1');
subplot(2,2,2);
stem(y);
xlabel('---->Time ');
ylabel('---->Amplitude ');
title('Input sequence 2');
if M > N
z = x + [y,zeros(1,M-N)];
else
z = [x,zeros(1,N-M)] + y;
end;
subplot(2,2,3);
stem(z);
xlabel('---->Time ');
ylabel('---->Amplitude ');
title('Addition of sequences 1 and 2');
if M > N
13
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
a = x.*[y,zeros(1,M-N)];
else
a = [x,zeros(1,N-M)].*y;
end;
subplot(2,2,4);
stem(a);
xlabel('---->Time ');
ylabel('---->Amplitude ');
title('Multiplication of sequences 1 and 2');
OUTPUT
Enter sequence 1 :: [1 2 3 4 5 1 2 3 4 5 1 2 3 4 5]
Enter sequence 2 :: [5 6 7 8 9 9 8 7 6 5]
clear all;
close all;
14
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
clc;
subplot(2,1,2);
stem([0:k-1],s_scal);
xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Scaled Sequence');
OUTPUT
15
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
clear all;
close all;
clc;
if a == 0
subplot(2,1,1)
stem([0:m-1],s); xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Input Sequence');
subplot(2,1,2);
stem([0:m-1],s); xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Shifted Sequence');
elseif a > 0
subplot(2,1,1)
stem([0:m-1],s); xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Input Sequence');
subplot(2,1,2);
stem([0:m+a-1],[zeros(1,a),s]); xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Shifted Sequence');
else
subplot(2,1,1)
stem([0:m-1],s); xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Input Sequence');
subplot(2,1,2);
stem([a:m-1],[s,zeros(1,abs(a))]); xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Shifted Sequence');
end;
OUTPUT
16
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
17
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
clear all;
close all;
clc;
subplot(2,1,1)
stem([-m:m],[zeros(1,m),s,0]);
xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Input Sequence');
subplot(2,1,2);
stem([-m:m],[0,fliplr(s),zeros(1,m)]);
xlabel('---------> Time');
ylabel('---------> Amplitude');
title('folded Sequence');
OUTPUT
18
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
clear all;
close all;
clc;
M = length(tes);
sum = 0;
for i = 1:M,
sum = sum + tes(i)*tes(i);
end;
disp('Energy of the given sequence is ..... :: ');
Energy = sum
disp('Average Power of the given sequence is ..... :: ');
Average_power = sum/M
OUTPUT
Energy =
85
Average_power =
9.4444
clear all;
close all;
clc;
t = 0:0.01:2;
x = sin(2*pi*t);
y = square(2*pi*t);
19
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
M = length(x);
N = length(y);
subplot(4,1,1);
stem(x);
xlabel('---->Time ');
ylabel('---->Amplitude ');
title('Input signal 1');
subplot(4,1,2);
stem(y);
xlabel('---->Time ');
ylabel('---->Amplitude ');
title('Input signal 2');
if M > N
z = x + [y,zeros(1,M-N)];
else
z = [x,zeros(1,N-M)] + y;
end;
z = x + y;
subplot(4,1,3);
stem(z);
xlabel('---->Time ');
ylabel('---->Amplitude ');
title('Addition of signals 1 and 2');
if M > N
a = x.*[y,zeros(1,M-N)];
else
a = [x,zeros(1,N-M)].*y;
end;
a = x.*y;
subplot(4,1,4);
stem(a);
xlabel('---->Time ');
ylabel('---->Amplitude ');
title('Multiplication of signals 1 and 2');
OUTPUT
20
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
clear all;
close all;
clc;
t = 0:0.01:2;
s = sin(2*pi*t);
a = input('Enter the scaling Factor ...:: ');
m = length(s);
k = ceil(m/a);
s_scal = [];
for i = 1:m,
if mod(i,a) == 0
s_scal = [s_scal,s(i-1)];
end;
end;
subplot(2,1,1)
stem([0:m-1],s);
xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Input Sequence');
subplot(2,1,2);
stem([0:k-1],s_scal);
21
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Scaled Sequence');
OUTPUT
clear all;
close all;
clc;
t = 0:0.01:2;
s = sin(2*pi*t);
a = input('Enter the length to be shifted ...:: ');
m = length(s);
if a == 0
subplot(2,1,1)
stem([0:m-1],s); xlabel('---------> Time');
22
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
ylabel('---------> Amplitude');
title('Input Sequence');
subplot(2,1,2);
stem([0:m-1],s); xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Shifted Sequence');
elseif a > 0
subplot(2,1,1)
stem([0:m-1],s); xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Input Sequence');
subplot(2,1,2);
stem([0:m+a-1],[zeros(1,a),s]); xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Shifted Sequence');
else
subplot(2,1,1)
stem([0:m-1],s); xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Input Sequence');
subplot(2,1,2);
stem([a:m-1],[s,zeros(1,abs(a))]); xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Shifted Sequence');
end;
OUTPUT
23
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
clear all;
close all;
clc;
t = 0:0.01:2;
s = sin(2*pi*t);
m = length(s);
subplot(2,1,1)
stem([-m:m],[zeros(1,m),s,0]);
xlabel('---------> Time');
ylabel('---------> Amplitude');
title('Input Sequence');
subplot(2,1,2);
stem([-m:m],[0,fliplr(s),zeros(1,m)]);
xlabel('---------> Time');
ylabel('---------> Amplitude');
title('folded Sequence');
OUTPUT
24
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
clear all;
close all;
clc;
t = 0:0.01:4;
tes = cos(2*pi*t);
M = length(tes);
sum = 0;
for i = 1:M,
sum = sum + tes(i)*tes(i);
end;
disp('Energy of the given sequence is ..... :: ');
Energy = sum
disp('Average Power of the given sequence is ..... :: ');
Average_power = sum/M
OUTPUT
Energy =
201
25
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
Average_power =
0.5012
Result:-
Experiment No: 3
Convolution between Signals and sequences
Aim:-
: Verifying the Convolution between Signals and Sequences
Equipment Required:-
1. MATLAB 8.6(2015b)
2. PC loaded with windows7 OS
Program:-
clear all;
close all;
clc;
26
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
subplot(3,1,1);
stem(x);
subplot(3,1,2);
stem(h);
o=zeros(1,length(x)+length(h)-1);
for m=1:length(x),
for n=1:length(h),
y(m,n)=x(m)*h(n);
end;
end;
for n=1:length(x)+length(h)-1,
for i=1:length(x),
for j=1:length(h),
if(i+j==n+1)
o(n)=o(n) + y(i,j);
end;
end;
end;
end;
subplot(3,1,3);
stem(o);
27
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
OUTPUT
enter the seq1 :: [1 2 3 4 3 2 1]
enter the seq2 :: [4 3 2 1 2 3 4]
clear all;
close all;
clc;
subplot(3,1,1);
stem(x);
subplot(3,1,2);
stem(h);
28
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
o = conv(x,h);
subplot(3,1,3);
stem(o);
OUTPUT
clear all;
close all;
clc;
t = 1:10;
x = sin(t);
h = square(t);
subplot(3,1,1);
29
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
stem(x);
subplot(3,1,2);
stem(h);
o=zeros(1,length(x)+length(h)-1);
for m=1:length(x),
for n=1:length(h),
y(m,n)=x(m)*h(n);
end;
end;
for n=1:length(x)+length(h)-1,
for i=1:length(x),
for j=1:length(h),
if(i+j==n+1)
o(n)=o(n) + y(i,j);
end;
end;
end;
end;
subplot(3,1,3);
stem(o);
OUTPUT
>> x
x=
Columns 1 through 7
Columns 8 through 10
>> h
h=
1 1 1 -1 -1 -1 1 1 1 -1
30
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
>>
clear all;
close all;
clc;
t = 1:10;
x = sin(t);
h = square(t);
subplot(3,1,1);
stem(x);
subplot(3,1,2);
stem(h);
o = conv(x,h);
subplot(3,1,3);
31
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
stem(o);
OUTPUT
>> x
x=
Columns 1 through 7
Columns 8 through 10
>> h
h=
1 1 1 -1 -1 -1 1 1 1 -1
32
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
Result:-
33
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
Experiment No:4
Auto Correlation and Cross Correlation between Signals and sequences
Aim:-
: Auto Correlation and Cross Correlation between Signals and Sequences
Equipment Required:-
1. MATLAB 8.6(2015b)
2. PC loaded with windows7 OS
Program:-
clear all;
close all;
clc;
res = xcorr(a);
subplot(2,1,1);
stem(a);
xlabel('----> Samples');
ylabel('----> Amplitude');
title('Input Sequence');
subplot(2,1,2);
stem(res);
xlabel('----> Samples');
ylabel('----> Amplitude');
title('Output Sequence');
34
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
OUTPUT
clear all;
close all;
clc;
t = 0:0.01:2;
a = cos(2 * pi * t);
res = xcorr(a);
subplot(2,1,1);
35
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
plot(a);
xlabel('----> Samples');
ylabel('----> Amplitude');
title('Input Sequence');
subplot(2,1,2);
plot(res);
xlabel('----> Samples');
ylabel('----> Amplitude');
title('Output Sequence');
OUTPUT
clear all;
36
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
close all;
clc;
subplot(2,2,1);
stem(a);
xlabel('----> Samples');
ylabel('----> Amplitude');
title('Input Sequence(1)');
subplot(2,2,2);
stem(b);
xlabel('----> Samples');
ylabel('----> Amplitude');
title('Input Sequence(2)');
subplot(2,2,[3,4]);
stem(res);
xlabel('----> Samples');
ylabel('----> Amplitude');
title('Output Sequence');
OUTPUT
37
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
clear all;
close all;
clc;
t = 0:0.01:2;
a = cos(2 * pi * t);
b = sin(2 * pi * t);
res = xcorr(a,b);
subplot(2,2,1);
plot(a);
xlabel('----> Samples');
ylabel('----> Amplitude');
title('Input signal(1)');
subplot(2,2,2);
plot(b);
xlabel('----> Samples');
ylabel('----> Amplitude');
38
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
title('Input Signal(2)');
subplot(2,2,[3,4]);
plot(res);
xlabel('----> Samples');
ylabel('----> Amplitude');
title('Output Signal');
OUTPUT
39
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
Result:-
40
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
Experiment No: 5
Verification of Linearity and Time Invariance properties of a given Continuous/Discrete
System
Aim:-
: Verification of Linearity and Time Invariance properties of a given Continuous
/ Discrete system.
Equipment Required:-
1. MATLAB 8.6(2015b)
2. PC loaded with windows7 OS
Program:-
i. Linearity of a system
clear all;
close all;
clc;
n=0:0.01:2;
a= -3; b= 5;
x1=cos(2*pi*n);
x2=cos(3*pi*n);
x=a*x1+b*x2;
ic=[0 0];
num=[2.2403 2.4908 2.2403];
den=[1 -0.4 0.75];
y1=filter(num,den,x1,ic);
y2=filter(num,den,x2,ic);
y=filter(num,den,x,ic);
yt=a*y1+b*y2;
d=y-yt;
subplot(3,1,1), stem(n,y);
xlabel('---------> Time');
ylabel('-> Amplitude');
title('y = a*x1 + b*x2');
subplot(3,1,2), stem(n,yt);
41
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
xlabel('---------> Time');
ylabel('-> Amplitude');
title('yt = a*y1 + b*y2');
subplot(3,1,3), stem(n,d);
xlabel('---------> Time');
ylabel('-> Amplitude');
title('difference of y and yt');
OUTPUT
clear all;
close all;
clc;
n=0:0.05:4;
D=10;
x=cos(2*pi*n);
xd=[zeros(1,D) x];
42
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
y=filter(num,den,x,ic);
yd=filter(num,den,xd,ic);
d=y-yd(1+D:1+D);
subplot(3,1,1), stem(y);
xlabel('---------> Time');
ylabel('-> Amplitude'); title('y ');
subplot(3,1,2), stem(yd);
xlabel('---------> Time');
ylabel('-> Amplitude'); title('yd');
subplot(3,1,3), stem(d);
xlabel('---------> Time');
ylabel('-> Amplitude');
title('difference of y and yd');
OUTPUT
43
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
Result:-
Experiment No: 6
Sinusoidal signal generation through recursive function
AIM:
To Write the Matlab Program for sinusoidal signal generation through recursive
function
Equipment Required:-
1. MATLAB 8.6(2015b)
2. PC loaded with windows7 OS
PROGRAM:
A=3;
f0=50;
fs=2000;
t=0.1;
length=fs*t;
y=zeros(1,length);
impulse=zeros(1,length);
impulse(1)=1;
a1=-2*cos(2*pi*f0/fs);
a2=1;
b0=2*sin(2*pi*f0/fs);
y(1)=0;
y(2)=b0;
for i=3:length;
y(i)=b0*impulse(i)-a1*y(i-1)-a2*y(i-2);
end
plot(y);
xlabel('samples n');
ylabel('y(n)');
title('sinusoidal waveform');
grid
44
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
OUTPUT:-
Result:-
45
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
Experiment No: 7
AIM:
To Write a Matlab program for determining DFT and IDFT of the given sequence.
Equipment Required:-
1. MATLAB 8.6(2015b)
2. PC loaded with windows7 OS
PROGRAM:
%MATLAB program to determine DFT of the sequence and plot magnitude and
%phase response
clc;
clear all;
close all;
xn=input('enter the input sequence:');
N=input('enter the length of sequence:');
% To compute N-point DFT of the sequence xn
L=length(xn);
%Checking for the length of the DFT
if (N<L)
error('N must be >=L');
end;
x1=[xn zeros(1,N-L)];%Appending zeros
%Computation of TWIDDLE FACTORS
for k=0:1:N-1;
for n=0:1:N-1
p=exp(-1i*2*pi*n*k/N);
x2(k+1,n+1)=p;
end
46
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
end
xk=x1*x2;
magxk=abs(xk);
k=0:N-1;
subplot(2,2,[1 2]);
stem(k,xn);
grid;
title('INPUT SEQUENCE');
xlabel('time index--> k');
ylabel('amplitude-->');
subplot(2,2,3);
stem(k,magxk);
grid;
title('MAGNITUDE RESPONSE');
xlabel('time index, k');
ylabel('Magnitude in dB');
angxk=angle(xk);
subplot(2,2,4);
stem(k,angxk);
grid;
title('PHASE RESPONSE');
xlabel('time index, k');
ylabel('Phase angle in radians');
INPUTS:
OUTPUT WAVEFORMS:
47
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
Result:-
%MATLAB program to determine IDFT of the sequence and plot magnitude and phase
response
clc;
clear all;
close all;
xk=input('enter the input sequence:');
N=length(xk);
%Computation of TWIDDLE FACTORS
for n=0:1:N-1;
for k=0:1:N-1;
p=exp(1i*2*pi*n*k/N);
x(k+1,n+1)=p;
end
end
48
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
xn=(xk*x)/N;
magxn=abs(xn);
n=0:N-1;
subplot(2,1,1);
stem(n,magxn);
grid;
title('MAGNITUDE RESPONSE');
xlabel('time index, k');
ylabel('Magnitude in dB');
angxn=angle(xn);
subplot(2,1,2);
stem(n,angxn);
grid;
title('PHASE RESPONSE');
xlabel('time index, k');
ylabel('Phase angle in radians');
disp(xn);
INPUTS:
OUTPUT WAVEFORMS:
49
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
Result:-
Experiment No: 8
Frequency Response
50
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
AIM:
To Write a Matlab program to plot the frequency response (magnitude and phase
1. MATLAB 8.6(2015b)
2. PC loaded with windows7 OS
PROGRAM:
%MATLAB program to plot the frequency response (magnitude and phase response)
%of a given difference equation.
clc;
clear all;
b=input('Enter the numerator coefficients:');
a=input('Enter the denominator coefficients:');
[h,ph]=freqz(b,a);
subplot(2,1,1);
plot(ph/pi,abs(h));
grid;
xlabel('Normalised Frequency');
ylabel('Magnitude in dB');
title('Magnitude Response');
subplot(2,1,2);
plot(ph/pi,angle(h));
grid;
xlabel('Normalised Frequency');
ylabel('phase in radians');
title('Phase Response');
INPUTS:
51
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
OUTPUT WAVEFORMS:
Result:-
52
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
Experiment No: 9
Fast Fourier Transform
AIM:
To Write a Matlab program for determining FFT of the given Sequence.
Equipment Required:-
1. MATLAB 8.6(2015b)
2. PC loaded with windows7 OS
PROGRAM:
clc;
clear all;
close all;
x=input('enter input sequence:');
N= input('size of fft(e.g . 2,4,8,16,32):');
n=length(x);
p=log2(N);
Y=x;
Y=[Y, zeros(1, N - n)];
N2=N/2;
YY = -pi*sqrt(-1)/N2;
WW = exp(YY);
JJ = 0 : N2-1;
W=WW.^JJ;
for L = 1 : p-1
u=Y(:,1:N2);
v=Y(:,N2+1:N);
t=u+v;
S=W.*(u-v);
Y=[t ; S];
U=W(:,1:2:N2);
W=[U ;U];
N=N2;
N2=N2/2;
end;
u=Y(:,1);
v=Y(:,2);
Y=[u+v;u-v];
Y
53
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
subplot(2,2,[1,2])
stem(x);grid
title('input sequence x')
xlabel('n');
ylabel('Amplitude');
subplot(2,2,3)
stem(abs(Y));grid
title('Magnitude of FFT')
xlabel('N');
ylabel('Amplitude');
subplot (2,2,4)
stem(angle(Y));grid
title('phase of FFT')
xlabel('N');
ylabel('phase');
output:
INPUT:
enter input sequence:[1 2 3 4]
Y=
10.0000 + 0.0000i
-2.0000 + 2.0000i
-2.0000 + 0.0000i
-2.0000 - 2.0000i
OUTPUT WAVEFORMS:
54
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
(b) To Write a Matlab program for determining FFT of the given Sequence using predefined
function.
Equipment Required:-
1. MATLAB 8.6(2015b)
2. PC loaded with windows7 OS
PROGRAM:
clc;
clear all;
close all;
N=4;
m=4;
a=input('Enter the input sequence');
n=0:1:N-1;
subplot(2,2,1);
stem(n,a);
xlabel('Time Index n');
ylabel('Amplitude');
title(' input Sequence');
x=fft(a,m);
k=0:1:N-1;
subplot(2,2,2);
stem(k,abs(x));
ylabel('magnitude');
55
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
output:
56
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
Result:-
57
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
PART-B
58
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
Experiment No: 1
Power Spectrum
AIM:
To obtain power spectrum of given signal using MATLAB.
Equipment Required:-
1. MATLAB 8.6(2015b)
2. PC loaded with windows7 OS
PROGRAM:
59
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
OUTPUT WAVFORMS:
Result:-
60
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
Experiment No: 2
Fir Low pass Filter
AIM:
To Write a Matlab program of FIR Low pass filter using rectangular, Hanning
Hamming, Blackman and Kaiser Window.
.
Equipment Required:-
1. MATLAB 8.6(2015b)
2. PC loaded with windows7 OS
PROGRAM:
%MATLAB program of FIR Low pass filter using Hanning
%Hamming, Blackman and Kaiser window
clf;
wc=.5*pi;
N=25;
w=0:0.1:pi;
b=fir1(N,wc/pi,blackman(N+1));
h=freqz(b,1,w);
subplot(2,2,1)
plot(w/pi,abs(h))
grid;xlabel('normalised frequency');
ylabel('magnitude in dB')
title('FIR LPF USING BLACKMAN WINDOW')
b=fir1(N,wc/pi,hamming(N+1));
h=freqz(b,1,w);
subplot(2,2,2)
plot(w/pi,abs(h));
grid;
xlabel('normalised frequency');
ylabel('magnitude in dB')
title('FIR LPF USING HAMMING WINDOW')
b=fir1(N,wc/pi,hanning(N+1));
h=freqz(b,1,w);
subplot(2,2,3)
plot(w/pi,abs(h));
grid;
61
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
xlabel('normalised frequency');
ylabel('magnitude in dB')
title('FIR LPF USING HANNING WINDOW')
b=fir1(N,wc/pi,kaiser(N+1,3.5));
h=freqz(b,1,w);
subplot(2,2,4)
plot(w/pi,abs(h));
grid;
xlabel('normalised frequency');
ylabel('magnitude in dB')
title('FIR LPF USING KAISER WINDOW')
OUTPUT WAVEFORMS:
Result:-
62
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
63
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
AIM:
To Write a Matlab program of FIR High pass filter using rectangular, triangular and
Kaiser Window.
.
Equipment Required:-
1. MATLAB 8.6(2015b)
2. PC loaded with windows7 OS
PROGRAM:
64
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
ylabel('Gain in dB-->');
xlabel('(b) Normalized frequency-->');
INPUT:
OUTPUT WAVEFORM:
65
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
Result:-
66
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
Experiment No: 3
IIR LOWPASS FILTER
AIM:
To Design a Butterworth low pass filter for the given specifications using Matlab.
Equipment Required:-
1. MATLAB 8.6(2015b)
2. PC loaded with windows7 OS
PROGRAM:
clc;
clear all;
close all;
alphap=input('enter pass attenuation in db=');%passband attenuation in db
alphas=input('enter stopband attenuation in db=');% stopband attenuation in db
fp=input('enter passband frequency in hz='); % passband frequency in hz
fs=input('enter stopband frequency in hz='); % stopband frequency in hz
F=input('enter sampling frequency in hz='); % sampling frequency in hz
omp=2*fp/F; %frequency in radians
oms=2*fs/F;
%to find cutoff frequency and order of the filter
[n,wn]=buttord(omp,oms,alphap,alphas);
%system function of the filter
[b,a]=butter(n,wn);
w=0:0.01:pi;
[h,om]=freqz(b,a,w,'whole');
m=20*log10(abs(h));
an=angle(h);
subplot(1,2,1);
plot(om/pi,m);
grid;
xlabel('normalised frequency');
ylabel('gain in db');
title('magnitude response');
subplot(1,2,2);
plot(om/pi,an);
67
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
grid;
xlabel('normalised frequency');
ylabel('phase in radians');
title('phase response');
disp(b);
disp(a);
INPUTS:
enter pass attenuation in db=4
enter stopband attenuation in db=30
enter passband frequency in hz=400
enter stopband frequency in hz=800
enter sampling frequency in hz=2000
OUTPUT WAVEFORM:
Result:-
68
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
(b) To Design a Butterworth Band stop filter for the given specifications using Matlab.
%To design a Butterworth Band stop filter for the given specifications
clc;
clear all;
close all;
alphap=input('enter pass attenuation in db=');%passband attenuation in db
alphas=input('enter stopband attenuation in db=');% stopband attenuation in db
wp=[.1*pi .5*pi]; % passband frequency in rad
ws=[.2*pi .4*pi]; % stopband frequency in rad
%to find cutoff frequency and order of the filter
[n,wn]=buttord(wp/pi,ws/pi,alphap,alphas);
%system function of the filter
[b,a]=butter(n,wn,'stop');
w=0.1:0.01:pi;
[h,ph]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(1,2,1);
plot(ph/pi,m);
grid;
xlabel('normalised frequency');
ylabel('gain in db');
title('magnitude response');
subplot(1,2,2);
plot(ph/pi,an);
grid;
xlabel('normalised frequency');
ylabel('phase in rad');
title('phase response');
disp(b);
disp(a);
INPUTS:
69
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
OUTPUT WAVEFORMS:
Result:-
70
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
(c) To Design a Chebyshev-I low pass filter for the given specifications using Matlab.
71
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
INPUTS:
Result:-
72
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
AIM:
To Design a Butterworth high pass filter for the given specifications using Matlab
Equipment Required:-
1. MATLAB 8.6(2015b)
2. PC loaded with windows7 OS
PROGRAM:
a) To Design a Butterworth High pass filter for the given specifications using
Matlab.
73
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
[b,a]=butter(n,wn,'high');
w=0:0.01:pi;
[h,om]=freqz(b,a,w,'whole');
m=20*log10(abs(h));
an=angle(h);
subplot(1,2,1);
plot(om/pi,m);
grid;
xlabel('normalised frequency');
ylabel('gain in db');
title('magnitude response');
subplot(1,2,2);
plot(om/pi,an);
grid;
xlabel('normalised frequency');
ylabel('phase in radians');
title('phase response');
disp(b);
disp(a);
INPUTS:
OUTPUT WAVEFORMS:
74
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
Result:-
b) To Design a Butterworth Band pass filter for the given specifications using
Matlab.
%To design a Butterworth Band pass filter for the given specifications
clc;
clear all;
close all;
alphap=input('enter pass attenuation in db=');%passband attenuation in db
alphas=input('enter stopband attenuation in db=');% stopband attenuation in db
wp=[.2*pi .4*pi]; % passband frequency in rad
ws=[.1*pi .5*pi]; % stopband frequency in rad
%to find cutoff frequency and order of the filter
[n,wn]=buttord(wp/pi,ws/pi,alphap,alphas);
%system function of the filter
[b,a]=butter(n,wn);
w=0.1:0.01:pi;
75
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
[h,ph]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(1,2,1);
plot(ph/pi,m);
grid;
xlabel('normalised frequency');
ylabel('gain in db');
title('magnitude response');
subplot(1,2,2);
plot(ph/pi,an);
grid;
xlabel('normalised frequency');
ylabel('phase in rad');
title('phase response');
disp(b);
disp(a);
INPUTS:
76
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
Result:-
(c) To Design a Chebyshev-I High pass filter for the given specifications using Matlab.
77
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
clc;
clear all;
close all;
alphap=input('passband attenuation in db='); %passband attenuation in db
alphas=input('stopband attenuation in db=');% stopband attenuation in db
wp=.3*pi;% passband frequency in rad
ws=.2*pi;% stopband frequency in rad
%order and cutoff frequency of the filter
[n,wn]=cheb1ord(wp/pi,ws/pi,alphap,alphas);
%system function of the filter
[b,a]=cheby1(n,alphap,wn,'high');
w=0:0.01:pi;
[h,ph]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(1,2,1);
plot(ph/pi,m);
grid;
xlabel('normalised frequency');
ylabel('gain in db');
title('magnitude response');
subplot(1,2,2);
plot(ph/pi,an);
grid;
xlabel('normalised frequency');
ylabel('phase in rad');
title('phase response');
disp(b);
disp(a);
INPUTS:
78
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
Result:-
79
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
Experiment No:4
Aim:- To generate the sinusoidal signal using filtering for the following difference equation
y(n)+0.5y(n-1)-0.001y(n-2)= x(n)
Equipment Required:-
1. MATLAB 8.6(2015b)
2. PC loaded with windows7 OS
PROGRAM:
clc;
clear all;
close all;
n=0:0.2:20;
x=sin(2*pi*0.4*n);
b=input('enter the numenator coefficients:');
a=input('enter the denominator coefficients:');
y=filter(b,a,x);
subplot(2,2,1)
plot(n,x);
xlabel('time')
ylabel('amplitude')
title('input signal')
subplot(2,2,2)
stem(n,x);
xlabel('time')
ylabel('amplitude')
title('given signal in discrete form')
subplot(2,2,3)
plot(n,y);
xlabel('time')
ylabel('amplitude')
title('generated sinusoidal signal through filtering')
subplot(2,2,4);
stem(n,y);
xlabel('time')
ylabel('amplitude')
title('generated sinusoidal signal in discrete form');
80
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
output:
OUTPUT WAVEFORM:
Result:-
81
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
Experiment No: 5
DECIMATION PROCESS
AIM:
To Write a Matlab program for Down-sampling of a sinusoidal input sequence.
Equipment Required:-
1. MATLAB 8.6(2015b)
2. PC loaded with windows7 OS
The function decimate can be employed to reduce the sampling rate of an input signal vector
X by an integer factor M generating the output signal vector Y and is available with four
options:
(i)Y=decimate(X,M) : This function employs an eight-order Type 1 Chebyshev IIR Lowpass
filter by default and filters the input sequence in both directions to ensure zero-phase filtering.
(ii)Y=decimate(X,M,n) : This function utilizes an order-n Type 1 Chebyshev IIR Lowpass
filter where n should be less than 13 to avoid numerical stability.
(iii)Y=decimate(X,M,’fir’) : This function employs a 30- tap FIR lowpass filter which filters
the input only in the forward direction. The FIR filter is designed with stop edge at π/M using
the function fir1 of MATLAB.
(iv)Y=decimate(X,M,N,’fir’) : This function design and employs a length-N FIR lowpass
filter.
PROGRAM:
%MATLAB program of Down-Sampling by an integer factor
clc;
clear all;
close all;
N=input('Enter the length of output sequence=');
M=input('Enter the Down-Sampling factor=');
fo=input('Enter the input signal frequency=');
82
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
INPUTS:
OUTPUT WAVEFORM:
83
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
Result:-
subplot(211)
stem(0:120,x(1:121),'filled','markersize',3)
grid on
xlabel('Sample number')
ylabel ('Original')
subplot(212)
stem(0:30,y(1:31),'filled','markersize',3)
grid on
xlabel('Sample number')
ylabel ('Decimated')
OUTPUT WAVEFORM:
84
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
Result:-
85
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
INTERPOLATION PROCESS:
AIM:
To Write a Matlab program for Up-sampling of a sinusoidal input sequence.
Equipment Required:-
1. MATLAB 8.6(2015b)
2. PC loaded with windows7 OS
The signal processing toolbox of MATLAB includes three specific functions for sampling
rate alteration.These are decimate ,interp and resample.
The function interp can be employed to increase the sampling rate of an input signal vector
X by an integer factor L generating the output signal vector Y. It is available with three
options.
(i). Y = interp(X,L): In this function the default values of and N are respectively, 0.5
and 4.
(ii). Y = interp(X,L,N,alpha): In this function the bandedge of the input signal and
length N of the interpolation filter can be specified.
(iii). [Y,h] = interp(X,L,N,alpha): In this function the bandedge of the input signal and
length N of the interpolation filter can be specified. Also, In this function the output data
contains in addition to the interpolated output vector Y, the filter coefficients ‘h’.
PROGRAM:
%MATLAB program of Up-Sampling by an integer factor
clc;
close all;
N=input('Enter the length of input sequence=');
L=input('Enter the Up-Sampling factor=');
fo=input('Enter the input signal frequency=');
%Generate the input sinusoidal sequence
n=0:N-1;
X=sin(2*pi*fo*n);
%Generate the Up-Sampled sequence
Y=zeros(1,L*length(X));
Y([1:L:length(Y)])=X;
%Plot input and Up-Sampled sequences
subplot(2,1,1);
stem(n,X);
title('input sequence');
xlabel('Time Index,n');
ylabel('Amplitude');
86
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
subplot(2,1,2);
stem(n,Y(1:length(X)));
title(' Up-Sampled sequence');
xlabel('Time Index,n');
ylabel('Amplitude');
INPUTS:
OUTPUT WAVEFORMS:
Result:-
87
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
INPUT:
88
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
OUTPUTWAVEFORMS:
Result:-
89
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
clc;
close all;
L = input('Up-sampling factor = ');
N = input('enter number of samples :');
n = 0:N-1;
x = sin(2*pi*0.043*n);
y = interp(x,L);
subplot(2,1,1);
stem(n,x(1:N));
title('Input Sequence');
xlabel('Time index n');
ylabel('Amplitude');
subplot(2,1,2);
m = 0:(N*L)-1;
stem(m,y(1:N*L));
title('Output Sequence');
xlabel('Time index n');
ylabel('Amplitude');
output:-
Up-sampling factor = 3
enter number of samples :50
OUTPUTWAVEFORMS:
90
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
Result:-
Experiment No:6
INTERPOLATION/DECIMATION SAMPLING RATE CONVERTERS
AIM:
(a) To Write a MATLAB program of the sampling rate increase by a ratio of two positive
integers of a signal composed of two sinusoids with frequencies f1 and
f2.
Equipment Required:-
1. MATLAB 8.6(2015b)
2. PC loaded with windows7 OS
The function resample in MATLAB can be utilized to increase the sampling rate of an input
vector X by a ratio of two positive integers, L/M, generating an output vector Y. There are
five functions available with this resample function.
(i). Y = resample(X, L, M)
(ii). Y = resample(X, L,M,R)
(iii). Y = resample(X, L,M,R,beta)
(iv). Y = resample(X,L,M,h)
(v).[ Y,h] = resample(X,L,M)
PROGRAM:
%MATLAB program of sampling rate alteration by a ratio of two integers
91
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
clc;
close all;
N=input('Enter the length of input sequence=');
L=input('Enter the Up-Sampling factor=');
M=input('Enter the Down-Sampling factor=');
f1=input('Enter the input signal frequency of first sinusoid=');
f2=input('Enter the input signal frequency of second sinusoid=');
%Generate the input sinusoidal sequence
n=0:N-1;
X=sin(2*pi*f1*n)+sin(2*pi*f2*n);
%Generate the Resampled output sequence
Y = resample(X,L,M);
%Plot input and Resampled output sequences
subplot(2,1,1);
stem(n,X(1:N));
title('input sequence');
xlabel('Time Index,n');
ylabel('Amplitude');
subplot(2,1,2);
m=0:N*L-1;
stem(m,Y(1:N*L/M));
title(' resampled output sequence');
xlabel('Time Index,n');ylabel('Amplitude');
INPUTS:
Enter the length of input sequence=50
Enter the Up-Sampling factor=10
Enter the Down-Sampling factor=5
Enter the input signal frequency of first sinusoid=0.043
Enter the input signal frequency of second sinusoid=0.031
OUTPUT WAVEFORMS:
92
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
Result:-
AIM:
(b) To Write a MATLAB program to study sampling rate conversion by a rational factor
of two positive integers of a sinusoidal signal
Equipment Required:-
1. MATLAB 8.6(2015b)
2. PC loaded with windows7 OS
PROGRAM:
93
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
clc;
close all;
L = input('Enter Up-sampling factor :');
M = input('Enter Down-sampling factor :');
N = input('Enter number of samples :');
n = 0:N-1;
x = sin(2*pi*0.041*n);
y = resample(x,L,M);
subplot(2,1,1);
stem(n,x(1:N));
axis([0 29 -2.2 2.2]);
title('Input Sequence');
xlabel('Time index n');
ylabel('Amplitude');
subplot(2,1,2);
m = 0:(N*L/M)-1;
stem(m,y(1:N*L/M));
axis([0 (N*L/M)-1 -2.2 2.2]);
title('Output Sequence');
xlabel('Time index n');
ylabel('Amplitude');
output:
Enter Up-sampling factor :4
Enter Down-sampling factor :2
Enter number of samples :40
OUTPUT WAVEFORMS:
94
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
Result:-
95
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
Experiment No:7
Noise Removal
1. MATLAB 8.6(2015b)
2. PC loaded with windows7 OS
Procedure:-
1) Open MATLAB
2) Open new M-file
3) Type the program
4) Save in current directory
5) Compile and Run the program
6) For the output see command window\ Figure window
Program:
clc
close all
clear all
x= cos(2*pi*12*[0:0.001:1.23]);
[b a] = butter(2,[0.6 0.7],'bandpass');
filtered_noise = filter(b,a,randn(1, length(x)*2));
x = (x + 0.5*filtered_noise(500:500+length(x)-1))/length(x)*2;
figure
plot(x)
title('Noisy signal')
xlabel('Samples');
ylabel('Amplitude')
96
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
X_mags = abs(fft(x));
figure
plot(X_mags)
xlabel('DFT Bins')
ylabel('Magnitude')
num_bins = length(X_mags);
[b a] = butter(25, 0.3, 'low');
H = freqz(b,a, floor(num_bins/2));
hold on
figure
plot([0:1/(num_bins/2 -1):1], abs(H),'m');
x_filtered = filter(b,a,x);
%plot the filtered signal
figure
plot(x_filtered,'m')
title('Filtered Signal - Using Second Order Butterworth')
xlabel('Samples');
ylabel('Amplitude')
97
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
Output:
Result:-
98
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
Experiment No:8
Impulse response of first order and second order systems
AIM:
To find the impulse response of first order system by using MATLAB.
Equipment Required:-
1. MATLAB 8.6(2015b)
2. PC loaded with windows7 OS
PROGRAM:
clc;
close all;
n=0:10;
b=[1 0 0];
a=[1 -0.6];
y=impz(b,a,length(n));
subplot(2,2,1);
stem(n,y);
xlabel('t');
ylabel('a')
title('impulse response of first order system');
w=abs(y);
subplot(2,2,2);
stem(n,w);
xlabel('t');
ylabel('a');
title('magnitude response');
x=angle(y);
subplot(2,2,3);
stem(n,x);
xlabel('t');
ylabel('a');
title ('phase response');
99
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
OUTPUT WAVEFORMS:
Result:-
100
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
(a) . To find the impulse response of second order system by using Matlab.
AIM:
To find the impulse response of second order system by using MATLAB.
Equipment Required:-
1. MATLAB 8.6(2015b)
2. PC loaded with windows7 OS
PROGRAM:
clc;
close all;
n=0:10;
b=[1 0 0];
a=[1 -0.6 0.08];
y=impz(b,a,length(n));
subplot(2,2,1);
stem(n,y);
xlabel('t');
ylabel('a');
title('impulse response of second order system');
w=abs(y);
subplot(2,2,2);
stem(n,w);
xlabel('t');
ylabel('a');
title('magnitude response');
x=angle(y);
subplot(2,2,3);
stem(n,x);
101
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
xlabel('t');
ylabel('a');
title ('phase response');
OUTPUT WAVEFORMS:
Result:-
102
MLR INSTITUTE OF TECHNOLOGY
Dundigal, hyderabad.
103