how to use state space model?

7 vues (au cours des 30 derniers jours)
Willy WOLFF
Willy WOLFF le 12 Mai 2020
Hi everybody,
I'm trying to use state-space model to do prediction at runtime.
I tryed the following code just to understand how to achieve that.
However, the manual calculation is way off of the predict command.
Note that I'm new to all of this, not sure if I really understood
state-space models, what did I miss in my calculation?
Many thanks in advance.
load iddata1 z1;
z1e = z1(1:155);
z1v = z1(156:300);
order = 1;
opt = n4sidOptions("InitialState", "zero", "Focus", "prediction");
n4sid_pf = n4sid(z1e, order, opt, "DisturbanceModel", "none");
test = n4sid_pf;
r = 42;
truth_43 = z1e.OutputData(r + 1,:)';
pred = predict(z1e(r:r+1), n4sid_pf, 1);
predict_43 = pred.OutputData(1,:);
manual_43 = test.C * (test.A * z1e.OutputData(r,:)' + test.B * z1e.InputData(r,:)');
truth_43, predict_43, manual_43
truth_43 =
1.8925
predict_43 =
4.4982
manual_43 =
-255.7701
Best Regards,
Willy

Réponses (2)

Emma Wilson
Emma Wilson le 13 Mai 2020
Hi,
I think the issue is you are using the output data as the state in the manual estimation. Instead you need to use the estimate of the state. A quick very quick example is below - note you'd probably get closer still if you used a kalman filter for your state estimation.
X(1)=0 ; %initial state,
for k=1:43 ;
X(k+1)= test.A*X(k) + test.B*z1e.InputData(k) ;
y(k)=test.C*X(k) ;
end ;
manual_43 = y(43) ;

Rajiv Singh
Rajiv Singh le 10 Juin 2020
If you want to reproduce the response of "predict" by (manual) simulation, you will need to generate the right prediction model first for the chosen prediction horizon. Note that the prediction model uses both measured inputs and measured outputs as its inputs. That is, if your original model has 2 inputs and 1 output, the predictive model will have 2+1=3 inputs and 1 output.
For 1-step ahead prediction, the prediction model is:
x(t+1) = (A-K*C)x(t) + (B-KD)u_m(t) + Ky_m(t)
y(t) = Cx(t) + Du(t)
Here u_m is measured input signal and y_m is measured output signal. x(t) is the predicted sate sequence and y(t) is the predicted response.
For prediction to horizons N> 1 steps, you can treat is as a sequence of N 1-step ahead predictions, where the results from the previous step are treated as measured output for the next step. You can also do this with a single simulation (as in the case of 1-step ahead prediction), but the model you will need to use will be more complicated. Note that the 3rd output argument of the PREDICT command returns this model. In the help content for PREDICT, you will see:
%{
[YP, X0E, MPRED] = predict(MODEL, DATA,...)
returns the estimated values of initial conditions X0E and a predictor system MPRED.
MPRED is a dynamic system whose simulation using [DATA.OutputData, Data.InputData] as input signal
yields YP.OutputData as the response ... For discrete-time data (time domain data
or frequency domain data with Ts>0), MPRED is a discrete-time system, even if
MODEL is continuous-time. If DATA is multiexperiment, MPRED is an array of Ne systems,
where Ne = number of data experiments.
%}

Catégories

En savoir plus sur Grey-Box Model Estimation dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by