How to simulate controller and plant without using simulink

27 visualizzazioni (ultimi 30 giorni)
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.

Risposte (1)

Robert U
Robert U il 11 Ago 2017
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

Categorie

Scopri di più su Dynamic System Models in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by