ThingSpeak

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Regularize Irregularly Sampled Data

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.

Read Data

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 thingSpeakRead function to check for irregularly sampled data.

data = thingSpeakRead(12397,'NumMin',5,'Fields',4,'outputFormat','timetable'); 

Check for Irregular Sampled Data

Data in channel 12397 for the last 60 minutes is stored in data as a timetable. Use isregular function 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 startTime, stopTime and the expected 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 Data to ThingSpeak

Send the processed data to a ThingSpeak channel using the thingSpeakWrite function.

% Change the Channel ID and the '<write API key>' to send data to your channel
thingSpeakWrite(<channelID>,chirpData,'WriteKey','<write API key>');

See Also

Functions

Was this topic helpful?