Lab 2 DSP. Linear Time-Invariant System
Lab 2 DSP. Linear Time-Invariant System
If you are using Octave please install the control and signal package by following command.
a. Shifting function
In this operation, each sample of 𝑥(𝑛) is shifted by an amount 𝑘 to obtain a shifted sequence 𝑦(𝑛).
Example 1.1 Let x(n) = [1, 2, 3, 4, 5,6, 7, 6, 5, 4, 3, 2, 1] Determine and plot following sequences:
𝑦(𝑛) = 𝑥(𝑛 − 5)
1
[y,n_shift]=sigshift(x,n,5)
subplot(2,1,2);
stem(n_shift, y); xlabel('n'); ylabel('y(n)');
title('Shifting signal x(n) by 5', 'FontSize', 14);
y = 1 2 3 4 5 6 7 6 5 4 3 2 1
n_shift = 5 6 7 8 9 10 11 12 13 14 15 16 17
Linear time-invariant (𝐿𝑇𝐼) system: A linear system in which an input-output pair, 𝑥(𝑛) and
𝑦(𝑛), is invariant to a shift k in time is called a linear time-invariant system i.e.,
2
For an (𝐿𝑇𝐼)system the linear operator 𝐿[.] and the shifting operators are reversible as shown here.
Example 1.2 Determine whether the following linear systems are time-invariant.
1 1
𝑦(𝑛) = 𝐿[𝑥(𝑛)] = 2
𝑥(𝑛) + 2
𝑥(𝑛 − 1)
1 1
𝑦𝑘(𝑛) = 𝐿[𝑥(𝑛 − 𝑘)] = 2
𝑥(𝑛 − 𝑘) + 2
𝑥(𝑛 − 𝑘 − 1)
1 1
While shifted output 𝑦(𝑛 − 𝑘) = 𝑥(𝑛 − 𝑘) + 𝑥(𝑛 − 𝑘 − 1) = 𝑦𝑘(𝑛)
2 2
3
[x3,ny_shift]=sigshift(x,n,1); % shifted by an amount of 1
y= 1/2*x + 1/2*x3; % y function
[y_shift, ny_shift] =sigshift(y,ny_shift, k) % shifted by an amount of k
subplot(3,1,3); stem(ny_shift,y);
xlabel('n'); ylabel('y(n-k)');
title('Response due to shifted output y(n-k)', 'FontSize', 14)
The response of the shifted input is the same as output → Hence the given system is time-invariant.
Exercise 1.1 Determine whether the following linear systems are time-invariant Matlab plots.
1 1 1
a) 𝑦(𝑛) = 𝐿[𝑥(𝑛)] = 4
𝑥(𝑛) + 2
𝑥(𝑛 − 1) + 4
𝑥(𝑛 − 2)
C. Convolution
4
Convolution operation to describe the response of the Linear time-invariant (𝐿𝑇𝐼) system. We will
denote a 𝐿𝑇𝐼 system by the operator 𝐿𝑇𝐼[.] . Let x(n) and y(n) be the input-output pair of an LTI
system. Then the time-varying function ℎ(𝑛, 𝑘) becomes a time-invariant function ℎ(𝑛 − 𝑘) , and the
output from:
The impulse response of an LTI system is given by ℎ(𝑛). The mathematics operation in
equation upper is called Linear Convolution sum and denoted by:
Hence an 𝐿𝑇𝐼system is completely characterized in the time domain by the impulse response ℎ(𝑛).
The convolution function conv(x, h) in Matlab can NOT be used directly, because this function
does not accept and provide any timing information if the signals have arbitrary support. By
default the conv(x, h) in Matlab knows the time origin at the beginning of the signal.
What is needed are the beginning points of signals, so we create a new convolution function,
called conv_m, which performs convolution of two signals with arbitrary supports
5
function [y,ny] = conv_m(x,nx,h,nh)
% Modified convolution routine for signal processing
% --------------------------------------------------
% [y,ny] = conv_m(x,nx,h,nh)
% y = convolution result
% ny = support of y
% x = first signal on support nx
% nx = support of x
% h = second signal on support nh
% nh = support of h
%
nyb = nx(1)+nh(1); nye = nx(length(x)) + nh(length(h));
ny = [nyb:nye];
y = conv(x,h);
6
Exercise 1.2 Determine analytically the convolution y[n] =x[n]*h[n] of the following sequences and
2. Z Transform
where z is a complex variable. The set of z values for which X(z) exists is called
the region of convergence (ROC) and is given by
7
for some non-negative numbers Rx−and Rx+
Comment:
● The complex variable z is called the complex frequency given by z =|z|ejω, where |z|is the
magnitude and ω is the real frequency.
● Note that Rx− may be equal to zero and/or Rx+ could possibly be ∞
● If Rx+ < Rx- then the ROC is a null space and the z-transform does not exist
● The function |z|= 1 (or z = ejω) is a circle of unit radius in the z-plane and is called the unit
circle
𝑛
Example 2.1: For a LTI system described by the following impulse response ℎ1(𝑛) = 𝑎 𝑢(𝑛),
with 0 < |𝑎| < ∞. Display the pole-zero plot using MATLAB and check the stability of this system.
𝐵(𝑧) 1
Then: 𝐻 (𝑧) = 𝐴(𝑧)
= −1
1 1−𝑎𝑧
In Matlab we can plot the Z-plane with zplane(b,a) plots poles and zeros, given the numerator
8
Start load the signal package1 in octave: pkg load signal
a=0.9;
n1 = [0:20]; h1 = (a.^n1).*stepseq(0,0,20);
subplot(1,2,1); stem(n1,h1)
xlabel('discrete time'); ylabel('h(n)');
title('input function');
subplot(1,2,2);
B = [1, 0]; A = [1, -a]; % numerator [b0 =1, b1=0] and denominator [a0=1, a1=-a]
zplane(B,A)
title('Z Plane');
If a=0.9 then the pole inside of the unit circle → This system is stable. We have the zplane results
If a=1.1 then the pole outside of the unit circle → This system is unstable.
1
https://octave.sourceforge.io/signal/function/zplane.html
9
𝑛
Example 2.2: Let ℎ (𝑛) = − 𝑏 𝑢(− 𝑛 − 1), with 0 < |𝑏| < ∞. Calculation this z function:
2
With function 𝑢(− 𝑛 − 1) we need to create a function stepseq_flip.m. The function stepseq(n0,
n1, n2) create the flip step signal via the y-axis, this can
Don't forget load the signal package in octave: pkg load signal
b=0.9;
n2 = [-20:0]; h2 = (-b.^n2).*stepseq_flip(-1,-20,0);
subplot(2,2,1); stem(n2,h2)
xlabel('discrete time'); ylabel('h(n)');
title('input function');
subplot(2,2,2);B = [1, 0]; A = [1, -b]; zplane(B,A)
title('Z Plane');
10
If b=0.9 then the pole inside of the unit circle → This system is stable. We have the zplane results
If b=1.1 then the pole outside of the unit circle → This system is unstable.
Exercise 2.1: Determine the z-transform of the following sequences using the z-transform table and
the z-transform properties. Indicate the region of convergence and provide a pole-zero plot using
Matlab/Octave to plot the z-plane.
Exercise 2.2 A linear time-invariant system is described by the following difference equation:
11
b) Use MATLAB to compute and plot the impulse response of the system for 𝑛 = 0,..., 200
c) Use MATLAB to compute and plot the response of the system if the input is
Hint: Use MATLAB built-in function filter that solves difference equations numerically, given
the input and the difference equation coefficients. The function can be invoked by y = filter(b,a,x)
Where 𝑏 = [𝑏0, 𝑏1, ..., 𝑏𝑀]; 𝑎 = [𝑎0, 𝑎1, ..., 𝑎𝑁]; are the coefficients of the difference equation of
the form.
given by
The operator 𝐹[.] transforms a discrete signal x(n) into a complex-valued continuous function
𝑗ω
𝑋(𝑒 )of real variable and ω, which is called the digital frequency and measured in
radians/samples.
Example 3.1 Determine the discrete-time Fourier transform of the following finite-duration
sequence
12
When we put the input is the impulse function ℎ[𝑛] = (δ[𝑛] + δ[𝑛 − 1])/2
−𝑗ω −𝑗ω/2
𝐻𝑑[ω] = (1 + 𝑒 )/2 = 𝑐𝑜𝑠(ω/2). 𝑒
13
Example 3.2: To plot the frequency response of the system given by the transfer function
Hint: Use MATLAB built-in function freqz. Type help freqz to see more information on how to
[H,w] = freqz(b,a,N)
which returns the N-point frequency vector w and the N-point complex frequency response vector
H of the system, given its numerator and denominator coefficients in vectors b and a.
num=[1 -2];%num
den=[1 -2 2];%den
n= 512; %numpoints input
14
%input omega range [-pi pi] includes 512 points
w=linspace(-pi,pi,512);%create vector(1x51)
H=freqz(num,den,w); %freq response
Magnitude = abs(H); %Magnitude response
Phase = angle(H); %phase response
figure, subplot(211), plot(w,abs(H)), title(' magnitude spectrum
|X(e^{-j\omega})|');
subplot(212), plot(w,angle(H)), title('phase spectrum');
2 𝑛
Exercise 3.1 : Given the sequence 𝑥[𝑛] = (𝑛 + 1)0. 2 𝑢[𝑛] use MATLAB to compute and plot the
magnitude response and phase response of the DTFT for the frequencies in the range [− π, π]
Bibliography
3. Vinay K. Ingle and John G. Proakis. 2011. Digital Signal Processing Using MATLAB (3rd. Ed)
CL-Engineering.
15