Main Content

在命令行确定时间序列模型

此示例显示了如何模拟时间序列并使用参数和非参数方法来估计和比较时间序列模型。

生成模型并模拟模型输出

Generate time series data by creating and simulating an autoregressive (AR) polynomial modelts_origof the form y k = 一个 1 y k - 1 + 一个 2 y k - 2 + e k , 在哪里 e k 是随机的高斯随机过程se. This noise represents an unmeasured input to the model. Since the model is a time series, there are no measured inputs.

计算之前 e k ,初始化随机数发生器种子,以使噪声值可重复。

ts_orig = iDpoly([1 -1.75 0.9]);rng('default')e=idinput(300,'rgs');

Simulate the observed outputy_obs该模型并转换y_obs到一个iddata目的ywith 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离开

图包含一个轴对象。带有标题输入噪声和原始模型输出的轴对象包含2个类型行的对象。这些对象代表RGS噪声,模型输出。

估计模型和比较光谱

功能Etfe一个ndspa提供两种非参数技术来进行光谱分析。比较来自Etfe一个ndspato the original model.

ts_etfe = etfe(y);ts_spa = spa(y);Spectrum(TS_ETFE,TS_SPA,TS_ORIG);传奇('ts_{etfe}',,,,'ts_{spa}',,,,'ts_ {orig}'

图包含一个轴对象。The axes object with title From: e@y1 To: y1 contains 3 objects of type line. These objects represent 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 axes object with title From: e@y1 To: y1 contains 3 objects of type line. These objects represent ts\_{spa}, ts\_{ar}, 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'

图包含一个轴对象。轴对象包含3个类型行的对象。这些对象代表ry_ {orig},ry_ {ar},ry。

估计的AR模型的协方差,RY_ar,更接近原始协方差ry_orig

Predict and Compare Model Outputs

使用函数比较原始模型和AR模型的三步预测精度或拟合百分比相比。Here,相比计算预测的响应ts_orig一个nd沙皇具有原始模型输出数据的模型y,假设输入不计 e k is zero. The fourth argument,3,是要预测的步骤数。

比较(y,ts_orig,ts_ar,3);

图包含一个轴对象。轴对象包含3个类型行的对象。这些对象代表y(y1),ts \ _orig:49.55%,ts \ _ar:49.54%。

传说中的百分比是拟合百分比,代表了合适的优点。即使对于原始模型,预测准确性也远非100%,因为未测量的模型输入 e k 在预测过程中不考虑。估计的AR模型的拟合值接近原始模型,表明AR模型是一个很好的估计值。

也可以看看

|||

相关示例

更多关于