Difference between matlab ss function and Simulink State-Space block
14 views (last 30 days)
Show older comments
I want to do induction motor state space model simulation, so I built it with ss function and set the zero initial conditions, but after I fed it with input by lsim function, the output diverged. When I built it with simulink state-space block, fed the same input, and set the same initial conditions, it converged and got pretty good result, which made me think what's the difference between these two state space modeling methods. What aspects should I pay attention if I want to make ss in matlab converge?
Update: I attached code in matlab and SImulink block for better understanding
Simulink Block and Solver setting:
The simulink block configurations are the same in matlab
Simulink solver setting:
MATLAB code:
%% Basic Setting
f = 10000; % Sampling Frequency
Ts = 1/f;
%% Data Preparation(Not Important
out1 = out;
ab0_voltage1 = out1.voltage_ab0;
ab0_current1 = out1.current_ab0;
rotation_f1 = out1.speed;
start_time = 0;
sampling_time = 5;
start_point = start_time*f+1;
sampling_points = sampling_time*f-1;
t_ind = start_point:start_point+sampling_points;
u = ab0_voltage1(t_ind,2:3); %Input
i = ab0_current1(t_ind,2:3);
flux_init = out.flux_ab(start_point,2:3);
w = mean(out.w_e(end,2));
%% Parameterization of State Space A B C D
x = [6.14,0.037874419,0.387125581,4.987617956];
Rs = x(1);
lls_dot = x(2);
Lm_dot = x(3);
Rr_dot = x(4);
%% State Space modeling
A = [-Rr_dot/Lm_dot, -w, Rr_dot,0;
w, -Rr_dot/Lm_dot, 0,Rr_dot;
Rr_dot/(Lm_dot*lls_dot), w/lls_dot, -(Rr_dot+Rs)/lls_dot, 0;
-w/lls_dot, Rr_dot/(Lm_dot*lls_dot), 0, -(Rr_dot+Rs)/lls_dot];
B = [0, 0;
0, 0;
1/lls_dot, 0;
0, 1/lls_dot];
C = [zeros(2),eye(2)];
D =zeros(2);
sys = ss(A,B,C,D,Ts)
%% Response
t = 0:Ts:sampling_time-Ts;
x0 = [flux_init,i(1,1:2)]; % initial conditions setting
y = lsim(sys,u,t,x0)
7 Comments
Accepted Answer
Raymond Wong
on 6 Jul 2022
Edited: Raymond Wong
on 6 Jul 2022
11 Comments
Paul
on 7 Jul 2022
You've got it. Use c2d() to develop the discrete-time approximation to a continous-time model. Check the c2d doc page for the available options for the conversion. Good luck with rest of your project.
More Answers (2)
Fangjun Jiang
on 5 Jul 2022
Edited: Fangjun Jiang
on 5 Jul 2022
There are limited number of settings when calling lsim(sys,u,t,x0,method). You need to change the settings in Simulink to match the MATLAB simulation time vector. Most likely, choose discrete solver with fixed step size in Simulink. This is just to make the two simulation results match.
If the outputs in Simulink converge using the default settings, then the system is stable. Most likely, the step size in MATLAB is too large which caused it to diverge.
Sam Chak
on 6 Jul 2022
I have added one line after sys = ss(A,B,C,D,Ts) to determine whether system is stable or not.
isstable(sys)
isstable(sys) returns a logical value of 1 (true) if the dynamic system model sys has stable dynamics, and a logical value of 0 (false) otherwise.
See Also
Categories
Find more on Power and Energy Systems in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!