In: Physics
Section 1: Given a system y[n]-y[n-1]+y[n-2]=x[n] (refer to M3.2
on textbook)
In class, we analytically derived the solutions of second order
difference equations, including zero-input response, unit impulse
response, zero-state response and total response. The Matlab has
imbedded commands to do the same job. Get familiar with the
following commends, and use them to get (0≤n≤40)
a) unit impulse response and plot it
b) zero-input response and plot it, with initial conditions of
y[-1]=1 and y[-2]=2 c) zero-state response and plot it,
x[n]=2cos(2πn/6)u[n]
d) total response and plot it
inline
filter
filtic
stem
xlabel, ylabel
****** Matlab Code ********
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% finding ZIR and ZSR for discrete systems
H = tf([1 0 0],[1 -1 1],1); % given (or derived) transfer
function
n = 0:1:40; % time vector
imp = double(n==0); % impulse signal
b = 1;
a = [1 -1 1];
y = filter(b,a,imp); % impulse response
subplot(2,2,1);
stem(n,y);
title('Impulse response');
xlabel('n');
ylabel('Amplitude')
%%%%%%%% creating state space model for finding ZSR and ZIR
sys_ss = ss(H);
x0 = [1;2]; % initial conditions
[y1,n,x] = initial(sys_ss,x0,n); % ZIR
subplot(2,2,2);
stem(n,y1);
title('Zero Input response');
xlabel('n');
ylabel('Amplitude')
u = 2*cos(2*pi*n/6);
subplot(2,2,3);
y2 = lsim(sys_ss,u,n); % ZSR
stem(n,y2);
title('Zero State response');
xlabel('n');
ylabel('Amplitude')
subplot(2,2,4);
stem(n,y1+y2);
title('Total response');
xlabel('n');
ylabel('Amplitude')
**************************
Output::-