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.

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.


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

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, 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.

See Also


Was this topic helpful?