[b,a] =
ss2tf(A,B,C,D) converts
a state-space representation of a system into an equivalent transfer
function. ss2tf returns the Laplace-transform transfer
function for continuous-time systems and the Z-transform transfer
function for discrete-time systems.

[b,a]
= ss2tf(A,B,C,D,ni) returns
the transfer function that results when the nith
input of a system with multiple inputs is excited by a unit impulse.

A one-dimensional discrete-time oscillating system consists of a unit mass, , attached to a wall by a spring of unit elastic constant. A sensor samples the acceleration, , of the mass at Hz.

Generate 50 time samples. Define the sampling interval .

Fs = 5;
dt = 1/Fs;
N = 50;
t = dt*(0:N-1);

The oscillator can be described by the state-space equations

where is the state vector, and are respectively the position and velocity of the mass, and the matrices

A = [cos(dt) sin(dt);-sin(dt) cos(dt)];
B = [1-cos(dt);sin(dt)];
C = [-1 0];
D = 1;

The system is excited with a unit impulse in the positive direction. Use the state-space model to compute the time evolution of the system starting from an all-zero initial state.

u = [1 zeros(1,N-1)];
x = [0;0];
for k = 1:N
y(k) = C*x + D*u(k);
x = A*x + B*u(k);
end

Plot the acceleration of the mass as a function of time.

stem(t,y,'v','filled')
xlabel('t')

Compute the time-dependent acceleration using the transfer function H(z) to filter the input. Plot the result.

An ideal one-dimensional oscillating system consists of two unit masses, and , confined between two walls. Each mass is attached to the nearest wall by a spring of unit elastic constant. Another such spring connects the two masses. Sensors sample and , the accelerations of the masses, at Hz.

Specify a total measurement time of 16 s. Define the sampling interval .

Fs = 16;
dt = 1/Fs;
N = 257;
t = dt*(0:N-1);

The system can be described by the state-space model

where is the state vector and and are respectively the location and the velocity of the -th mass. The input vector and the output vector . The state-space matrices are

the continuous-time state-space matrices are

and denotes an identity matrix of the appropriate size.

Ac = [0 1 0 0;-2 0 1 0;0 0 0 1;1 0 -2 0];
A = expm(Ac*dt);
Bc = [0 0;1 0;0 0;0 1];
B = Ac\(A-eye(4))*Bc;
C = [-2 0 1 0;1 0 -2 0];
D = eye(2);

The first mass, , receives a unit impulse in the positive direction.

ux = [1 zeros(1,N-1)];
u0 = zeros(1,N);
u = [ux;u0];

Use the model to compute the time evolution of the system starting from an all-zero initial state.

x = [0;0;0;0];
for k = 1:N
y(:,k) = C*x + D*u(:,k);
x = A*x + B*u(:,k);
end

Plot the accelerations of the two masses as functions of time.

The system is reset to its initial configuration. Now the other mass, , receives a unit impulse in the positive direction. Compute the time evolution of the system.

u = [u0;ux];
x = [0;0;0;0];
for k = 1:N
y(:,k) = C*x + D*u(:,k);
x = A*x + B*u(:,k);
end

Plot the accelerations. The responses of the individual masses are switched.

Input index, specified as an integer scalar. If the system has p inputs,
use ss2tf with a trailing argument ni = 1, …, p to
compute the response to a unit impulse applied to the nith
input.

Transfer function numerator coefficients, returned as a vector
or matrix. If the system has p inputs and q outputs
and is described by n state variables, then b is q-by-(n + 1) for each input. The coefficients
are returned in descending powers of s or z.

Transfer function denominator coefficients, returned as a vector.
If the system has p inputs and q outputs
and is described by n state variables, then a is
1-by-(n + 1)
for each input. The coefficients are returned in descending powers
of s or z.