0% found this document useful (0 votes)
71 views

2019ee76 - LAB4 DSP

The document describes tasks from a lab experiment on properties of linear time-invariant (LTI) systems. Task 1 verifies commutativity of LTI systems using MATLAB and shows the input, impulse response, and outputs. Task 2 verifies associativity using different impulse responses. Task 3 checks for causality of impulse responses. Task 4 checks if impulse responses are bounded input bounded output stable. Task 5 computes correlation between signals using a custom function. The highest correlation occurs at a lag of 5 samples, matching the delay between the signals.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views

2019ee76 - LAB4 DSP

The document describes tasks from a lab experiment on properties of linear time-invariant (LTI) systems. Task 1 verifies commutativity of LTI systems using MATLAB and shows the input, impulse response, and outputs. Task 2 verifies associativity using different impulse responses. Task 3 checks for causality of impulse responses. Task 4 checks if impulse responses are bounded input bounded output stable. Task 5 computes correlation between signals using a custom function. The highest correlation occurs at a lag of 5 samples, matching the delay between the signals.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Regd. No.

: 2019 – EE – 076 Name: M Hassan Bashir Section: B

LAB 4

Properties of LTI Systems – II

Instructions:

 All tasks must be completed in this lab session for full credit.
 Students must show the output and MATLAB code for each task to the instructor
before proceeding to the next task.

References:

1. Digital Signal Processing using MATLAB: A problem solving companion, Vinay K.


Ingle and John G. Proakis, 4th Edition, Cengage Learning, 2016
2. Discrete Time Signal Processing, Alan. V. Oppenheim and Ronald. W. Schafer, 3rd
Edition, Prentice Hall, 2010
3. Digital Signal Processing: Principles, Algorithms, and Applications, John G.
Proakis and Dimitris G. Manolakis, 4th Edition, Prentice Hall, 2007

1. IMPLEMENTATION OF LTI SYSTEMS IN MATLAB

Task 1

Write a MATLAB script file to verify the commutativity for an LTI systems having impulse response ℎ[𝑛] =
0.2𝑛𝑢[𝑛 − 2], 0 ≤ 𝑛 ≤ 10. Follow the steps given below to complete this task.

 Initialize the input sequence 𝑥[𝑛] = 𝑢[𝑛 + 3] − 𝑢[𝑛 − 5].


 Compute the responses 𝑦1[𝑛] = 𝑥[𝑛] ∗ ℎ[𝑛] and 𝑦2[𝑛] = ℎ[𝑛] ∗ 𝑥[𝑛] using the function conv_m.m.
 Plot the sequences (using the stem command) 𝑦1[𝑛] and 𝑦2[𝑛] on the same figure window.
How does 𝑦1[𝑛] relate to 𝑦2[𝑛] and what does it imply?
x = [1,1,1,1,1,1,1,1,0,0,0,0,0,0];
nx = [-3:10];
h = [0,0,0,0,0,0.2^2,0.2^3,0.2^4,0.2^5,0.2^6,0.2^7,0.2^8,0.2^9,0.2^10];
nh = [-3:10];
[y_1, n_1] = conv_m(x, nx, h, nx);
[y_2, n_2] = conv_m(h, nh, x, nx);
subplot(2,2,1); stem(nx, x);
title('Input Signal')
xlabel('n'); ylabel('x[n]');

subplot(2,2,2); stem(nh, h);


title('Impulse Response')
xlabel('n'); ylabel('h[n]');
subplot(2,2,3); stem(n_1, y_1);
title('y1[n] = x[n]*h[n]')
xlabel('n_1'); ylabel('y_1[n]');
subplot(2,2,4); stem(n_2, y_2);
title('y2[n] = h[n]*x[n]')
xlabel('n_2'); ylabel('y_2[n]');

Task 2
Write a MATLAB script file to verify the associative law for the LTI systems having impulse response ℎ1[𝑛] =
0.2𝑛𝑢[𝑛], 0 ≤ 𝑛 ≤ 10 and ℎ2[𝑛] = 𝑢[𝑛 − 1] − 𝑢[𝑛 + 3]. Follow the steps given below to complete this task.

 Initialize the input sequence 𝑥[𝑛] = 𝑢[𝑛 + 3] − 𝑢[𝑛 − 5].


 Compute the response 𝑦1[𝑛] = 𝑥[𝑛] ∗ (ℎ1[𝑛] ∗ ℎ2[𝑛]) using the function conv_m.m.
 Compute the response 𝑦2[𝑛] = (𝑥[𝑛] ∗ ℎ1[𝑛]) ∗ ℎ2[𝑛] using the function conv_m.m.
 Plot the sequences (using the stem command) 𝑦1[𝑛] and 𝑦2[𝑛] on the same figure window.
