This example shows how to detect and remove outliers in your ThingSpeak™ channel data using a Hampel filter. This filter is closely related to a median filter and it helps to remove outliers from a signal without overly smoothing the data.
Note: You must be logged in with a MathWorks Account that is licensed to use the Signal Processing Toolbox to run this example.
Read the air temperature (in degree Celsius)
stored in channel 22641 using the
data = thingSpeakRead(22641,'NumPoints',8000,'Fields',2,'outputFormat','table');
Remove outliers in the raw data by applying
Specify the number of neighbors as 60 on either side of each sample
of the data in the measurement window. Since temperature within an
hour does not change by more than 10 degrees, this setting allows
for sufficient data to decide whether each point is an outlier. Specify
the number of standard deviations to be 10, the number by which a
data point must differ from the local median for it to be replaced
with the median.
windowSize = 60; numMedians = 10; hampel(data.AirTemperatureC, windowSize, numMedians);
The plot show the original data, the filtered data and the outliers in the original data.