www.gusucode.com > ident 案例代码 matlab源码程序 > ident/ForecastTimeSeriesDataUsingAnARModelExample.m

    %% Forecast Time Series Data Using an AR Model
%% Forecast AR Model
% Generate and plot time series data.
past_data = iddata(sin(0.1*[1:100])',[]);
%%
% Fit an AR model to the data.
sys = ar(past_data,2);
%%
% Perform a 10-step ahead prediction to validate the model over the 
% time-span of the measured data.
yp = predict(sys,past_data,10);
%%
% Plot the predicted response and the measured data.
plot(past_data,yp)
%%
% Forecast model output 100 steps beyond the estimation data.
yf = forecast(sys,past_data,100);
%%
% Plot the past and forecasted data.
plot(past_data,'--r',yf,'b')
legend('Past Data','Forecasted Data')