How to simulate a discrete linear system model with a user-specified disturbance signal?

조회 수: 9 (최근 30일)
I'm using idpoly and sim to simulate a discrete linear system so I can compare the output with my own (hand-coded) simulation.
The problem is sim generates a new noise signal whereas I want it to use the noise signal I already generated for my simulation.
% My noise signal
Vq = 0.001; % variance
e = sqrt(Vq)*randn(nT+1,1);
% Control signal will be stored here
u = zeros(nT+1,1);
% Hand-coded control loop simulation
% <code for hand-coded simulation is here>
% Check my simulation with MATLAB
sys = idpoly(A,B,C,D,1,Vq,1,'IODelay',d)
opt = simOptions('AddNoise',true);
y_chk = sim(sys,u,opt);
Is there a way to specify the disturbance signal or alternatively, extract or generate the same noise signal used by sim so I can use it for both simulations?

채택된 답변

Bill Tubbs
Bill Tubbs 2020년 8월 18일
편집: Bill Tubbs 2020년 8월 18일
I found the answer in the documentation:
opt = simOptions('AddNoise',true,'NoiseData',e);
Turns out I was looking at the wrong documentation. There are at least three different versions of the sim function and I was reading the documentation for the wrong one:
  1. simOut = sim(model) from Simulink
  2. sim(MPCobj,T,r) from the MPC toolbox
  3. y = sim(sys,udata) from the system identification toolbox (this is the one I am using in this question)
(There is also lsim in the system identification toolbox but I am not sure what it does different).
Footnote:
When using NoiseData with a SISO model, I realised that I have to set the model's NoiseVariance to 1 if the data in e is already adjusted to the variance of the noise signal. In other words:
sys = idpoly(A,B,C,D,1,1,1,'IODelay',d)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulation and Prediction에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by