Draw block diagrams showing the functional relation between 𝑥[𝑛], ℎ1[𝑛], ℎ2[𝑛], 𝑦1[𝑛] and 𝑦2[𝑛].

x = [1,1,1,1,1,1,1,1,0,0,0,0,0,0];
n = [-3:10];
h1 = [0,0,0,1,0.2^1,0.2^2,0.2^3,0.2^4,0.2^5,0.2^6,0.2^7,0.2^8,0.2^9,0.2^10];
h2 = [-1,-1,-1,-1,1,1,1,1,1,1,1,1,1,1,];
[y_d1, n_d1] = conv_m(h1, n, h2, n);
[y_1, n_1] = conv_m(x, n, y_d1, n_d1);
[y_d2, n_d2] = conv_m(x, n, h1, n);
[y_2, n_2] = conv_m(y_d2, n_d2, h2, n);
subplot(2,1,1); stem(n_1, y_1);
title('y1[n] = x[n]*(h1[n]*h2[n])')
xlabel('n_1'); ylabel('y_1[n]');
subplot(2,1,2); stem(n_2, y_2);
5
title('y2[n] = (x[n]*h1[n])*h2[n]')
xlabel('n_2'); ylabel('y_2[n]');

2.1 CAUSALITY AND STABILITY OF LTI SYSTEMS


 An LTI system is said to be causal if its impulse response is zero for negative time instants, i.e.,

ℎ[𝑛] = 0, 𝑛 < 0.

 An LTI system is said to be stable, in the bounded input-bounded output (BIBO) sense, if its impulse
response is absolutely summable, i.e.,

∑ |ℎ[𝑛]| ≤ 𝑀ℎ < ∞,

where 𝑀ℎ is the upper bound on the absolute summation of the impulse response. It can be observed that
the impulse response sequence of BIBO stable systems is a decaying sequence, i.e., ℎ[𝑛] → 0 as 𝑛 →
∞.

Task 3
Write a MATLAB function, using if-else control statements, that takes impulse response as its input and outputs
1 (when the system is causal) and 0 (otherwise). Call the function with the impulse responses defined in tasks 1
and 2 to find out which are causal. Record your observation below.
6
function [status] = causality_check (x, n)
%
%
% --------------------------------------------------------------
d = 0;
for i = 1:length(n)
if n(i) < 0
d = d + x(i);
end
end
if d == 0
status = 1;
else
status = 0;
end

h1 = [0,0,0,0,0,0.2^2,0.2^3,0.2^4,0.2^5,0.2^6,0.2^7,0.2^8,0.2^9,0.2^10];
n1 = [-3:10];
n23 = [-3:10];
h2 = [0,0,0,1,0.2^1,0.2^2,0.2^3,0.2^4,0.2^5,0.2^6,0.2^7,0.2^8,0.2^9,0.2^10];
h3 = [-1,-1,-1,-1,1,1,1,1,1,1,1,1,1,1,];
x1 = causality_check (h1, n1)
x2 = causality_check (h2, n23)
x3 = causality_check (h3, n23)

Task 4
Find whether the three impulse response sequences, defined in Tasks 1 and 2, are BIBO stable or not ? Justify
your answer through MATLAB by writing a one statement code.
h1 = [0,0,0,0,0,0.2^2,0.2^3,0.2^4,0.2^5,0.2^6,0.2^7,0.2^8,0.2^9,0.2^10];
n1 = [-3:10];
n23 = [-3:10];
h2 = [0,0,0,1,0.2^1,0.2^2,0.2^3,0.2^4,0.2^5,0.2^6,0.2^7,0.2^8,0.2^9,0.2^10];
h3 = [-1,-1,-1,-1,1,1,1,1,1,1,1,1,1,1,];
x1 = isstable (h1)
x2 = isstable (h2)
x3 = isstable (h3)

7
2.1 CORRELATION OF SEQUENCES
An operation that is closely related to the discrete convolution of two sequences is the correlation of two
sequences, which is a measure of similarity of the sequences. Given two real-valued sequences 𝑥[𝑛] and 𝑦[𝑛] of
finite energy, the cross-correlation of 𝑥[𝑛] and 𝑦[𝑛]is a sequence 𝑟𝑥𝑦[𝑙] defined as

