Skip to content

Commit

Permalink
rudimental deglitch
Browse files Browse the repository at this point in the history
  • Loading branch information
maurov committed Apr 13, 2018
1 parent 808a78f commit f7646f9
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions sloth/math/deglitch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""Deglitch utility"""

import numpy as np
import pandas as pd

def remove_spikes(x_data, y_spiky_data, threshold=3):
# convert data to pandas DataFrame
df = pd.DataFrame(y_spiky_data);
df['filtered'] = pd.rolling_median(df, window=3, center=True).fillna(method='bfill').fillna(method='ffill')
diff = df['filtered'].as_matrix()-y_spiky_data
mean = diff.mean()
sigma = (y_spiky_data-mean)**2
sigma = np.sqrt(sigma.sum()/float(len(sigma)))
ynew = np.where(abs(diff) > threshold * sigma, df['filtered'].as_matrix(), y_spiky_data)
return ynew

0 comments on commit f7646f9

Please sign in to comment.