How to simulate controller and plant without using simulink
27 次查看(过去 30 天)
显示 更早的评论
Hello, I have a transfer function and a controller that I would like to simulate using purely matlab. I know that I can use the step() function to simulate the step response, but I would like to generate my own trajectory and input it into my system and not use an integrator such as ode45(). In simulink I can just output the output of my system and the trajectory is plotted. How would I do the same thing in MATLAB code?
The main reason I would like to do this is that I want to feed the output of my system to modify the trajectory at the input, but at a much slower rate than the sample rate of the controller. Im finding it difficult to figuring out how to do this in simulink.
0 个评论
回答(1 个)
Robert U
2017-8-11
Hi Windell:
You can simulate the time response of dynamic systems to arbitrary inputs with lsim ( https://de.mathworks.com/help/control/ref/lsim.html?s_tid=srchtitle ).
Example for a second order lowpass filter:
%%create input signal
fs = 50e3;
time = 0:1/fs:0.2;
signal = chirp(time,100,0.2,1000,'li');
%%create system
system = tf(1,[1/(2*pi*250)^2 2/(2*pi*250) 1]);
%%simulation
[outSignal, time] = lsim(system,signal,time);
%%plot result
plot(time,[signal; outSignal'])
Kind regards,
Robert
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dynamic System Models 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!