[Scipy-tickets] [SciPy] #902: need high, stop, pass options to signal.firwin

SciPy Trac scipy-tickets@scipy....
Sat Oct 30 16:28:34 CDT 2010


#902: need high, stop, pass options to signal.firwin
----------------------------------+-----------------------------------------
 Reporter:  tpk@…                 |       Owner:  somebody    
     Type:  enhancement           |      Status:  needs_review
 Priority:  normal                |   Milestone:  0.9.0       
Component:  scipy.signal          |     Version:  0.7.0       
 Keywords:                        |  
----------------------------------+-----------------------------------------

Comment(by warren.weckesser):

 I haven't forgotten about this, but after letting it sit for a few days,
 I'm having second thoughts about the API.  In the current patch, the type
 ('pass' or 'stop') of the last band specified by the user is given by the
 btype argument, which is 'pass' by default.  This doesn't feel like the
 most natural API.  The following shows how the four most common filters
 (lowpass, highpass, bandpass, and bandstop) would be specified, for three
 different APIs.  In each group, all the examples implement the same
 filter.


 '''API 1''': The type of the last specified band is given by btype, whose
 default is 'pass'.

 ''lowpass:''

 {{{
 firwin(N, cutoff=0.5)
 firwin(N, cutoff=[0, 0.5])
 firwin(N, cutoff=[0, 0.5, 1.0], btype='stop')
 firwin(N, cutoff=[0.5, 1.0], btype='stop')
 }}}

 ''highpass:''

 {{{
 firwin(N, cutoff=0.5, btype='stop')
 firwin(N, cutoff=[0, 0.5], btype='stop')
 firwin(N, cutoff=[0.5, 1.0])
 firwin(N, cutoff=[0, 0.5, 1.0])
 }}}

 ''bandpass:''

 {{{
 firwin(N, cutoff=[0.2, 0.7])
 firwin(N, cutoff=[0, 0.2, 0.7])
 firwin(N, cutoff=[0.0, 0.2, 0.7, 1.0], btype='stop')
 firwin(N, cutoff=[0.2, 0.7, 1.0], btype='stop')
 }}}

 ''bandstop:''

 {{{
 firwin(N, cutoff=[0.2, 0.7], btype='stop')
 firwin(N, cutoff=[0, 0.2, 0.7], btype='stop')
 firwin(N, cutoff=[0.2, 0.7, 1])
 firwin(N, cutoff=[0, 0.2, 0.7, 1])
 }}}

 '''API 2''': First cutoff value begins a stop band; no additional args.

 (With this API, a final value of 1.0 in the cutoff list is always
 optional.)

 ''lowpass:''

 {{{
 firwin(N, cutoff=0.5)
 firwin(N, cutoff=[0.5])
 firwin(N, cutoff=[0.5, 1.0])
 }}}

 ''highpass:''

 {{{
 firwin(N, cutoff=[0.0, 0.5])
 firwin(N, cutoff=[0.0, 0.5, 1.0])
 }}}

 ''bandpass:''

 {{{
 firwin(N, cutoff=[0.0, 0.2, 0.7])
 firwin(N, cutoff=[0.0, 0.2, 0.7, 1.0])
 }}}

 ''bandstop:''

 {{{
 firwin(N, cutoff=[0.2, 0.7])
 firwin(N, cutoff=[0.2, 0.7, 1.0])
 }}}

 '''API 3''': A boolean argument, say 'pass_zero', specifies whether the
 gain at w=0 is 0 or 1.
 Default is True. (Matlab uses something like this for fir1.)

 With this API, including 0 or 1 in the cutoff list is always optional.

 ''lowpass:''

 {{{
 firwin(N, cutoff=0.5)
 firwin(N, cutoff=[0.5, 1.0])
 firwin(N, cutoff=[0.0, 0.5])
 firwin(N, cutoff=[0.0, 0.5, 1.0])
 }}}


 ''highpass:''

 {{{
 firwin(N, cutoff=0.5, pass_zero=False)
 firwin(N, cutoff=[0.5, 1.0], pass_zero=False)
 firwin(N, cutoff=[0.0, 0.5], pass_zero=False)
 firwin(N, cutoff=[0.0, 0.5, 1.0], pass_zero=False)
 }}}

 ''bandpass:''

 {{{
 firwin(N, cutoff=[0.2, 0.7], pass_zero=False)
 firwin(N, cutoff=[0, 0.2, 0.7], pass_zero=False)
 firwin(N, cutoff=[0.2, 0.7, 1], pass_zero=False)
 firwin(N, cutoff=[0, 0.2, 0.7, 1], pass_zero=False)
 }}}

 ''bandstop:''

 {{{
 firwin(N, cutoff=[0.2, 0.7])
 firwin(N, cutoff=[0, 0.2, 0.7])
 firwin(N, cutoff=[0.2, 0.7, 1])
 firwin(N, cutoff=[0, 0.2, 0.7, 1])
 }}}


 Any thoughts?  Better alternatives?

-- 
Ticket URL: <http://projects.scipy.org/scipy/ticket/902#comment:19>
SciPy <http://www.scipy.org>
SciPy is open-source software for mathematics, science, and engineering.


More information about the Scipy-tickets mailing list