This is machine translation

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

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Visualize and Remove Outliers in Your Data

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.


To run this example, you must be logged in with a MathWorks Account that is licensed to use the Signal Processing Toolbox .

Read Data

Read the air temperature (in degree Celsius) stored in channel 22641 using the thingSpeakRead function.

data = thingSpeakRead(22641,'NumPoints',8000,'Fields',2,'outputFormat','table');

Remove Outliers

Remove outliers in the raw data by applying Hampel function. Specify the number of neighbors as 60 on either side of each sample of the data in the measurement window. Since temperature does not change by more than 10 degrees per hour, this setting allows for sufficient data to decide whether each point is an outlier. Specify the number of standard deviations to be 10, 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 shows the original data, the filtered data, and the outliers in the original data.

See Also