19EC2208 Solution of Linear Constant Coefficient Difference Equations
19EC2208 Solution of Linear Constant Coefficient Difference Equations
No: 2000040230
Pre-lab Session In-Lab Session Post Lab session Viva Total Marks
work (15M) work (15M) work (10M) (10M) 50M
Remarks if any:
Objectives:
To find the impulse and step response of the system.
To test whether the given system is stable or not using the impulse response.
To assess the solution for a system described by linear constant coefficient
difference equations, with initial conditions for an arbitrary input sequences.
Requirements: Digital Computer with MATLAB software.
Basic theory: Difference Equations: An LTI system can also be described by a Nth
order linear constant Coefficient difference equation of the form
1
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Id. No: 2000040230
Examples:
(d) Develop Matlab codes for the above and compare with analytical results
Solution
(a) Impulse response using impz.m and filter.m functions
figure();
subplot(4,1,1);stem(n,s,'r','fill','LineWidth', 1.5);
xlabel('Time-index n---->');ylabel('Amplitude');
title('Input Impulse Sequence');grid on
axis([-2 21 -0.05 1.2]);
subplot(4,1,2);stem(n,h1,'r','fill','LineWidth', 1.5);
xlabel('Time-index n---->');ylabel('Amplitude');
title('Impulse Response using impz.m');grid on
axis([-2 21 min(h1) max(h1)+0.25]);
subplot(4,1,3);stem(n,h2,'b','fill','LineWidth', 1.5);
xlabel('Time-index n---->');ylabel('Amplitude');
title('Impulse Response using filter.m');grid on
axis([-2 21 min(h2) max(h2)+0.25]);
subplot(4,1,4);stem(n,ha,'k','fill','LineWidth', 1.5);
xlabel('Time-index n---->');ylabel('Amplitude');
title('Impulse Response Analytical Solution');grid on
axis([-2 21 min(ha) max(ha)+0.25]);
3
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Id. No: 2000040230
% Stability Test
% T = sum(abs(h1))
% T = sum(abs(h2))
T = sum(abs(ha))
if (T < 1000)
disp (' Stable ')
else
disp (' Unstable ')
end
4
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Id. No: 2000040230
ya = (1/2).^n + 2*n.*ones(size(n));
figure();
subplot(3,1,1);stem(n,s,'b','fill','LineWidth', 1.5);
xlabel('Time-index n---->');ylabel('Amplitude');
title('Step Sequence s[n]');grid on
axis([-2 21 -0.1 1.2]);
subplot(3,1,2);stem(n,ys,'r','fill','LineWidth', 1.5);
xlabel('Time-index n---->');ylabel('Amplitude');
title('Step Response ys[n]');grid on
5
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Id. No: 2000040230
subplot(3,1,3);stem(n,ya,'k','fill','LineWidth', 1.5);
xlabel('Time-index n---->');ylabel('Amplitude');
title('Step Response ya[n]');grid on
axis([-2 21 min(ya) max(ya)+1]);
(c) Case1: Analytical solution for the response of system with zero initial conditions for
an input sequence
6
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Id. No: 2000040230
figure();
subplot(3,1,1);stem(n,x,'b','fill','LineWidth', 1.5);
xlabel('Time-index n---->');ylabel('Amplitude');
title('Input Sequence');grid on
axis([-1 21 -0.1 1.2]);
subplot(3,1,2);stem(n,y,'m','fill','LineWidth', 1.5);
xlabel('Time-index n---->');ylabel('Amplitude');
title('Response of the System');grid on
7
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Id. No: 2000040230
y1 = (1/3)*(1/4).^n - 2*(1/2).^n+(8/3)*ones(size(n));
subplot(3,1,3);stem(n,y1,'b','fill','LineWidth', 1.5);
axis([-1 21 min(y1) max(y1)+0.5]);
xlabel('Time-index n---->');ylabel('Amplitude');
title('Response of the System (Analytical)');grid on
Case2: Analytical solution for the response of system with initial conditions
8
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Id. No: 2000040230
y = (1/3)*(1/4).^n+(1/2).^n+(2/3)*ones(1,21);
subplot(3,1,3);stem(n,y,'b','fill','LineWidth', 1.5);
axis([-2 22 min(y) max(y)+0.25]);
xlabel('Time-index n---->');ylabel('Amplitude');
title('Response of the System (Analytical)');grid on
9
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Id. No: 2000040230
Laboratory Exercise - 4
Exercise 1: Consider a LCCDE described by the equation
.
(a) Determine analytically Impulse Response of the system. Using this impulse response
test whether this system is stable or not.
Code:
clear; close all; clc;
format long;
b = [0.45 0.4]; a = [1, -0.4 -0.45];
% h = 2u[n]-(1/2)^n u[n]
figure();
subplot(4,1,1);stem(n,s,'r','fill','LineWidth', 1.5);
xlabel('Time-index n---->');ylabel('Amplitude');
title('Input Impulse Sequence');grid on
axis([-2 21 -0.05 1.2]);
subplot(4,1,2);stem(n,h1,'r','fill','LineWidth', 1.5);
xlabel('Time-index n---->');ylabel('Amplitude');
title('Impulse Response using impz.m');grid on
axis([-2 21 min(h1) max(h1)+0.25]);
subplot(4,1,3);stem(n,h2,'b','fill','LineWidth', 1.5);
xlabel('Time-index n---->');ylabel('Amplitude');
title('Impulse Response using filter.m');grid on
axis([-2 21 min(h2) max(h2)+0.25]);
% Stability Test
% T = sum(abs(h1))
% T = sum(abs(h2))
T = sum(abs(ha))
if (T < 1000)
disp (' Stable ')
else
disp (' Unstable ')
end
RESULT:
11
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Id. No: 2000040230
RESULT:
12
Digital Signal Processing Lab, Dept. of ECE, KL University, A.P., India. Id. No: 2000040230
(d) Develop Matlab codes for the above and compare with analytical results
Exercise 2: A linear and time-invariant system is described by the difference equation
(a) Using the impz.m and filter functions, compute and plot the impulse response of the
system over .
(b) Determine the stability of the system from this impulse response.
(c) If the input to this system is , determine
13