Time Series with System identification toolbox

9 views (last 30 days)
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);

Answers (2)

Rajiv Singh
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.
  1 Comment
Mario
Mario on 12 Jul 2011
Dear Rajiv,
thank you really much for the reply. What I want to do is:
- create a model of the data (in my case annually irradiance measurement)
- I want to create a block in Simulink that has in output the same value of the measurement (and if it's possible can forecast the successive value)
For the first goal I use the ar and armax function to find the model, I compare the model and the data and the fit are pretty good.
For the second goal I don't know how to do it.
A simplify example of my problem is to create a block that as a sine in output using the code below.
x = [1:0.1:100]';
y = sin(x);
ts = 1;
z = iddata(y,[],ts);
na = 2;
nc = 2;
m1=ar(z,na);
m2 = armax(z,[na nc]);
figure(1)
compare(z,m1,1);
figure(2)
compare(z,m2,1);
TF = tf(m1);
Thank you

Sign in to comment.


Rajiv Singh
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
Mario
Mario on 18 Jul 2011
Dear Rajiv,
thank you for the advice, I follow the steps but the result are different from what I expected. However, I saw that I can obtain the same result with the command "sim()" in MATLAB's workspace.
So, why if I use the follow code the result are not a sine?
x = [1:0.1:100]';
y = sin(x);
n = length(y);
ts = 1;
z = iddata(y,[],ts);
na = 2;
nc = 2;
m1=ar(z,na);
e = iddata([],randn(n,1));
test = sim(m1,e);
plot(test)
I'm thinking that the idpoly model can simulate the behaviour of the data, so I will have in the output the same data right? If I'm right I don't understand how to use the model to obtain this results.
For the prediction I resolve it using a script that you write here http://www.mathworks.se/matlabcentral/newsreader/view_thread/242914
Thank you
Rajiv Singh
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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!