Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Signal analysis in Python - removing outliers from curve

I have the following signal to process (raw data):

enter image description here

I would like to process the signal to eliminate outliers to obtain a "smooth" curve. Note: I do not want to change any of the actual values, I am only interested in removing spurious points. A specific requirement is that the curve "wraps around" (i.e. the beginning of the curve should be contiguous with its end). A picture may be more helpful (I have manually traced the black line to illustrate):

enter image description here

So far, I have tried thresholding the function based on a distance from a moving average, but that failed pretty miserably. I have also tried computing the first derivative and thresholding based on that, which was also unhelpful. Any ideas as to how I can achieve the desired result? I remain convinced there is a relatively simple solution that I am missing here. I am using Python/NumPy/SciPy.

like image 651
user2398029 Avatar asked Aug 13 '14 19:08

user2398029


1 Answers

Use a rolling median filter from SciPy: < http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.ndimage.filters.median_filter.html >.

You could also use other forms of a rolling average or rolling order statistic filter.

like image 132
ely Avatar answered Oct 17 '22 21:10

ely