This example shows how to regularize irregularly sampled data to regular sampled data with constant time period between measurements. You update timestamps of data in a ThingSpeak™ channel to remove irregularity. You can apply data preprocessing and data analytics algorithms on regularly sampled data. Hence for such applications, it is important to correct timestamp variations in measured data introduced due to network latencies.
ThingSpeak channel 12397 contains data
from the MathWorks® weather station, located in Natick,
Massachusetts. The data is collected once every minute. Field 4 of
the channel contains air temperature data. Read the air temperature
data from channel 12397 using the
to check for irregularly sampled data.
data = thingSpeakRead(12397,'NumMin',5,'Fields',4,'outputFormat','timetable');
Data in channel 12397 for the last 60 minutes
is stored in
data as a timetable. Use
to check if the channel data is regularly sampled. If data is irregularly
sampled, then generate a regularly spaced time vector for the time
period of interest. For this, use the
timePeriod between measurements to
generate the new time vector.
regularFlag = isregular(data,'Time'); if ~regularFlag startTime = data.Timestamps(1); stopTime = data.Timestamps(end); timePeriod = minutes(1); newTimeVector = startTime:timePeriod:stopTime; data.Timestamps = newTimeVector; end
Send the processed data to a ThingSpeak channel
% Change the Channel ID and the '<write API key>' to send data to your channel thingSpeakWrite(<channelID>,chirpData,'WriteKey','<write API key>');