replacespikediff#

[xDespiked, Indx] = replacespikediff(x, WindowSize, spikedefineMethod, nrpeat, DespikeScaleFactor, interpMethod, dispout)

Description#

Remove spikes in the time series using a local difference of data respect to a moving average window

Inputs#

x

Input data

WindowSize=5;

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

spikedefineMethod=’ellipse’;
Method to define spike points
‘ellipse’: use both local difference and its gradient
‘circle’: use local difference only
nrpeat=1;

Number of time despiking procedure is repeating

DespikeScaleFactor=1;

Scaling a despiking threshold

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#

xDespiked

Dispiked data

Indx

Index of despiked 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;
[xDespiked,Indx]=replacespikediff(x,5,'ellipse',2,1,'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));
[xDespiked,Indx]=replacespikediff(x,5,'ellipse',1,1,'linear','yes');

References#

Goring, D. G., & Nikora, V. I. (2002). Despiking acoustic Doppler velocimeter data. Journal of Hydraulic Engineering, 128(1), 117-126.