How to simulate controller and plant without using simulink

조회 수: 27 (최근 30일)
Windell
Windell 2017년 8월 4일
답변: Robert U 2017년 8월 11일
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.

답변 (1개)

Robert U
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

카테고리

Help CenterFile Exchange에서 Dynamic System Models에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by