It is worth noting that the units of your bp will not necessarily be in Hz, but depending on the sampling rate of the signal, you should use scipy.fftpack.fftfreq to convert. Also, if your signal is real, you should use scipy.fftpack.rfft . Here is a minimal working example that filters out all frequencies less than a given amount:
import numpy as np from scipy.fftpack import rfft, irfft, fftfreq time = np.linspace(0,10,2000) signal = np.cos(5*np.pi*time) + np.cos(7*np.pi*time) W = fftfreq(signal.size, d=time[1]-time[0]) f_signal = rfft(signal) # If our original signal time was in seconds, this is now in Hz cut_f_signal = f_signal.copy() cut_f_signal[(W<6)] = 0 cut_signal = irfft(cut_f_signal)
We can build the evolution of a signal in real and rangefinding space:
import pylab as plt plt.subplot(221) plt.plot(time,signal) plt.subplot(222) plt.plot(W,f_signal) plt.xlim(0,10) plt.subplot(223) plt.plot(W,cut_f_signal) plt.xlim(0,10) plt.subplot(224) plt.plot(time,cut_signal) plt.show()

Hooked
source share