Lowpass filter timeseries python

110 Views Asked by At

I would like to apply a low-pass filter to my timeseries at a 3-month cutoff. The time period is 6528,5 days, saved twice a day (so 13057 time points in total). I am using the following function I found online, but I'm just not really sure what to use as cut-off and sample_rate? Also, what should I choose for the order of the filter (N)?

`def lowpass(data: np.ndarray, cutoff: float, sample_rate: float, N: int = 5):
    sos = scipy.signal.butter(N, cutoff, 'lowpass', fs=sample_rate, output='sos')
    filtered_data = scipy.signal.sosfiltfilt(sos, data)
    return filtered_data`

Many thanks!

I tried

cutoff = 1/(3*30*24*60*60)
sample_rate = 1/(2*24*60*60)

and I got this (see Figures). Something strange is happening at the beginning and end of the series. Why is this?

Original and filterd signal, limited y-axis Original and filtered signal, non-limited y-axis

0

There are 0 best solutions below