www.gusucode.com > ident 案例代码 matlab源码程序 > ident/ForecastFutureValuesofaSinusoidalSignalExample.m
%% Forecast Future Values of a Sinusoidal Signal % Forecast the values of a sinusoidal signal using an AR model. %% % Generate and plot data. data = iddata(sin(0.1*[1:100])',[]); plot(data) %% % Fit an AR model to the sine wave. sys = ar(data,2); %% % Forecast the values into the future for a given time horizon. K = 100; p = forecast(sys,data,K); %% % |K| specifies the forecasting time horizon as 100 samples. |p| is the % forecasted model response. %% % Plot the forecasted data. plot(data,'b',p,'r'), legend('measured','forecasted') %% % Alternatively, plot the forecasted output using the syntax % |forecast(sys,data,K)|.