I am looking for a method to eliminate freak values ββfrom a given dataset. For instance:

All these peaks must be eliminated. I tried different filters like medfilt , but the peaks are still there. I also tried the low pass filter, but it didn't work either. I am new to signal filtering, so I probably did it wrong.
You can download datasets for x array here and y here .
I could also imagine a loop for comparing values ββnext to each other, but am I sure there should be an inline function?
Here is the result using medfilt1(input,15) :

The peaks disappear, but then I get these ugly steps that I don't want.
source share