[SciPy-User] FFT Filter

Warren Weckesser warren.weckesser@enthought....
Tue Sep 27 10:14:32 CDT 2011


On Tue, Sep 27, 2011 at 9:21 AM, Anders Harrysson <
anders.harrysson@fem4fun.com> wrote:

>  Hi,
>
> I have looked thou the example and obviously there are something that I
> simply don't get :(.  Do anyone have some good references on how to decide
> the input parameters to firwin2?
>


The text "Discrete-Time Signal Processing" by Oppenheim and Schafer is a
good reference.  In particular, the "window method" is described in Chapter
7 (7.4 or 7.5, depending on the edition).  You can try googling for "fir
filter design window method", but many of the hits will be implementations
(in Matlab, IDL, R, etc) without much explanation.

A correction to the example that I sent: the 'width' calculation did not
agree with the comment; it should have been 'width = 5.0 / nyq_rate'.



>  Furthermore, when computing he phase delay, will this differ when using a
> band pass filter instead of a low pass?
>


No.  For a symmetric FIR filter, the phase delay only depends on the number
of coefficients (ie. "taps") in the filter.


Warren



>
> Sorry for very elementary questions...
>
> Anders
>
> Warren Weckesser skrev 2011-09-27 13:53:
>
> Anders,
>
> The attached script is a variation of
> http://www.scipy.org/Cookbook/FIRFilter.  It uses firwin() to create a
> bandpass filter, and plots the frequency response and the results of
> applying the filter to a sample.  It should be straightforward to modify it
> to use firwin2() instead, if desired.
>
> The script uses scipy.signal.lfilter to apply the filter, but this isn't
> the fastest way to apply a FIR filter.  Take a look at an experiment that I
> did here http://www.scipy.org/Cookbook/ApplyFIRFilter to see a comparison
> of several way of applying a FIR filter.
>
> Regards,
>
> Warren
>
>
> On Tue, Sep 27, 2011 at 4:47 AM, Anders Harrysson <
> anders.harrysson@fem4fun.com> wrote:
>
>>  Hi,
>> Thanks a lot for the reply. I have started to look into this and currently
>> I am trying to use firwin2 to generate the filter coefficients according to
>> below
>>
>> b=signal.firwin2(512,freq,gain,nfreqs=N,nyq=nf)
>>
>> X2=signal.lfilter(b,[1.0],y)
>>
>> However I get strange results, when trying to filter even a very simple
>> signal :(. This is probably not a scipy related question, but how to put the
>> numtaps number? How is this related to the other inputs.
>>
>> Regards,
>> Anders
>>
>> Christophe Grimault skrev 2011-09-26 18:32:
>>
>> Hi Anders,
>>
>> Use : scipy.signals.lfilter(b, a, x)
>>
>> Where x is your signal (complex or real, it doesn't matter). As a filter
>> in the Fourier domain is basically FIR filter, you only need to pass the
>> b array (the response of the filter) and set a = [1.0].
>>
>> Chris
>>
>> On Sat, 2011-09-24 at 09:33 +0200, Anders Harrysson wrote:
>>
>>  Dear all,
>>
>> I am kind of new to scipy and also new to the signal processing field
>> that this question relates to.
>> I am trying to do a bandpass FFT filter using python. The filter shape
>> is symmetric around 11 Hz and is defined by the parameters ff and Hz below.
>>
>> x=loadtxt('file')
>>
>> sr = 250                    # [samples/s]
>> nf = sr/2.0                # Nyquist frequence
>> Ns = len(tr[:,0])       # Total number of samples
>> N=float(8192)          # Fourier settings
>>
>> # Fourier transform
>> X1 = fft(x,n=int(N))
>> X1 = fftshift(X1)
>> F1 = arange(-N/2.0,N/2.0)/N*sr
>>
>> # Filter
>> ff=[0,1,1,0]
>> Hz = [9.5, 10, 12, 12.5]
>> k1=interp(-F1,Hz,ff)+interp(F1,Hz,ff)
>> X1_f=X1*k1
>> X1_f=ifftshift(X1_f)
>> x1_f=ifft(X1_f,n=int(N))
>>
>> My question is now:
>> Are ther built in functionallity for filtering in scioy and, if so, how
>> would a similar filter looks like.
>>
>> Regards,
>> Anders Harrysson
>> _______________________________________________
>> SciPy-User mailing listSciPy-User@scipy.orghttp://mail.scipy.org/mailman/listinfo/scipy-user
>>
>>
>>
>> _______________________________________________
>> SciPy-User mailing list
>> SciPy-User@scipy.org
>> http://mail.scipy.org/mailman/listinfo/scipy-user
>>
>>
>
>
> _______________________________________________
> SciPy-User mailing listSciPy-User@scipy.orghttp://mail.scipy.org/mailman/listinfo/scipy-user
>
>
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20110927/baa807b5/attachment-0001.html 


More information about the SciPy-User mailing list