I am having a hard time trying to find documentation to implement band-pass or high-pass filter with python/scipy/numpy.
I can easily create and apply a low-pass filter, though, so I ask:
Would it be conceptually correct to low-pass-filter a signal, then subtract the result from the original signal, in order to get just the high-frequencies?
Also, if anyone has a simple example of a naive bandpass filter in Python (preferrably using the numpy and scipy libraries), I'd be very thankful.
What I look for is something like:
filtered_signal = band_pass(original_signal, rate, low=20, high=500)
Thanks for any help!
EDIT: with scipy, I'm using this as low-pass, with good results:
import numpy, scipy.signal
def firfilt(interval, freq, sampling_rate):
nfreq = freq/(0.5*sampling_rate)
taps = sampling_rate + 1
a = 1
b = scipy.signal.firwin(taps, cutoff=nfreq)
firstpass = scipy.signal.lfilter(b, a, interval)
## second pass to compensate phase delay
secondpass = scipy.signal.lfilter(b, a, firstpass[::-1])[::-1]
return secondpass
scipy.signal.firwin
tells how to make low-pass, high-pass, band-pass, band-stop, and multi-band filters. Did you tryfirwin(taps, cutoff=nfreq, pass_zero=False)
? $\endgroup$