𝑟𝑥𝑦[𝑙] = ∑ 𝑥[𝑛] 𝑦[𝑛 − 𝑙] = 𝑥[𝑛] ∗ 𝑦[−𝑛],


where ∗ represents the linear convolution sum and the index 𝑙 is called the shift or lag parameter. The special
case of correlation, when 𝑦[𝑛] = 𝑥[𝑛], is called autocorrelation and is defined by

𝑟𝑥𝑥(𝑙) = ∑ 𝑥[𝑛] 𝑥[𝑛 − 𝑙] = 𝑥[𝑛] ∗ 𝑥[−𝑛].


𝑛=−∞

It provides a measure of self-similarity between different alignments of the sequence. MATLAB functions xcorr
and to compute auto- and cross-correlations for sequences In its simplest form,

>> xcorr(x,y)

computes the cross-correlation between vectors x and y, while

>> xcorr(x)

8
computes the autocorrelation of vector x. However, like the conv function, the xcorr function cannot provide the
timing (or lag) information, which then must be obtained in a similar manner that was used to obtain the timing
information for the convolution of two sequences.

Task 5

 Write a function my_corr.m to find the correlation of two sequences 𝑥[𝑛] and 𝑦[𝑛], where 𝑥[𝑛] is the
input and 𝑦[𝑛] = 𝑥[𝑛 − 5] + 𝑤[𝑛], in which 𝑤[𝑛] is a zero-mean, unit-variance Gaussian noise signal.
 Verify its output by writing a MATLAB script file named my_corr_check.m, in which define the input
sequence 𝑥[𝑛] = {−2, −1, 0, 1, 2} and the Gaussian noise sequence by the following piece of code

w = randn(1, length(x));
nw = nx;

 Call the function my_corr in the script file and write commands to plot the signals 𝑥[𝑛], 𝑤[𝑛] and 𝑦[𝑛].
The signals must be plotted on a single figure window using the stem command.
 For your convenience, structure of the function my_corr is given below.

function [rxy, l] = my_corr (x, nx, y, ny)


% Implements y[n] = x1[n] ∗ x2[-n]
%
% [rxy, l] = my_corr (x, nx, y, ny)
% [rxy, l] = result of correlation
% [x, nx] = first signal
% [y, ny] = second signal
%
%
%
% Write your code here to generate rxy from x and w.
%
What value of the lag parameter shows the highest correlation between the signals and why ?
function [rxy, l] = my_corr (x, nx, y, ny)
% Implements y[n] = x1[n] ? x2[-n]
% ------------------------------------
% [rxy, l] = my_corr (x, nx, y, ny)
% [rxy, l] = result of correlation
% [x, nx] = first signal
% [y, ny] = second signal
%
%
% --------------------------------------------------------------
[x_fold, n_fold] = sigfold(y,ny);
nyb = nx(1)+n_fold(1); nye = nx(length(x)) + n_fold(length(x_fold));
l = [nyb:nye];
rxy = conv(x,x_fold);

x = [-2:2];
nx = [-2:2];
w = randn(1, length(x));
nw = nx;
[x_delay, n_delay] = sigshift(x,nx,5);
[y,ny] = sigadd(x_delay,n_delay,w,nw);
9
[r_xy, n_xy] = my_corr(x,nx,y,ny);
subplot(3,1,1); stem(nx, x);
title('1st Input Signal')
xlabel('nx'); ylabel('x[n]');
subplot(3,1,2); stem(ny, y);
title('2nd Input Signal')
xlabel('ny'); ylabel('y[n]');
subplot(3,1,3); stem(n_xy, r_xy);
title('Correlaion Output')
xlabel('n_xy'); ylabel('r_xy[n]');

2. LINEAR CONSTANT COEFFICIENT DIFFERENCE EQUATIONS

A discrete causal LTI system can also be described by a linear constant coefficient difference equation of the
form
𝑁 𝑀

∑ 𝑎𝑘𝑦[𝑛 − 𝑘] = ∑ 𝑏𝑘𝑥[𝑛 − 𝑘], ∀ 𝑛. (4.1)


𝑘=0 𝑘=0

If 𝑎𝑁 ≠ 0, then the difference equation is of order 𝑁. This equation describes a recursive approach for
computing the current output, given the input values and previously computed output values. In practice, this
the equation is computed forward in time, from 𝑛 = −∞ to 𝑛 = ∞. Therefore, another form of this equation is
𝑁 𝑀

