how to use state space model?

6 次查看(过去 30 天)
Willy WOLFF
Willy WOLFF 2020-5-12
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

回答(2 个)

Emma Wilson
Emma Wilson 2020-5-13
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 2020-6-10
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.
%}

类别

Help CenterFile Exchange 中查找有关 Linear Model Identification 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by