I have tried to implement an high-pass filter in python to hourly precipitation measurements. I need to filter low frequency over 24 hour.
I have modified this code from: Python High Pass Filter
import numpy as np
import pandas as pd
from pandas import Series
import csv
import matplotlib.pyplot as plt
from scipy import signal
def butter_highpass(cutoff, fs, order=5):
nyq = 0.5 * fs
normal_cutoff = cutoff / nyq
b, a = butter(order, normal_cutoff, btype='high', analog=False)
return b, a
def butter_highpass_filter(data, cutoff, fs, order=5):
b, a = butter_highpass(cutoff, fs, order=order)
y = filtfilt(b, a, data)
return y
df= pd.read_csv('pp_2010.csv', sep=',', parse_dates=['Date'])
df= df.set_index('Date')
dt=3600
fs=1/float(dt)
cutoff=1/float(dt*24)
data=np.array(df['pp/hr'])
data_fl = butter_highpass_filter(data,cutoff,fs)
plt.plot(data,label='obs')
plt.plot(data_fl,label='filtered')
plt.show()
The code is working, I have tried it with the example of the link. In my case data_fl is an array of nan's.
I think the problem is because is non-sinusoidal, but I am not sure. If this is the problem, How could I filter this dataset?
Any hints what is the mistake?
thanks