𝑦[𝑛] = − ∑ 𝑎𝑘𝑦[𝑛 − 𝑘] + ∑ 𝑏𝑘𝑥[𝑛 − 𝑘], ∀ 𝑛. (4.2)


𝑘=1 𝑘=0

A solution to this equation can be obtained in the form

1
0
𝑦[𝑛] = 𝑦𝑝[𝑛] + 𝑦ℎ[𝑛],

where 𝑦𝑝[𝑛] and 𝑦ℎ[𝑛] are called particular and homogeneous solutions respectively. The homogeneous
solution is given by
𝑁

𝑦ℎ[𝑛] = ∑ 𝐶𝑘𝜆𝑛𝑘
𝑘=1

where 𝜆𝑘, 𝑘 = 1,2, … , 𝑁 are the 𝑁 roots of the characteristic polynomial of the system, given by
∑ 𝑎𝑘𝜆𝑁−𝑘 = 0.
𝑘=0

This characteristic polynomial is important in determining the stability of system. If the roots 𝜆𝑘 satisfy the
condition

|𝜆𝑘| < 1, 𝑘 = 1,2, … , 𝑁,

then a causal system described by the linear constant-coefficient difference equation in (4.2) is stable. The
particular solution, 𝑦𝑝[𝑛], is determined from the right-hand side of (4.1).

2.1 MATLAB IMPLEMENTATION


A function called filter is available to solve difference equations numerically, given the input and the difference
equation coefficients. In its simplest form, this function is invoked by

>> y = filter (b, a, x)

where

b = [b0, b1, ..., bM];


a = [a0, a1, ..., aN];

are the coefficient arrays from the equation given in (4.1) and x is the input sequence array. The output y has the
same length as input x. One must ensure that the coefficient a0 is not zero. To compute and plot impulse
response, MATLAB provides the function impz. When invoked by

>> h = impz (b, a, n);

it computes samples of the impulse response of the filter at the sample indices given in n with numerator
coefficients in b and denominator coefficients in a. When no output arguments are given, the impz function
plots the response in the current figure window using the stem function.

2.2 ZERO-INPUT AND ZERO-STATE RESPONSES


The difference equation is generally solved forward in time from 𝑛 = 0. Therefore, initial conditions on 𝑥[𝑛]
and 𝑦[𝑛] are necessary to determine the output for 𝑛 ≥ 0. The difference equation is then given by equation
(4.2) subject to the initial conditions
1
1
{𝑦[𝑛], −𝑁 ≤ 𝑛 ≤ −1}.

A solution to (4.2) can be obtained in the form

𝑦[𝑛] = 𝑦𝑧𝑖[𝑛] + 𝑦𝑧𝑠[𝑛],

where 𝑦𝑧𝑖[𝑛] is called the zero-input response, which is a solution due to the initial conditions alone (assuming
they exist), while the zero-state response, 𝑦𝑧𝑠[𝑛], is a solution due to input x(n) alone (or assuming that the
initial conditions are zero).

2.3 DIGITAL FILTERS


Filter is a generic term that refers to a linear time-invariant system designed for a specific job of frequency
selection or frequency discrimination. Hence, discrete-time LTI systems are also called digital filters. There are
two types of digital filters.

FIR filter
If the unit impulse response of an LTI system is of finite duration, then the system is called a finite-duration
impulse response (or FIR) filter. Hence, for an FIR filter, ℎ[𝑛] = 0 for 𝑛1 ≤ 𝑛 ≤ 𝑛2. The following part of the
difference equation (4.1) describes a causal FIR filter:
𝑀

𝑦[𝑛] = ∑ 𝑏𝑘𝑥[𝑛 − 𝑘], ∀ 𝑛.


𝑘=0

Furthermore, ℎ[0] = 𝑏0, ℎ[1] = 𝑏1, … , ℎ[𝑀] = 𝑏𝑀, while all other ℎ[𝑛]’s are 0.

FIR filters are also called non-recursive or moving average (MA) filters. In MATLAB, FIR filters are
represented either as impulse response values ℎ[𝑛] or as difference equation coefficients {𝑏𝑘} and 𝑎0 = 1.
Therefore, to implement FIR filters, we can use either the conv(x, h) function (and its modification that we
discussed) or the filter (b, 1, x) function. It should be noted that the output sequence from the conv(x, h)
function has a longer length than both the 𝑥[𝑛] and ℎ[𝑛] sequences. On the other hand, the output sequence
from the filter (b, 1, x) function has exactly the same length as the input sequence 𝑥[𝑛].

