[SciPy-user] Lowpass Filter
Thu Feb 5 11:34:48 CST 2009
Hi - I don't know if this what you want (I don't know how to use lp2lp or
scipy.signal), but one strategy that I have used is to convolve your signal
with a box-car function of a length equal to the inverse of your cut-off.
This is most definitely not the best filter known to man, but fwiw here is
For example (here I do a lowpass and then subtract the low-passed signal
from the original, effectively doing a quick-and-ugly highpass) :
box_car = np.ones(np.ceil(1.0/(f_c/TR))) #TR is the inverse of the sampling
frequency in the fMRI signal I am analyzing, f_c is the cutoff
box_car = box_car/(float(len(box_car)))
print('Normalizing and detrending time series')
for i in range(len(tSeries)):
#Start by applying a low-pass to the signal:
#Pad the signal on each side with the initial and terminal signal
pad_s = np.append(np.ones(len(box_car)) * tSeries[i],
pad_s = np.append(pad_s, np.ones(len(box_car)) * tSeries[i][-1])
#Filter operation is a convolution with the box-car:
conv_s = np.convolve(pad_s,box_car)
#Extract the low pass signal (by excising the central len(tSeries)
#ceil(/2.0) for cases where the tSeries has an odd number of points
#Extract the high pass signal simply by subtracting the high pass
#from the original signal:
tSeries[i] = tSeries[i][:] - s_lp + np.mean(s_lp) #add mean to make
sure that there are no negative values
tSeries[i] = tSeries[i]/np.mean(tSeries[i])-1
On Thu, Feb 5, 2009 at 9:17 AM, Marco <email@example.com> wrote:
> Hi list!
> Let's suppose a to be a 1D array with N elements.
> Basically, it's a signal of some sort.
> How do I apply a low pass filter (with selected frequency and width)
> to this signal?
> How to store the resulting, filtered, signal, in a new array?
> I had a look at lp2lp() in scipy.signal, but it returns, if I am
> right, a filter object, which then I dunno how to use to filter my
> Any ideas or pointers?
> Quando sei una human pignata
> e la pazzo jacket si è accorciata
> e non ti puoi liberare
> dai colpi di legno e di bastone
> dai petardi sul groppone
> Vinicio Capossela
> SciPy-user mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the SciPy-user