Time Series with System identification toolbox
9 views (last 30 days)
Show older comments
Hi everyone, I want to create a block in Simulink that has in output the value of the data that I have. I'm using the System identification toolbox to realize the model that I will use/load in Simulink. I have only data measurement (without input) so I used the procedure for the time series. I found the models with an AR and ARMAX, the results are good (90% of fit) but now I don't understand how to continue. I tried to convert the model with the tf and ss command. I loaded these models with the LTI block of the Control toolbox (but which kind of input I have to use, I tried white noise but the results are not good). What I have to do?
CODE:
DayEx = load('MyDayData.dat'); % load day data
% DayEx = load('MyData.dat'); %load all the data
y = DayEx(:,3)./1000; %output Irradiation convert in Suns to use in PV notation
ts = 60; % The sampling interval (s)
z = iddata(y,[],ts);
set(z,'OutputName','Irradiation');
%%coefficient used to find the model with AR and ARMAX
na = 5;
nc = 5;
m1 = ar(z,na);
m2 = armax(z,[na nc]);
%%Compare the two models with the original data
figure(1)
compare(z,m1,1);
figure(2)
compare(z,m2,1);
TF = tf(m1);
SS = ss(m1);
0 Comments
Answers (2)
Rajiv Singh
on 12 Jul 2011
What is your ultimate goal? A time series model is used for prediction, not simulation. Simulink is a simulation environment where one would typically use a model that takes in external inputs to produce outputs.
If you are trying to perform prediction/forecasting in Simulink using a time series model, it will help to realize that the "input" of such a model is past measured values of itself. So your input signal is your variable y. When you use TF or SS commands as you do, you convert the time series model into an input-output model. For use in Simulink, this appears a reasonable thing to do provided you drive your model using input signal which is observed (previously collected) response values. Note that such a model will just perform one-step ahead prediction based on the input signal you provide.
Rajiv Singh
on 12 Jul 2011
Based on what you wrote your code appears to be in the right direction. After you get your model "TF", put it in Simulink using an LTI block. Use "y" as the input using a "From Workspace" source block and simulation sample time to be 1. When you run this model, the result you will obtain should be the one-step ahead prediction of the response, at least after the initial condition effects taper off.
Note that this will only perform one-step ahead prediction. For prediction of more than one steps (say, forecast N steps into future), you have to work harder - you have to understand how forecasting works. This may not be easy to explain in few words but basically it boils down to constructing a suitable model using feedback and using right initial conditions.
2 Comments
Rajiv Singh
on 19 Jul 2011
Again, for time series models, simulation is generally not what you want to do; you need prediction. So use PREDICT in place of SIM. When you call "sim(m1, e)", SIM command assumes that you want to add disturbance to your model's response (since model has 0 inputs and input signal matrix "e" has one column; see help on idmodel/sim for more info). Since m1 is a time series model, it converts the time series model m1 into an input-output model using NOISECNV command. It then simulates this model using "e" as input signal. The result you are getting is probably just garbage.
If you must use SIM (and not PREDICT) and still expect to recover the signal "y", this is what you must do:
[yp,x0,mp]=predict(m1,y,1,'init','e');
ys=sim(idss(mp{1}),y,'init',x0);
plot([y ys])
ys is same as yp. mp{1} is the model you are interested in. In Simulink use idss(mp{1}) as model, x0 as initial conditions and "y" as input signal to get your response.
DO NOT use random noise as input and expect to retrieve your sine wave.
See Also
Categories
Find more on Data Preparation Basics in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!