Professional Documents
Culture Documents
Experiment 10
Experiment 10
Examples-
1)
clear all;
close all;
clc;
n=20;
b=[5 0 0];
a=[1,-0.6,-0.16];
f=[1,zeros(1,n-1)];
y=filter(b,a,f);
k=0:1:n-1;
stem(k,y);
xlabel('n');
ylabel('x(n)');
title('impulse response');
impulse response
5
4.5
3.5
3
x(n)
2.5
1.5
0.5
0
0 2 4 6 8 10 12 14 16 18 20
n
2)
clear all;
close all;
clc;
b=[1 2];
a=[1 0.4 -0.12];
L=11;
[y,t]=impz(b,a,L);
stem(t,y);
xlabel('n');
ylabel('h(n)');
title('impulse response');
impulse response
2
1.5
1
h(n)
0.5
-0.5
-1
0 1 2 3 4 5 6 7 8 9 10
n
3)
clear all;
close all;
clc;
x=input('Enter the sequence');
N=input('Enter fft length');
X=fft(x,N);
subplot(2,1,1);
stem(x);
xlabel('n');
ylabel('x');
title('Input Signal');
subplot(2,1,2);
%n=0:1:7;
stem(X);
title('FFT of the signal');
Input Signal
4
2
x
0
1 1.5 2 2.5 3 3.5 4
n
FFT of the signal
10
-5
-10
1 2 3 4 5 6 7 8
4)
clear all;
close all;
clc;
b=[2 16 44 56 32];
a=[3 3 -15 18 -12];
[z p k]=tf2zp(b,a);
disp('Zeros:');
disp(z);
disp('Poles');
disp(p);
disp('Gain constant=');
disp(k);
disp('Radius of poles:');
disp(abs(p));
sos=zp2sos(z,p,k);
disp('Second order system');
disp(real(sos));
zplane(b,a);
2
1.5
0.5
Imaginary Part
-0.5
-1
-1.5
-2
5)
clear all;
close all;
clc;
y=dsolve('Dy=1-y','y(0)=0');
disp('y=');
disp(y);
Output-
y=
1 - exp(-t)\
EXERCISES-
1)
b=[8 2 -5 0];
a=[1 0 -1.75 0.75];
L=11;
[y,t]=impz(b,a,L);
stem(t,y);
xlabel('n');
ylabel('h(n)');
title('inverse z transform');
inverse z transform
120
100
80
60
40
h(n)
20
-20
-40
-60
-80
0 1 2 3 4 5 6 7 8 9 10
n
2)
clear all;
close all;
n=20;
a=[1 -1.5 ];
b=[0 0 1];
f=[1,zeros(1,n-1)];
y=filter(b,a,f);
k=0:1:n-1;
stem(k,y);
xlabel('h');
ylabel('x(n)');
title('impulse response');
impulse response
2
1.5
0.5
x(n)
-0.5
-1
-1.5
0 2 4 6 8 10 12 14 16 18 20
h
3)
clear all;
close all;
y=dsolve('D2y+(13*(y))+(4*(Dy))=0','Dy(0)=0','y(0)=1');
disp('y=');
disp(y);
Output-
y=
cos(3*t)*exp(-2*t) + (2*sin(3*t)*exp(-2*t))/3
4)
clear all;
close all;
n=20;
b=[0 0 1];
a=[1 -1 -2];
f=[1,zeros(1,n-1)];
y=filter(b,a,f);
k=0:1:n-1;
stem(k,y);
xlabel('n');
title('impulse response');
4
x 10 impulse response
9
0
0 2 4 6 8 10 12 14 16 18 20
n
5)
clear all;
close all;
n=0:21;
a=[1 0 0];
b=[1 -1 0];
u0=[(n)>=0];
u1=[(n)>=10];
u2=[(n)>=20];
u3=u0-u1;
u4=u1-u2;
u5=u0-u2;
x1=n.*u3+(20-n).*u4;
y1=filter(b,a,x1);
k=0:21;
subplot(2,2,1);
stem(k,y1);
x2=5*u5;
y2=filter(b,a,x2);
k=0:21;
subplot(2,2,2);
stem(k,y2);
1 5
0.5
0 0
-0.5
-1 -5
0 10 20 30 0 10 20 30
6)
n=0:25;
x=sin(2*pi*50*n);
N=20;
X=fft(x,N);
subplot(2,1,1);
stem(X);
subplot(2,1,2);
y=angle(X);
stem(y);
-12
x 10
2
-1
-2
0 2 4 6 8 10 12 14 16 18 20
-2
-4
0 2 4 6 8 10 12 14 16 18 20
7)
clear all;
close all;
n=0:25;
x=sin(2*pi*30*n)+sin(2*pi*80*n)+sin(2*pi*120*n);
X=fft(x,10);
subplot(2,1,1);
stem(x);
xlabel('n');
ylabel('x');
title('input signal');
subplot(2,1,2);
stem(X);
title('fft of signal');
-12
x 10 input signal
0
-2
-4
x
-6
-8
0 5 10 15 20 25 30
n
-12
x 10 fft of signal
4
-2
-4
1 2 3 4 5 6 7 8 9 10
8)
a)
clear all;
close all;
n=20;
b=[1 0.5 0];
a=[1 0.5 -0.25];
f=[1,zeros(1,n-1)];
y=filter(b,a,f);
k=0:1:n-1;
stem(k,y);
xlabel('n');
ylabel('n');
title('impule response');
impule response
1.2
0.8
0.6
n
0.4
0.2
-0.2
0 2 4 6 8 10 12 14 16 18 20
n
8) c)
clear all;
close all;
clc;
b=[2*(0.9) 2*0.5*0.9];
a=[1 0.5 -0.25];
[z p k]=tf2zp(b,a);
disp('Zeros:');
disp(z);
disp('Poles');
disp(p);
disp('Gain constant=');
disp(k);
disp('Radius of poles:');
disp(abs(p));
sos=zp2sos(z,p,k);
disp('Second order system');
disp(real(sos));
zplane(b,a);
1
0.8
0.6
0.4
Imaginary Part
0.2
-0.2
-0.4
-0.6
-0.8
-1
-1 -0.5 0 0.5 1
Real Part