# Operation of a Discrete time System

Demonstrates the operation of a discrete time system

## Initialize the Filter: Program memory : a and b Coefficients

a1=-1.2;a2=.9;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;
x=1;  % Read the input at time = 0


## Run The difference Equation

N=50;
figure(1)
% At each sampling instant repeat the following loop ('forever')
while(n<N)
% Calculate next value of output
y = -a1*y1 -a2*y2 + b0*x + b1*x1 + b2*x2;
stem(n,y,'markersize',6,'markerfacecolor','r');hold on
% Update Memory
y2=y1;y1=y;n=n+1;
% Read next value of input
x=0;
end
%
%
text('Interpreter','latex',...
'String',['$$H(z)=\frac{1}{(z^2 + ',num2str(a1),' z+',num2str(a2),')}$$'],...
'Position',[10,1],...
'FontSize',16);
text('Interpreter','latex',...
'String',['$$y(n)= - ',num2str(a1),' y(n-1) -',num2str(a2),'+x(n)$$'],...
'Position',[10,2],...
'FontSize',16);
%hold off; grid off
axis([0 N -3 3]);
title('Difference Equation, Transfer function and unit sample response','fontsize',13)
xlabel('time in samples, ''\itn''')