Lab Manual EKT230/4 Signals & Systems
LABORATORY 3
DIFFERENCE EQUATIONS & STATE-VARIABLES
1.0 OBJECTIVES:
After completing this lab you will be able :
1.1 To manipulate State Variables Description and Difference Equations.
1.2 Use “filter” command, “filtic” command and “impz” command
correctly.
2.0 TOOLS
The MATLAB Signal Processing Toolbox.
3.1 SIMULATING DIFFERENCE EQUATIONS
Differential Equation (DE)
Coefficients ak and bk are real numbers; m ≤ n. DE are widely used to model physical processes. They occur frequently in networks, dynamics, physics, etc.
To express the Difference Equation description of a system in recursive form that allowed the system output to be computed for the input signal & past output, we use the “filter” command.
=
Define vectors den = [ a0, a1, ……, aN ]
num = [ b0, b1, ……, bM ]
if X is a vector representing the input signal.
then , vector y = filter ( num, den, x ) ….. representing the output of the system at zero, initial condition.
For non-zero initial conditions, we use alternative command syntax, y = filter ( num, den, x, Zi ), where Zi represent the initial condition required by filter. The command “[h, t] = impz(num, den, n)” evaluates “n” values of the impulse response of a system described by a difference equation. The vector h contains the values of the impulse response, and t contains the corresponding time indices.
Note: The initial conditions used by “filter” are not the past values of the output. These initial conditions are obtain from knowledge of the past outputs, using command
Zi = filtic ( num, den, yi ) ,
where yi is a vector containing, initial condition in the order [ y [-1], y[-2], …..,
y [-N]].
Example 3.1.1
A system is described by the Difference Equation,
y [n] – 1.143y [n-1] + 0.4128y [n-2] = 0.0675x[n] + 0.1349x[n-1] + 0.675x[n-2]
Determine the output in response to zero input and initial condition,
y[-1] = 1 and y[-2] = 2, [first 50 values]
Solution 3.1.1
> clear
> n = [1:50]; @ [0:49]
> den = [1, -1.143, 0.4128];
> num = [0.0675, 0.1349, 0.675];
> x = zeros (1, 50);
> Zi = filtic ( num, den, [1, 2] ); % initial condition y[-1] = 1 & y[-2] = 2
> y = filter ( num, den, x, Zi);
> stem (n,y)
3.2 STATE – VARIABLE DESCRIPTIONS
Systems are manipulated in MATLAB by operation on their LTI objects. By using the MATLAB Control System Toolbox, we are enabling to manipulate LTI System descriptions as Single MATLAB variables.
The command “SyS = ss (a,b,c,d,-1)” produces an LTI object “SyS” that represents the discrete-time system in state-variable form. While for a continuous-time system, omits the ‘-1’ that is, by using ,
“SyS = ss (a,b,c,d) ______Continuous-time System
if SyS1 and SyS2 are objects representing two systems in state variable form, then
SyS = SyS1 + SyS2 ______parallel combination
SyS = SyS1 * SyS2 ______cascade combination
The function “LSIM” Simulates the output of an LTI system in response to a specified input.
y = Lsim ( SyS, x ) ______x = vector input
h = impulse ( SyS, N ) ______N = value of the impulse response in ‘h’.
Different state-variable descriptions for the LTI system are obtained by transforming the state. The State transformation is identical for both continuous & discrete-time system. The command is of the form
SyST = ss2ss (SyS, T)
Where, SyST = Transformed state-variable description
SyS = the original state variable description
T = the state transformation matrix.
Example 3.2.1
A discrete-time system has the state variable description
A = 1/10 -1 4 , B = 2
4 -1 4
C = 1/2 1 1 , D = 2
Using the state-transformation matrix
T = 1/2 -1 1
1 1
Using MATLAB, find the state-variables description A’, B’, C’, D’.
The following commands produce the designed result:
> a = [-0.1, 0.4; 0.4, -0.1] ; b = [ 2 ; 4 ] ;
> c = [0.5, 0.5] ; d = 2 ;
> SyS = ss (a, b, c, d,-1) % define the state-space object system
> T = 0.5 * [-1, 1; 1, 1];
> SyST = ss2ss ( SyS,T)
a = x1 x2
x1 -0.50000 0
x2 0 0.30000
b = u1
x1 1.0000
x2 3.0000
c = x1 x2
y1 0 1.00000
d = u1
y1 2.00000
To verify that the two systems represented by SyS and SyST have identical input-output characteristic by comparing their impulse by responses via the following commands.
> h = impulse (SyS, 10);
> hT = impulse ( SyST,10);
> subplot ( 2,1,1 );
> stem ( [0:9],h );
> title (‘Original System Impulse Response’);
> xlabel (‘Time’); ylabel (‘Amplitude’);
> subplot (2,1,2);
> stem ( [0:9], hT);
> title (‘Transformed System Impulse Response’);
> xlabel (‘Time’); ylabel (‘Amplitude’);
Problem 3.2.1
A continuous-time system has the state variable description
A = -2 0 , B = 1
1 -1 1
C = [ 0 2 ] D = 1
Using MATLAB, find the state-variables description A’, B’, C’, D’.
Corresponding to the new states,
q1’ (t) = 2q1 (t) + q2 (t) and q2’ (t) = q1 (t) – q2 (t)
TASKS OF THE DAY
Q 3.1 Use the MATLAB commands filter and filtic to determine the first 50 output values in the following problems. The output of the systems is described by the following difference equations with input and initial condition as specified.
(a) y[n] - 1/2 y[n-1] = 2 x[n]
y[-1] = 3, x [n] = (- ½ )n u[n]
(b) y[n] - 3/4 y[n-1] + 1/8y[n-2] = 2x[n]
y[-1] = 1, y[-2] = -1, x[n] = 2 u[n]
Q 3.2 Use the MATLAB command ss2ss to solve following problems. Let a discrete-time system have the state variables description given by
A = 1 - 1/2 ; B = 1
1/3 -1 2
C = [ 1 - 1 ] ; and D = [ 0 ]
(a) Define new state q1’ [n] = 2q1 [n], q2’ [n] = 3 q2 [n]
Find the new state variable description given by
A’, B’, C’ and D’.
(b) Define new state q1’ [n] = 3q2 [n], q2’ [n] = 2q1 [n]
Find the new state variable description given by
A’, B’, C’ and D’.
(c) Define new state q1’ [n] = q1 [n] + q2 [n] , q2’ [n] = q1 [n] - q2 [n]
Find the new state variable description given by
A’, B’, C’ and D’.
Q 3.3 (a) Use the MATLAB commands lsim and impulse to determine the first 30 values of the step and impulse response of this system.
(b) Defines new state q1 [n] = q1 [n] + q2 [n] and q2 [n] = 2q1 [n] - q2 [n] .
Repeat Part (a) for the transformed system. A system has the state-variable description.
A = 1/2 - 1/2 , B = 1
1/3 0 2
C = [ 1 -1 ] , D = [ 0 ]
27