You are on page 1of 8

J = 0.01; % Rotor moment of inertia (kg.

m^2)
b = 0.1; % Friction coefficient (N.m.s)
Ke_dc = 0.01; % Electromotive force (V/rad/sec)
Kt_dc = 0.01; % Motor torque constant (N.m/A)
R_dc = 1; % Resistance (Ohm)
L_dc = 0.5; % Inductance (H)

A_matrix = [0 1 0; 0 -b/J Kt_dc/J; 0 -Ke_dc/L_dc -R_dc/L_dc];


B_matrix = [0; 0; 1/L_dc];
C_matrix = [1 0 0];
D_matrix = 0;

system_ss = ss(A_matrix, B_matrix, C_matrix, D_matrix);


poles_dc_system = eig(A_matrix);
gain_DC = C_matrix * inv(-A_matrix) * B_matrix + D_matrix;

Warning: Matrix is singular to working precision.

[num_dc, den_dc] = ss2tf(A_matrix, B_matrix, C_matrix, D_matrix);


damping_dc_info = damp(tf(num_dc, den_dc));
zeros_dc_system = tzero(system_ss);
step_info_dc = stepinfo(system_ss);
frequency_dc = logspace(-1, 2, 100);
[magnitude_dc, phase_dc] = bode(system_ss, frequency_dc);

figure;
subplot(2, 1, 1);
semilogx(frequency_dc, 20*log10(magnitude_dc(:)));
title('Frequency Response - Magnitude');
xlabel('Frequency (rad/sec)');
ylabel('Magnitude (dB)');
grid on;
subplot(2, 1, 2);
semilogx(frequency_dc, phase_dc(:));
title('Frequency Response - Phase');
xlabel('Frequency (rad/sec)');
ylabel('Phase (degrees)');
grid on;

1
time_impulse_dc = 0:0.01:5;
impulse_response_dc = impulse(system_ss, time_impulse_dc);
figure;
plot(time_impulse_dc, impulse_response_dc);
title('Impulse Response');
xlabel('Time (seconds)');
ylabel('Amplitude');
grid on;

2
time_step_dc = 0:0.01:5;
step_response_dc = step(system_ss, time_step_dc);
figure;
plot(time_step_dc, step_response_dc);
title('Step Response');
xlabel('Time (seconds)');
ylabel('Amplitude');
grid on;

3
time_ramp_dc = 0:0.01:5;
ramp_response_dc = lsim(system_ss, time_ramp_dc, time_ramp_dc);
figure;
plot(time_ramp_dc, ramp_response_dc);
title('Ramp Response');
xlabel('Time (seconds)');
ylabel('Amplitude');
grid on;

4
disp('Motor Characteristics:');

Motor Characteristics:

disp(['State Matrix A:']);

State Matrix A:

disp(A_matrix);

0 1.0000 0
0 -10.0000 1.0000
0 -0.0200 -2.0000

disp(['Input Matrix B:']);

Input Matrix B:

disp(B_matrix);

0
0
2

disp(['Output Matrix C:']);

Output Matrix C:

disp(C_matrix);

1 0 0

5
disp(['Direct Transmission Matrix D:']);

Direct Transmission Matrix D:

disp(D_matrix);

disp(['Eigenvalues (Poles):']);

Eigenvalues (Poles):

disp(poles_dc_system);

0
-9.9975
-2.0025

disp(['Gain Analysis:']);

Gain Analysis:

disp(gain_DC);

NaN

disp(['Natural Frequency, Damping Ratio:']);

Natural Frequency, Damping Ratio:

disp(['Damping Ratio: ', num2str(damping_dc_info(:, 1)')]);

Damping Ratio: 0 2.0025 9.9975

if size(damping_dc_info, 2) > 1
disp(['Natural Frequency (rad/sec): ', num2str(damping_dc_info(:, 2)')]);
else
disp('Natural Frequency information not available.');
end

Natural Frequency information not available.

disp(['Zeros and Poles:']);

Zeros and Poles:

disp(['Poles: ', num2str(poles_dc_system')]);

Poles: 0 -9.9975 -2.0025

disp(['Zeros: ', num2str(zeros_dc_system')]);

Zeros:

disp(['Characteristics: Settling Time, Rise Time, Overshoot Percentage:']);

Characteristics: Settling Time, Rise Time, Overshoot Percentage:

6
disp(['Settling Time (sec): ', num2str(step_info_dc.SettlingTime)]);

Settling Time (sec): NaN

disp(['Rise Time (sec): ', num2str(step_info_dc.RiseTime)]);

Rise Time (sec): NaN

disp(['Overshoot (%): ', num2str(step_info_dc.Overshoot)]);

Overshoot (%): NaN

disp(['Frequency Response (Bode plot):']);

Frequency Response (Bode plot):

disp(['Frequency (rad/sec): ', num2str(frequency_dc)]);

Frequency (rad/sec): 0.1 0.1072267 0.1149757 0.1232847 0.1321941 0.1417474 0.1519911 0.1

disp(['Magnitude (dB): ', num2str(20*log10(magnitude_dc(:))')]);

Magnitude (dB): -0.01993282 -0.6276761 -1.235671 -1.843954 -2.452568 -3.061564 -3.670996

disp(['Phase (degrees): ', num2str(phase_dc(:)')]);

Phase (degrees): -93.43192 -93.67955 -93.94499 -94.2295 -94.53443 -94.86124 -95.21146 -

disp(['Impulse Response:']);

Impulse Response:

disp(['Time (sec): ', num2str(time_impulse_dc)]);

Time (sec): 0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08

disp(['Amplitude: ', num2str(impulse_response_dc')]);

Amplitude: 0 9.6101e-05 0.00036959 0.00079989 0.0013685 0.0020586 0.0028552 0.0037448 0.0047152 0.005

disp(['Step Response:']);

Step Response:

disp(['Time (sec): ', num2str(time_step_dc)]);

Time (sec): 0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08

disp(['Amplitude: ', num2str(step_response_dc')]);

Amplitude: 0 3.2354e-07 2.5131e-06 8.2378e-06 1.8972e-05 3.6012e-05 6.0498e-05 9.3426e-05 0.00013566 0.0001

disp(['Ramp Response:']);

Ramp Response:

disp(['Time (sec): ', num2str(time_ramp_dc)]);

7
Time (sec): 0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08

disp(['Amplitude: ', num2str(ramp_response_dc')]);

Amplitude: 0 8.1367e-10 1.2715e-08 6.2881e-08 1.9419e-07 4.6335e-07 9.3926e-07 1.7015e-06 2.8388e-06 4.4483

You might also like