You are on page 1of 2

MATLAB Code Difference Equation For LTI System:

clc;
close all;
clear all;
a=[1 -1.143 0.4128];
b=[0.0675 0.1349 0.675];
x=zeros(1,50);
yi=[1 2];
zi=filtic(b,a,yi);
y=filter(b,a,x,zi);

% For Initial Condition Output


subplot(4,1,3);
stem(y);
xlabel('Time Index(n)');
ylabel('Amplitude(A)');
title('Output Due to Initial Condition');
grid on;
% For Unit Step Response
x1=ones(1,50);
y1=filter(b,a,x1);
subplot(4,1,1);
stem(y1);
xlabel('Time Index(n)');
ylabel('Amplitude(A)');
title('Unit Step Response');
grid on;

% For Output of Cosine Function


n=1:100;
x2=cos((1/10)*pi*n);
y2=filter(b,a,x2);
subplot(4,1,4);
stem(y2);
xlabel('Time Index(n)');
ylabel('Amplitude(A)');
title('Output Due to Cos(1/10)pi');
grid on;
% For Impulse Response
[h,t]=impz(b,a,100);
subplot(4,1,2);
stem([h,t]);
xlabel('Time Index(n)');
ylabel('Amplitude(A)');
title('Impulse Response');
grid on;
Result:

Fig.01: Simulation of Difference Equation for LTI system

You might also like