I am trying to do fft for removing noise from the signal. While doing that I am getting frequency domain like thisfreq_domain:
So when applying butter pass filter to the peak freq of the signal is over smoothing like this original image:
image after applying butter pass filter:
So I am stuck at this and want to figure out the solution for reducing over smoothing in the signal
for i in range(data_first_interval.shape[0]):
ppgwave=data_first_interval.loc[i]
ppg_fit=fftpack.fft(np.array(ppgwave))
ppgarr=np.array(ppgwave)
amp=2 / time_vec.size*np.abs(ppg_fit)
sample_freq=fftpack.fftfreq(2100,0.001)
signal_amplitude = pd.Series(amp).nlargest(2).round(0).astype(int).tolist()
magnitudes = abs(ppg_fit[np.where(sample_freq >= 0)])
#Get index of top 2 frequencies\
peak_frequency = np.sort((np.argpartition(magnitudes, -2)[-2:])/2.1)
cutoff = peak_frequency[1]
y = butter_lowpass_filter(ppgarr, cutoff, fs, order)
data_first_interval.loc[i]=y
and my butter low pass filter is as defined below
fs = 1000.0
order = 2
def butter_lowpass_filter(data, cutoff, fs, order):
print("Cutoff freq " + str(cutoff))
nyq = 0.5 * fs # Nyquist Frequency
normal_cutoff = cutoff / nyq
# Get the filter coefficients
b, a = butter(order, normal_cutoff, btype='low', analog=False)
y = filtfilt(b, a,data)
return y
Can anyone help me where I am going wrong