replaceoutlier#

[xReplaced, outlier_Indx] = replaceoutlier(x, WindowSize, zscore_threshold, interpMethod, dispout)

Description#

Remove outliers in the time series using moving z-score window

Inputs#

x

Input data

WindowSize=15;

Window size (number of adjacent elements) that is used for moving window, should be equal or larger than 3

zscore_threshold=2;
z-score threshold to define outliers
data in range of x < (xmean-zscore_threshold*std) or x > (xmean+zscore_threshold*std) considered outliers
interpMethod=’linear’;
Interpolation method for replacing spike points:
Matlab/Octave: ‘linear’, ‘nearest’, ‘next’, ‘previous’, ‘pchip’, ‘cubic’, ‘spline’
Python/Scipy : ‘linear’, ‘nearest’, ‘zero’, ‘slinear’, ‘quadratic’, ‘cubic’
dispout=’no’;

Define to display outputs or not (‘yes’: display, ‘no’: not display)

Outputs#

xReplaced

Replaced data

outlier_Indx

Logical index of replaced points

Examples#

fs=128;
t(:,1)=linspace(0,9.5,10*fs);
x(:,1)=sin(2*pi*0.3*t)+0.1*sin(2*pi*4*t);
spikeloc(:,1)=[10:100:length(t(:,1))];
x(spikeloc+round(2*randn(length(spikeloc(:,1)),1)),1)=sign(randn(length(spikeloc(:,1)),1));
x(220:225,1)=1.5;
x=x+5;
[xReplaced,outlier_Indx]=replaceoutlier(x,37,2,'linear','yes');

fs=2;
t(:,1)=linspace(0,1023.5,1024*fs);
x(:,1)=detrend(0.5.*cos(2*pi*0.2*t)+(-0.1+(0.1-(-0.1))).*rand(1024*fs,1));
spikeloc(:,1)=[10:100:length(t(:,1))];
x(spikeloc+round(2*randn(length(spikeloc(:,1)),1)),1)=sign(randn(length(spikeloc(:,1)),1));
[xReplaced,outlier_Indx]=replaceoutlier(x,21,2,'linear','yes');

References#