A one-dimensional discrete-time oscillating system consists of a unit mass, m, attached to a wall by a spring of unit elastic constant. A sensor samples the acceleration, a, of the mass at Fs=5 Hz.
Generate 50 time samples. Define the sampling interval Δt=1/Fs.
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:
H(z)=1-z-1(1+cosΔt)+z-2cosΔt1-2z-1cosΔt+z-2.
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.
bf = [1 -(1+cos(dt)) cos(dt)];
af = [1 -2*cos(dt) 1];
yf = filter(bf,af,u);
stem(t,yf,'o')
xlabel('t')
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')