Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
165 views

Lab 2 DSP. Linear Time-Invariant System

This document discusses linear time-invariant (LTI) systems and their properties. It contains 3 sections: 1. Shifting and time-invariant systems - Defines shifting of signals and describes how LTI systems are invariant to time shifts. Matlab functions for shifting signals are introduced. 2. Z-transform - Defines the z-transform and region of convergence. Examples calculate z-transforms and use the zplane function to plot poles and check stability. 3. Convolution - Describes convolution as the operation used to characterize the response of LTI systems. A modified convolution function is created to allow signals with arbitrary supports. Examples calculate and plot convolutions.

Uploaded by

Trí Từ
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
165 views

Lab 2 DSP. Linear Time-Invariant System

This document discusses linear time-invariant (LTI) systems and their properties. It contains 3 sections: 1. Shifting and time-invariant systems - Defines shifting of signals and describes how LTI systems are invariant to time shifts. Matlab functions for shifting signals are introduced. 2. Z-transform - Defines the z-transform and region of convergence. Examples calculate z-transforms and use the zplane function to plot poles and check stability. 3. Convolution - Describes convolution as the operation used to characterize the response of LTI systems. A modified convolution function is created to allow signals with arbitrary supports. Examples calculate and plot convolutions.

Uploaded by

Trí Từ
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Lab2.

Linear Time-Invariant System


WINTER SEMESTER 2021
INSTRUCTOR: MSc. Tri Bien
tri.bm@vgu.edu.vn

If you are using Octave please install the control and signal package by following command.

pkg install -forge control


pkg install -forge signal
pkg load signal

1. Linear time-invariant system

a. Shifting function

In this operation, each sample of 𝑥(𝑛) is shifted by an amount 𝑘 to obtain a shifted sequence 𝑦(𝑛).

Matlab using signal shifting function 𝑠𝑖𝑔𝑠ℎ𝑖𝑓𝑡(𝑥, 𝑚, 𝑘)

In the Malab we create the shifting function 𝑠𝑖𝑔𝑠ℎ𝑖𝑓𝑡(𝑥, 𝑚, 𝑘) in sigshift.m file

function [y,n] = sigshift(x,m,k)


% implements y(n) = x(n-k)
% -------------------------
% [y,n] = sigshift(x,m,k)
n = m+k; y = x;
Hence this operation has no effect on the vector x, but the vector n is changed by adding k to each
element. This is shown in the function sigshift.

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)

% Plot the raw signal x(n)


n= 0:12; x=[1:7,6:-1:1];
subplot(2,1,1); stem(n,x) ;xlabel('n'); ylabel('x(n)');
title('Raw signal x(n)', 'FontSize', 14)
% Shifting the x signal by 5 unit

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

b. Linear time-invariant system

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)

Solution: The response due to shifted input is:

1 1
𝑦𝑘(𝑛) = 𝐿[𝑥(𝑛 − 𝑘)] = 2
𝑥(𝑛 − 𝑘) + 2
𝑥(𝑛 − 𝑘 − 1)

1 1
While shifted output 𝑦(𝑛 − 𝑘) = 𝑥(𝑛 − 𝑘) + 𝑥(𝑛 − 𝑘 − 1) = 𝑦𝑘(𝑛)
2 2

→ Hence the given system is time-invariant.

Using Matlab plot

% Plot the raw signal x(n)


n= 0:12; x=[1:7,6:-1:1];
subplot(3,1,1); stem(n,x) ;xlabel('n'); ylabel('x(n)');
title('Raw signal x(n)', 'FontSize', 14)
% Shift the k value
k=3
%---------------------
% Plot the shifted input x(n-k) signal
[x1,n_shift]=sigshift(x,n,k); % shifted by an amount of k
[x2,n_shift]=sigshift(x,n,(1 + k)); % shifted by an amount of k +1
Lx=1/2*x1 + 1/2*x2; % Lx(n-k) function
subplot(3,1,2); stem(n_shift,Lx) ;xlabel('n'); ylabel('Lx(n-k)');
title('Response due to shifted input x(n-k)', 'FontSize', 14)
%---------------------
% Plot the shifted output y(n-k) signal

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)

b) 𝑦(𝑛) = 𝐿[𝑥(𝑛)] = 10 𝑠𝑖𝑛(0. 1π𝑛)𝑥(𝑛)

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 ℎ(𝑛).

Implement Convolution function in Matlab:

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.

Example 1.3 Convolution of two rectangular pulses with

x=[0 0 0 5 5 5 0 0 0]; h=[0 0 0 5 5 5 0 0 0];


y=conv(x,h)

%Result print on screen


>> y= 0 0 0 0 0 0 25 50 75 50 25 0 0 0 0 0 0

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);

