-3

I am trying to do fft for removing noise from the signal. While doing that I am getting frequency domain like thisfreq_domain:

freq_domain

So when applying butter pass filter to the peak freq of the signal is over smoothing like this original image:

original image

image after applying butter pass filter:

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

  • 3
    I’m voting to close this question because it is not about programming as defined in the [help] but about signal processing theory/methodology. – desertnaut Apr 30 '21 at 22:04

1 Answers1

1

Typically the way you produce "less smoothing" is to raise the cutoff frequency.

With smoothing filters, you have two parameters to play with:

  • Cutoff: higher cutoff produces less smoothing; lower cutoff produces more smoothing.

  • Order (related to "roll off"): higher order causes less low frequency distortion, but may cause ringing. Lower order has less ringing, but may distort frequencies below the cutoff. This may also appear as over smoothing.

Owen
  • 38,836
  • 14
  • 95
  • 125