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

10 vues (au cours des 30 derniers jours)
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?

Réponse acceptée

Bill Tubbs
Bill Tubbs le 18 Août 2020
Modifié(e) : Bill Tubbs le 18 Août 2020
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)

Plus de réponses (0)

Catégories

En savoir plus sur Simulation and Prediction dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by