Ajustar un modelo de autorregresión a los datos de profundidad de marea
Este ejemplo muestra cómo ajustar un modelo de autorregresión (AR) para datos en su canal ThingSpeak™ y calcular los parámetros de regresión junto con sus incertidumbres. Los modelos de autorregresión se utilizan para representar un proceso en la naturaleza que depende del tiempo.
Leer datos del mareógrafo en tiempo real de Ockway Bay
El canal ThingSpeak 50289 contiene datos sobre la profundidad de las mareas en Ockway Bay. Los datos se recopilan una vez cada 5 minutos. El campo 1 del canal contiene datos de profundidad de marea.
% 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);
Ajustar un modelo AR a los datos
Utilice la función iddata
para crear un objeto iddata de los datos de profundidad de marea. Utilice detrend
para asegurarse de que los datos tengan una media cero.
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
Ajustar modelo a datos
Dado que la profundidad de la marea varía con el tiempo, utilice la función ar
para ajustar un modelo autorregresivo de tiempo discreto a los datos.
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
Mostrar parámetros
Utilice la función getpvec
para mostrar los parámetros estimados junto con sus incertidumbres.
[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
El resultado muestra los parámetros estimados del modelo AR y el valor de una desviación estándar de los parámetros estimados.
Escribir parámetros en ThingSpeak
Utilice la función thingSpeakWrite
para escribir la matriz de valores en ThingSpeak, con un valor por campo. Transponga los datos para que sean 8 x 1. Cambia el channelID
y el writeAPIKey
para enviar datos a tu canal.
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: []
Consulte también
Funciones
thingSpeakRead
|iddata
(System Identification Toolbox) |detrend
(System Identification Toolbox) |ar
(System Identification Toolbox) |getpvec
(System Identification Toolbox)