Simple Python Median Filter for time series

5.6k views Asked by At

I have a time series in a log file having the following form (timestamp, value) :

1433787443, -60 1433787450, -65 1433787470, -57 1433787483, -70

Is there any available python code/library that takes as input the log file and a window size, apply a median filter to the time series to remove noise and outliers, and outputs the filtered signal to a new file ?

1

There are 1 answers

0
jojeck On BEST ANSWER
  1. Load the data using any method you prefer. I see that your file can be treated as csv format, therefore you could use numpy.genfromtxt('file.csv', delimiter=',') function.

  2. Use the scipy function for median filtering: scipy.signal.medfilt(data, window_len). Keep in mind that window length must be odd number.

  3. Save the results to a file. You can do it for example by using the numpy.savetxt('out.csv', data, delimiter=',') function.