% Design Example 4.1 - Suspension Analysis

clc             % clear the command window
clear           % clear all variables
close all       % close any existing windows
format compact	% prevent extra blank lines in the output

k = 500 * 12;
b = 10 * 12;
m = 500 / 32.174;
F0 = 6/12*k;
B0 = 3/12*k;
w = [10 20 30];
i = 1:3;
t = 0 : 0.01: 2;

wn = sqrt(k/m)
zeta = b / (2*sqrt(k*m))
wd = wn * sqrt(1 - zeta^2);

% Plot step response
x = F0/k * (1 - exp(-zeta*wn*t).*cos(wd*t));
plot(t, x*12)
xlabel('t');
ylabel('x(t)(in)');

% Plot frequency responses
x0(i) = B0/k ./ sqrt((1-(w(i)/wn).^2).^2 + 4*zeta^2*(w(i)/wn).^2);
phi(i) = -angle ((wn./w(i) - w(i)/wn) + 2*zeta*1j);
x1 = x0(1) * sin(w(1)*t + phi(1));
x2 = x0(2) * sin(w(2)*t + phi(2));
x3 = x0(3) * sin(w(3)*t + phi(3));

figure
plot(t, x1*12,'Color',[1 0 0])
hold on
plot(t, x2*12,'Color',[0 0 1])
hold on
plot(t, x3*12,'Color',[0 1 0])

disp 'Hit Enter to close all windows and quit'
pause
close all