このページは機械翻訳を使用して翻訳されました。最新版の英語を参照するには、ここをクリックします。
潮汐深度データに自己回帰モデルを当てはめる
この例では、ThingSpeak ™チャネルのデータに自己回帰 (AR) モデルを適合させ、回帰パラメーターとその不確実性を計算する方法を示します。自己回帰モデルは、自然界における時間依存のプロセスを表すために使用されます。
オックウェイベイリアルタイム潮位計のデータを読み取る
ThingSpeakチャネル50289 には、オックウェイ湾の潮汐深度に関するデータが含まれています。データは5分ごとに収集されます。チャネルのフィールド 1 には潮汐深度データが含まれています。
% Read the data using the |thingSpeakRead| function from channel 50289 on a particular day, for example, July 01, 2016.
startDate = datetime('July 1, 2016 12:01:00 AM'); endDate = datetime('July 2, 2016 12:01:00 AM'); dateRange = startDate:endDate; [data,timestamps] = thingSpeakRead(50289,'DateRange',dateRange,'Fields',1);
データにARモデルを適合させる
iddata 関数を使用して、潮汐深度データの iddata オブジェクトを作成します。データの平均がゼロであることを確認するには、detrend を使用します。
sampleTime = 5; IDdata = iddata(data,[],sampleTime,'OutputName',{'Tidal Depth'},'TimeUnit','minutes') IDdata = detrend(IDdata,0);
IDdata =
Time domain data set with 288 samples.
Sample time: 5 minutes
Outputs Unit (if specified)
Tidal Depth
モデルをデータに適合
潮の深さは時間とともに変化するため、ar 関数を使用して離散時間自己回帰モデルをデータに適合させます。
modelOrder = 8; sys = ar(IDdata,modelOrder)
sys =
Discrete-time AR model: A(z)y(t) = e(t)
A(z) = 1 - 1.154 z^-1 - 0.1668 z^-2 + 0.2144 z^-3 + 0.2974 z^-4
- 0.4227 z^-5 + 0.1509 z^-6 - 0.1612 z^-7 + 0.2491 z^-8
Sample time: 5 minutes
Parameterization:
Polynomial orders: na=8
Number of free coefficients: 8
Use "polydata", "getpvec", "getcov" for parameters and their uncertainties.
Status:
Estimated using AR ('fb/now') on time domain data "IDdata".
Fit to estimation data: 98.5%
FPE: 0.04741, MSE: 0.04485
パラメーターを表示
getpvec 関数を使用して、推定されたパラメーターとその不確実性を表示します。
[Parameters,Uncertainties] = getpvec(sys)
Parameters =
-1.1543
-0.1668
0.2144
0.2974
-0.4227
0.1509
-0.1612
0.2491
Uncertainties =
0.0580
0.0918
0.0932
0.0918
0.0921
0.0970
0.0962
0.0647
出力には、推定された AR モデルパラメーターと、推定されたパラメーターの 1 つの標準偏差値が表示されます。
ThingSpeak にパラメーターを書き込む
thingSpeakWrite 関数を使用して、フィールドごとに 1 つの値を持つ値の配列を ThingSpeak に書き込みます。データを 8 x 1 に転置します。channelID と writeAPIKey を変更して、データをチャネルに送信します。
channelID=17504; writeAPIKey='23ZLGOBBU9TWHG2H'; response = thingSpeakWrite(channelID,'Values',Parameters','WriteKey',writeAPIKey)
response =
struct with fields:
Field1: '-1.154266029802091'
Field2: '-0.1668388400729965'
Field3: '0.2143807521019717'
Field4: '0.2973816840220466'
Field5: '-0.4226981725238166'
Field6: '0.1509427726183032'
Field7: '-0.1612303290788889'
Field8: '0.2490548535561231'
Latitude: []
Longitude: []
ChannelID: 17504
Created: 10-Jan-2019 15:10:41
LastEntryID: 20736
Altitude: []
参考
関数
thingSpeakRead|iddata(System Identification Toolbox) |detrend(System Identification Toolbox) |ar(System Identification Toolbox) |getpvec(System Identification Toolbox)