In: Electrical Engineering
Consider the discrete-time LTI system characterized by the following difference equation with input and initial conditions specified: y[n] - 2 y[n-1] – 3 y[n-2] = x[n] , with y[0] = -1 and y[1] = 0, x[n] = (-1/2)n u[n-2]. ? Write a MATLAB program to simulate this difference equation. You may try the commands ‘filter’ or ‘filtic’ or create a loop to compute the values recursively. ? Printout and plot the values of the input signal, x[n] and the output signal, y[n] over the range 1 ? n ? 10. ? Solve this difference equation by hand using the classical method. ? Verify that the values of the output signal, y[n] produced by MATLAB are the same as those calculated by hand for the values of n = 2, 3, 4.
MATLAB PROGRAM :
clc;
clear all;
close all;
num =
1;
% Numerator of the Transfer Function (From Difference
Equation)
den = [1 -2
-3];
% Denominator of Transfer Function (From Difference Equation)
n = 0:10
;
% Choose as desired
x = (1/4)*(-1/2).^(n-2); %u[n] is 1 for
n>=2
subplot(121);
stem(n,x);
% Plotting Input Signal
xlabel(['Discrete in Time n']);
ylabel(['Discrete in Amplitu X[n]']);
title(['Input Signal']);
y = filter(num, den, x, filtic(num, den, [(2/3) (-7/9)], [0
0]));
% [(2/3) (-7/9)] reflects initial conditions y(-1)=2/3 ,y(-2)=-7/9
on Y and [0 0] those on X.
subplot(122);
stem(n,y);
% Plotting Output Signal
xlabel(['Discrete in Time n']);
ylabel(['Discrete in Amplitu Y[n]']);
title(['Output Signal']);
RESULTS :
HAND USING CLASSICAL METHOD :