此示例显示了如何模拟时间序列并使用参数和非参数方法来估计和比较时间序列模型。
Generate time series data by creating and simulating an autoregressive (AR) polynomial modelts_orig
of the form
, 在哪里
是随机的高斯随机过程se. This noise represents an unmeasured input to the model. Since the model is a time series, there are no measured inputs.
计算之前 ,初始化随机数发生器种子,以使噪声值可重复。
ts_orig = iDpoly([1 -1.75 0.9]);rng('default')e=idinput(300,'rgs');
Simulate the observed outputy_obs
该模型并转换y_obs
到一个iddata
目的y
with the default sample time of one second. Plot the model output together with the input noise.
y_obs = sim(ts_orig,e);y = iddata(y_obs);情节(e)保留on情节(y_obs)标题('Input Noise and Original Model Output') 传奇(“ RGS噪音”,,,,“模型输出”)hold离开
功能Etfe
一个ndspa
提供两种非参数技术来进行光谱分析。比较来自Etfe
一个ndspa
to the original model.
ts_etfe = etfe(y);ts_spa = spa(y);Spectrum(TS_ETFE,TS_SPA,TS_ORIG);传奇('ts_{etfe}',,,,'ts_{spa}',,,,'ts_ {orig}')
现在,使用AR结构估算一个参数模型。估计二阶AR模型,并将其频谱与原始模型进行比较spa
估计。
ts_ar = ar(y,2);Spectrum(TS_SPA,TS_AR,TS_ORIG);传奇('ts_{spa}',,,,'沙皇}',,,,'ts_ {orig}')
The AR model spectrum fits the original model spectrum more closely than the nonparametric models.
通过将每个模型输出与本身进行卷积,计算原始模型和AR模型的协方差函数。
ir_orig = sim(ts_orig,[1; zeros(24,1)]);ry_orig = conv(ir_orig,ir_orig(25:-1:1));ir_ar = sim(ts_ar,[1; zeros(24,1)]);ry_ar = conv(ir_ar,ir_ar(25:-1:1));
还估计协方差RY
直接从观察到的输出y
使用xcorr
。
RY=xcorr(y.y,24,“有偏见”);
绘图并比较原始和估计的协方差。
图(-24:24'*一个(1,3),[ry_orig,ry_ar,ry]);传奇('ry_ {orig}',,,,'Ry_{ar}',,,,'ry')
估计的AR模型的协方差,RY_ar
,更接近原始协方差ry_orig
。
使用函数比较原始模型和AR模型的三步预测精度或拟合百分比相比
。Here,相比
计算预测的响应ts_orig
一个nd沙皇
具有原始模型输出数据的模型y
,假设输入不计
is zero. The fourth argument,3
,是要预测的步骤数。
比较(y,ts_orig,ts_ar,3);
传说中的百分比是拟合百分比,代表了合适的优点。即使对于原始模型,预测准确性也远非100%,因为未测量的模型输入 在预测过程中不考虑。估计的AR模型的拟合值接近原始模型,表明AR模型是一个很好的估计值。