IIR filter
If the impulse response of an LTI system is of infinite duration, then the system is called an infinite-duration
impulse response (or IIR) filter. The part of difference equation (4.1)

∑ 𝑎𝑘𝑦[𝑛 − 𝑘] = 𝑥[𝑛], ∀𝑛
𝑘=0

describes a recursive filter in which the output 𝑦[𝑛]is recursively computed from its previously computed
values and is called an autoregressive (AR) filter. The impulse response of such a filter is of infinite duration
and hence, represents an IIR filter. The general equation (4.1) also describes an IIR filter. It has two parts: an
AR part and an MA part. Such an IIR filter is called an autoregressive moving average, or an ARMA, filter. In
1
2
MATLAB, IIR filters are described by the difference equation coefficients {𝑏𝑘} and {𝑎𝑘} and are implemented
by the filter(b ,a ,x) function.

Exercises:
1. Linear Constant-Coefficient Difference Equation
A backward difference system, given by

𝑦[𝑛] = 𝑥[𝑛] − 𝑥[𝑛 − 1],

is a digital differentiator. Implement this differentiator on the following sequences and plot the results
using stem command.
 𝑥[𝑛] = 3𝑢[𝑛 − 5] − 3𝑢[𝑛 − 25]: a rectangular pulse
 𝑥[𝑛] = 𝑛(𝑢[𝑛] − 𝑢[𝑛 − 15]) + (30 − 𝑛)(𝑢[𝑛 − 15] − 𝑢[𝑛 − 30]): a triangular pulse
𝜋𝑛
 𝑥[𝑛] = sin ( ) (𝑢[𝑛] − 𝑢[𝑛 − 100]): a sinusoidal pulse
20

Comment on the appropriateness of this differentiator.


% Part A: Simple Differentiator response to a rectangular
a = 1; b = [1 -1];
n1 = 0:30;
[x11,nx11] = stepseq(5,0,30); [x12,nx12] = stepseq(25,0,30);
x1 = 5*(x11 - x12);
y1 = filter(b,a,x1);
stem(n1,y1)

% Part B: Simple Differentiator response to a triangular


a = 1; b = [1 -1];
n2 = 0:31;

1
3
[x21,nx21] = stepseq(0,0,31);[x22,nx22] = stepseq(15,0,31); [x23,nx23] =
stepseq(30,0,31);
x2 = n2.*(x21 - x22) + (30 - n2).*(x22 - x23);
y2 = filter(b,a,x2);
stem(n2,y2)

% Part C: Simple Differentiator response to a sinusoidal


a = 1; b = [1 -1]; n3 = 0:101;
[x31,nx31] = stepseq(0,0,101);[x32,nx32] = stepseq(100,0,101);
x33 = x31-x32; x3 = sin(pi*n3/20).*x33;
y3 = filter(b,a,x3);
stem(n3,y3)

1
4
2. Correlation of Sequences
In a certain concert hall, echoes of the original audio signal x(n) are generated due to the reflections at
the walls and ceiling. The audio signal experienced by the listener y(n) is a combination of x(n) and its
echoes. Let

𝑦[𝑛] = 𝑥[𝑛] − 𝛼𝑥[𝑛 − 𝑘],

where 𝑘 is the amount of delay in samples and 𝛼 is its relative strength.


Let 𝑥[𝑛] = cos(0.2𝜋𝑛) + 0.5 cos(0.6𝜋𝑛) , 𝛼 = 0.1, 𝑘 = 50. Generate 200 samples of 𝑦[𝑛] & determine
its cross-correlation. Can you obtain α and 𝑘 by observing 𝑟𝑦𝑥[𝑙] ? Record your response below.
n = 0:200;
x = cos(0.2*pi*n) + 0.5*cos(0.6*pi*n);
a = 0.1;
k = 50;
[y,ny] = sigshift(x,n,k);
y = a*y;
[y,ny] = sigadd(y,ny,x,n);
subplot(2,2,1); stem(n,x);
title('Given Sequence');
subplot(2,2,2); stem(ny,y);
title('Delayed Signal');
[yf,nyf] = sigfold(y,ny);
[ry,nry] = conv_m(x,n,yf,nyf);
subplot(2,2,3); stem(nry,ry);
title('Autocorrelation rxy');
[xf,nf] = sigfold(x,n);
[rx,nrx] = conv_m(xf,nf,y,ny);
subplot(2,2,4); stem(nrx,rx);
title('Autocorrelation ryx');

We can’t able to estimate the values of alpha and k.


1
5

You might also like