0% found this document useful (0 votes)
27 views6 pages

UE23EC251B-PDSP Exp 2

bu;brw[b

Uploaded by

rishabbafna20005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views6 pages

UE23EC251B-PDSP Exp 2

bu;brw[b

Uploaded by

rishabbafna20005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

P.E.S.

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

WITHOUT INBUILT FUNCTION

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

clc; %clears the console window


clear all;%deletes the user defined variable in variable browser
close all;%close the figure window

%a=[1 -0.25 -0.125]


%b=[1 0.5]
b=input('Enter the coefficients of x: ');
a=input('Enter the coefficients of y: ');

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

title('input sequence x[n]');


xlabel('n');
ylabel('x[n]');

y=[IC zeros(1,length(n)-N)];

for n=N+1:20 %loop runs length(n) times to find y(n)


sumx=0;sumy=0;

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

title('output sequence y[n]');

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:

Enter the coefficients of x: [1 0.5]


Enter the coefficients of y: [1 -0.25 -0.125]
Enter the initial conditions for y: [2 1]
y[n]=
Columns 1 through 13

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

0.0022 0.0011 0.0005 0.0003 0.0001 0.0001 0.0000 0 0 0

WITH INBUILT FUNCTION

%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

%y(-1)=1 and y(-2)=2 , (enter the values as [2 1])

clc; %clears the console window


clear all;%deletes the user defined variable in variable browser
close all;%close the figure window

%a=[1 -0.25 -0.125]


%b=[1 0.5]
b=input('Enter the coefficients of x: ');
a=input('Enter the coefficients of y: ');

M=length(b)-1;
N=length(a)-1;
IC=input('Enter the initial conditions for y: ');

%Initial conditions for transposed direct-form II filter


ic=filtic(b,a,flip(IC));
n=[0:20];%number of terms

%x[n]=u[n]-u[n-2]
x=[(n>=0)]-[(n>=2)];
y=filter(b, a, x, ic);

subplot(211);
stem(n,x);

title('input sequence x[n]');


xlabel('n');
ylabel('x[n]');

subplot(212);
stem(n,y);

title('output sequence y[n]');


xlabel('n');
ylabel('y[n]');
disp('y[n]=');
disp(y)

OUTPUT:

Enter the coefficients of x: [1 0.5]


Enter the coefficients of y: [1 -0.25 -0.125]
Enter the initial conditions for y: [2 1]

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

0.0005 0.0003 0.0001 0.0001 0.0000 0.0000 0.0000 0.0000

With zero initial conditions

Enter the coefficients of x: [1 0.5]


Enter the coefficients of y: [1 -0.25 -0.125]
Enter the initial conditions for y: [0 0]
y[n] yinbuilt[n]
0 0
0 0
1.0000 1.0000
1.7500 1.7500
1.0625 1.0625
0.4844 0.4844
0.2539 0.2539
0.1240 0.1240
0.0627 0.0627
0.0312 0.0312
0.0156 0.0156
0.0078 0.0078
0.0039 0.0039
0.0020 0.0020
0.0010 0.0010
0.0005 0.0005
0.0002 0.0002
0.0001 0.0001
0.0001 0.0001

24
P.E.S. UNIVERSITY
Department of Electronics and Communication Engineering
Session: Jan - May 2025

To find impulse response

x=double([n==0]);

IC =[0 0];

Impulse Response Output:


Enter the coefficients of x: [1 0.5]
Enter the coefficients of y: [1 -0.25 -0.125]
Enter the initial conditions for y: [0 0]
y[n] yinbuilt[n]
0 0
0 0
1.0000 1.0000
0.7500 0.7500
0.3125 0.3125
0.1719 0.1719
0.0820 0.0820
0.0420 0.0420
0.0208 0.0208
0.0104 0.0104
0.0052 0.0052
0.0026 0.0026
0.0013 0.0013
0.0007 0.0007
0.0003 0.0003
0.0002 0.0002
0.0001 0.0001

25
P.E.S. UNIVERSITY
Department of Electronics and Communication Engineering
Session: Jan - May 2025

26

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy