%% Parameter motor DC
R = 2.0 % Ohms
L = 0.5 % Henrys
Km = .015 % torque constant
Kb = .015 % emf constant
Kf = 0.2 % Nms
tau = 0.02 % kg.m^2

%% Construct state space
A = [-R/L -Kb/L; Km/tau -Kf/tau];
B = [1/L; 0];
C = [0 1];
D = [0];

%% Create state space
motor_dc_SS = ss(A,B,C,D)

%% Konversi antar Model
% Dari state space ke transfer function
motor_dc_TF = tf(motor_dc_SS)
% Dari state space ke zero-pole-gain
motor_dc_ZPK = zpk(motor_dc_SS)
% Dari transfer function ke zero-pole-gain
motor_dc_ZPK1 = zpk(motor_dc_TF)
% Dari transfer function ke state space
motor_dc_SS1 = ss(motor_dc_TF)
% Dari zero-pole-gain ke state space
motor_dc_SS2 = ss(motor_dc_ZPK)
% Dari zero-pole-gain ke transfer function
motor_dc_TF1 = tf(motor_dc_ZPK)

%% Plot
clf
[x1,t1] = step(motor_dc_SS); % Step respon
plot(t1,x1,'-b','LineWidth', 3)
hold on
[x2,t2] = step(motor_dc_TF);
plot(t2,x2,'-.g','LineWidth', 3)
hold on
[x3,t3] = step(motor_dc_ZPK);
plot(t3,x3,'.k','LineWidth', 3)
legend({'State Space','Transfer Function', 'Zero Pole Gain'})