Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. fs = 1652 Hz
  2. fc = 208 Hz
  3.  
  4. def fir_lowpass(data, fc, fs, nfft):
  5.  
  6. # Convert to normalized frequency
  7. fc_nor = fc / (fs / 2)
  8.  
  9. N = nfft
  10.  
  11. n = np.arange(N)
  12.  
  13. # Compute sinc filter.
  14. h = np.sinc(2 * fc * (n - (N - 1) / 2))
  15.  
  16. # Compute hanning window.
  17. w = signal.hann(N)
  18.  
  19. # Multiply sinc filter with window.
  20. h = h * w
  21.  
  22. # Normalize to get unity gain.
  23. h = h / np.sum(h)
  24.  
  25. # Apply filter to data
  26. data = np.convolve(data, h, 'same')
  27.  
  28. return data
  29.  
  30. def IIR_lowpass(data, fc, fs):
  31.  
  32. fc_nor = fc / (fs / 2) # Normalize cutoff frequency
  33.  
  34. b, a = signal.butter(5, fc_nor, btype='low', analog=False, output='ba')
  35.  
  36. filt_data = signal.filtfilt(b, a, data)
  37.  
  38.  
  39. return filt_data
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement