UE23EC251B-PDSP Exp 2
UE23EC251B-PDSP Exp 2
UNIVERSITY
Department of Electronics and Communication Engineering
Session: Jan - May 2025
EXPERIMENT No.2 : Program to solve difference equation and program to find the Impulse
response of the system
%y(n)-0.25y(n-1)-0.125y(n-2)=x(n)+0.5x(n-1)
%x(n)=u(n)-u(n-2)
%y(-1)=1 and y(-2)=2 (enter the values as [2 1])
M=length(b)-1;
N=length(a)-1;
IC=input('Enter the initial conditions for y: ');
n=[-N:20];%number of terms
%x[n]=u[n]-u[n-2]
x=[(n>=0)]-[(n>=2)];
subplot(211);
stem(n,x);
y=[IC zeros(1,length(n)-N)];
for k=0:M
sumx=sumx+(b(k+1)*x(n-k));
end
for k=1:N
sumy=sumy+(a(k+1)*y(n-k));
end
y(n)=sumx-sumy;
end
n=[-N:20];%number of terms
subplot(212);
stem(n,y);
21
P.E.S. UNIVERSITY
Department of Electronics and Communication Engineering
Session: Jan - May 2025
xlabel('n');
ylabel('y[n]');
disp('y[n]=');
disp(y)
OUTPUT:
2.0000 1.0000 1.5000 2.0000 1.1875 0.5469 0.2852 0.1396 0.0706 0.0351
0.0176 0.0088 0.0044
Columns 14 through 23
%y(n)-0.25y(n-1)-0.125y(n-2)=x(n)+0.5x(n-1)
%x(n)=u(n)-u(n-2)
22
P.E.S. UNIVERSITY
Department of Electronics and Communication Engineering
Session: Jan - May 2025
M=length(b)-1;
N=length(a)-1;
IC=input('Enter the initial conditions for y: ');
%x[n]=u[n]-u[n-2]
x=[(n>=0)]-[(n>=2)];
y=filter(b, a, x, ic);
subplot(211);
stem(n,x);
subplot(212);
stem(n,y);
OUTPUT:
y[n]=
Columns 1 through 13
1.5000 2.0000 1.1875 0.5469 0.2852 0.1396 0.0706 0.0351 0.0176 0.0088
0.0044 0.0022 0.0011
Columns 14 through 21
23
P.E.S. UNIVERSITY
Department of Electronics and Communication Engineering
Session: Jan - May 2025
24
P.E.S. UNIVERSITY
Department of Electronics and Communication Engineering
Session: Jan - May 2025
x=double([n==0]);
IC =[0 0];
25
P.E.S. UNIVERSITY
Department of Electronics and Communication Engineering
Session: Jan - May 2025
26