Filter löschen
Filter löschen

How to remove spikes without modifying the dataset?

39 Ansichten (letzte 30 Tage)
Andrea Cecilia
Andrea Cecilia am 22 Mär. 2021
Beantwortet: Star Strider am 22 Mär. 2021
Hi,
I need to remove spikes from a signal, but I don't want to modify the dataset. Using the medfilt1 function, it can remove spikes but it also interpolates all the dataset. As an example, given the following dataset
data = [1,2,10,1,3,2,1,2];
the function gives
>> medfilt1(data)
ans =
1 2 2 3 2 2 2 1
but what I want is
1 2 NaN 1 3 2 1 2
i.e. I just want to remove the spike (10) replacing it with a NaN.
Is this possible in some way?
Thank you

Antworten (1)

Star Strider
Star Strider am 22 Mär. 2021
Use the isoutlier function:
data = [1,2,10,1,3,2,1,2];
TF = isoutlier(data); % Function Introduced In R2017a
data(TF) = NaN
producing:
data =
1 2 NaN 1 3 2 1 2
To keep the original ‘data’ vector, first make a copy of it, then do the analyses.

Kategorien

Mehr zu Electrophysiology finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by