Example 1.4 Let’s calculate the convolution of two rectangular pulses

% get the function x and h


x=[0 0 0 5 5 5 0 0 0];nx=[-3:5];
h=[ 0 0 0 1 1 1 0]; nh=[-2:4];
[y, ny] =conv_m(x,nx,h, nh)
%Plot function
subplot(3,1,1); stem(nx, x);
xlabel('nx'); ylabel('x');
title('The x(n) function', 'FontSize', 14)
subplot(3,1,2); stem(nh, h);
xlabel('nh'); ylabel('h');
title('The h(n) function', 'FontSize', 14)
subplot(3,1,3); stem(ny, y);
xlabel('ny'); ylabel('y');
title('The y function is convolution of x(n)*h(n) ', 'FontSize', 14)

6
Exercise 1.2 Determine analytically the convolution y[n] =x[n]*h[n] of the following sequences and

verify your answers using the function conv_m.

2. Z Transform

a. Z Transform and examples

The z-transform of a sequence x(n) is given by:

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.

Solution: We can find 𝐻1(𝑧) transfer function below:

𝐵(𝑧) 1
Then: 𝐻 (𝑧) = 𝐴(𝑧)
= −1
1 1−𝑎𝑧

In Matlab we can plot the Z-plane with zplane(b,a) plots poles and zeros, given the numerator

row vector b and the denominator row vector a.

>> help zplane


Function File: zplane (B, A)
The transfer function is

B(z) b0 + b1 z^(-1) + b2 z^(-2) + ... + bM z^(-M)


H(z) = ---- = --------------------------------------------
A(z) a0 + a1 z^(-1) + a2 z^(-2) + ... + aN z^(-N)

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

function [x,n] = stepseq_flip(n0,n1,n2)


% Generates x(n) = u(-n-n0); n1 <= n <= n2
% ------------------------------------------
% [x,n] = stepseq(n0,n1,n2)
%
n = [n1:n2]; x = [(n-n0) <= 0];

Plot 𝑢(− 𝑛 − 1)in range:-20:0

%Plot step sequence flip signal


n2 = [-20:0]; x2 = stepseq_flip(-1,-20,0);
stem(n2,x2, 'b')
xlabel('n','fontsize',16); ylabel('Magnitude', 'fontsize',16);
title('Plot step sequence flip signal', 'fontsize',16);

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:

𝑦[𝑛] − 0. 5𝑦[𝑛 − 1] + 0. 25𝑦[𝑛 − 2] = 𝑥[𝑛] + 2𝑥[𝑛 − 1] + 𝑥[𝑛 − 3]

a) Find the transfer function .

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

(5 + 3𝑐𝑜𝑠(0. 2π𝑛))𝑢[𝑛 − 10], 𝑛 = 0,..., 200.

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.

3. Discrete-Time Fourier Transform (DTFT)



If 𝑥(𝑛) is absolutely summable, that is, ∑ 𝑥(𝑛) < ∞, then its discrete time Fourier transform is
−∞

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

𝑦[𝑛] = (𝑥[𝑛] + 𝑥[𝑛 − 1])/2

We can plot this equation to block diagram:

12
When we put the input is the impulse function ℎ[𝑛] = (δ[𝑛] + δ[𝑛 − 1])/2

Convert this function to DTFT

−𝑗ω −𝑗ω/2
𝐻𝑑[ω] = (1 + 𝑒 )/2 = 𝑐𝑜𝑠(ω/2). 𝑒

w = [0:1:500]*pi/500; % [0, pi] axis divided into 501 points.


H = exp(-j*w/2) .* cos(w/2);
magH = abs(H); angH = angle(H); realH = real(H); imagH = imag(H)
subplot(2,2,1); plot(w/pi,magH); grid;
xlabel('frequency in pi units'); title('Magnitude Part');
ylabel('Magnitude')
subplot(2,2,3); plot(w/pi,angH); grid
xlabel('frequency in pi units'); title('Angle Part');
ylabel('Radians')
subplot(2,2,2); plot(w/pi,realH); grid
xlabel('frequency in pi units'); title('Real Part'); ylabel('Real')
subplot(2,2,4); plot(w/pi,imagH); grid
xlabel('frequency in pi units'); title('Imaginary Part');
ylabel('Imaginary')

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

use this function. In its simplest form, this function is invoked by

[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

1. Wikipedia, MATLAB. https://en.wikipedia.org/wiki/MATLAB.

2. Octave, Wikipedia. https://www.gnu.org/software/octave/index.

3. Vinay K. Ingle and John G. Proakis. 2011. Digital Signal Processing Using MATLAB (3rd. Ed)

CL-Engineering.

15

You might also like