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

13 views (last 30 days)
Bill Tubbs
Bill Tubbs on 18 Aug 2020
Edited: Bill Tubbs on 18 Aug 2020
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?

Accepted Answer

Bill Tubbs
Bill Tubbs on 18 Aug 2020
Edited: Bill Tubbs on 18 Aug 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).
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)

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by