A one-dimensional discrete-time oscillating system consists of a unit mass, $\mathit{m}$, attached to a wall by a spring of unit elastic constant. A sensor samples the acceleration, $\mathit{a}$, of the mass at ${\mathit{F}}_{\mathrm{s}}=5$ Hz.

Generate 50 time samples. Define the sampling interval $\Delta \mathit{t}=1/{\mathit{F}}_{\mathrm{s}}$.

Fs = 5;
dt = 1/Fs;
N = 50;
t = dt*(0:N-1);
u = [1 zeros(1,N-1)];

The transfer function of the system has an analytic expression:

The system is excited with a unit impulse in the positive direction. Compute the time evolution of the system using the transfer function. Plot the response.

Find the state-space representation of the system. Compute the time evolution starting from an all-zero initial state. Compare it to the transfer function prediction.

[A,B,C,D] = tf2ss(bf,af);
x = [0;0];
for k = 1:N
y(k) = C*x + D*u(k);
x = A*x + B*u(k);
end
hold on
stem(t,y,'*')
hold off
legend('tf','ss')

b — Transfer function numerator coefficients vector | matrix

Transfer function numerator coefficients, specified as a vector or matrix. If
b is a matrix, then each row of b
corresponds to an output of the system.

For discrete-time systems, b contains the coefficients in
descending powers of z.

For continuous-time systems, b contains the coefficients
in descending powers of s.

For discrete-time systems, b must have a number of columns equal
to the length of a. If the numbers differ, make them equal by padding
zeros. You can use the function eqtflength to accomplish this.

a — Transfer function denominator coefficients vector

Transfer function denominator coefficients, specified as a vector.

For discrete-time systems, a contains the coefficients in
descending powers of z.

For continuous-time systems, a contains the coefficients
in descending powers of s.

You can also select a web site from the following list:

How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.