Contents
Demonstration of the operation of a Difference Equation
format compact;
N=25;n=0:N-1;
Different Inputs
xi=[1 zeros(1,N-1)];
Initialize the Filter: Program memory : a and b Coefficients
a1=-1.7;a2=.8;b0=1;b1=0;b2=0;
Initialize the Filter: data memory : Variable data, x and y
y1=0;y2=0;x1=0;x2=0;
Time starts
n=0;
Run The difference Equation
figure(1);plot(0,0);hold on;
grid on
fprintf('%s %s %s %s %s %s \n',' y ',' y1 ',' y2 ',' x ',' x1 ',' x2')
while(n<N)
x=xi(n+1);
y = -a1*y1 -a2*y2 + b0*x + b1*x1 + b2*x2;
fprintf('%10.3g %10.3g %10.3g %10.3g %10.3g %10.3g\n',y,y1,y2,x,x1,x2)
stem(n,y,'markersize',6,'markerfacecolor','r');drawnow;hold on;
y2=y1;y1=y;
n=n+1;
end
hold off
y y1 y2 x x1 x2
1 0 0 1 0 0
1.7 1 0 0 0 0
2.09 1.7 1 0 0 0
2.19 2.09 1.7 0 0 0
2.06 2.19 2.09 0 0 0
1.74 2.06 2.19 0 0 0
1.31 1.74 2.06 0 0 0
0.842 1.31 1.74 0 0 0
0.38 0.842 1.31 0 0 0
-0.0276 0.38 0.842 0 0 0
-0.351 -0.0276 0.38 0 0 0
-0.575 -0.351 -0.0276 0 0 0
-0.696 -0.575 -0.351 0 0 0
-0.724 -0.696 -0.575 0 0 0
-0.673 -0.724 -0.696 0 0 0
-0.566 -0.673 -0.724 0 0 0
-0.423 -0.566 -0.673 0 0 0
-0.267 -0.423 -0.566 0 0 0
-0.115 -0.267 -0.423 0 0 0
0.0181 -0.115 -0.267 0 0 0
0.123 0.0181 -0.115 0 0 0
0.194 0.123 0.0181 0 0 0
0.232 0.194 0.123 0 0 0
0.239 0.232 0.194 0 0 0
0.22 0.239 0.232 0 0 0