I simulate the same transfer function with lsim and transfer fcn block in simulink but I ended up with different results.
In Simulink, the block diagram is shown as follows, the input signal is ua = 400sin(2*pi*50*t), the sampling frequency is 10 kHz
In matlab, the code is shown following, ua is the data from simulink and the same for ua.
sys = tf(numerator, denominator);
matlab_ia = lsim(sys, ua, t_simu);
Technically, they're exact the same with no differences, but when I got the error between them and drew them out, I get :
Although it's really small, it's not tolerable for my later application, which is used for PSO to find the transfer function.
Simulink transfer fcn block actually gave the closer results, but there's no PSO block in Simulink.
So I wondered why the lsim and transfer function generated different results and how I can use the lsim to get the same results as transfer function block or are there other alternative function in matlab.
There're similar questions but I didn't find those answering my questions.