[SciPy-user] firwin upgrades
Tom K.
tpk at kraussfamily.org
Sun Apr 26 16:51:48 EDT 2009
Hi folks,
About a month ago, a feature for high / pass / stop filters was requested in
firwin (or somewhere in scipy.signal) (see
http://projects.scipy.org/scipy/ticket/902).
I'm looking at how that might be added and had a few alternatives I would
like to run by the group:
SUPPORT FOR OTHER FILTER TYPES - PROPOSALS
1) add "btype" kwarg after cutoff that may be any key of the band_dict
mapping. Allow cutoff to be a list or 1D array, and make sure that the
cutoff and btype arguments are consistent.
h = firwin(N, .1) # lowpass
h = firwin(N, .1, btype='high') # highpass
h = firwin(N, [.1, .2]) # bandpass
h = firwin(N, [.1, .2], btype='stop') # bandstop
For this, I propose the btype defaults to None, and its value would be 'low'
for length 1 cutoff, and 'pass' for length 2 cutoff, since I think bandpass
filters are more common than bandstop (maybe I am wrong though).
2) Allow cutoff to be an arbitrary length list. Only need a boolean to
indicate whether to start with a value of 0 at DC (the default), or start
with a value of 1 at DC (for highpass and bandpass filters). I propose a
new 'lowpass' boolean with default True for that in this option. For this,
the calls would be e.g.:
h = firwin(N, .1) # lowpass
h = firwin(N, .1, lowpass=False) # highpass
h = firwin(N, [.1, .2], lowpass=False) # bandpass
h = firwin(N, [.1, .2]) # bandstop
3) Same as option 2), but instead of a new boolean argument, allow "0" as
the first cutoff frequency:
h = firwin(N, .1) # lowpass
h = firwin(N, [0, .1]) # highpass
h = firwin(N, [0, .1, .2]) # bandpass
h = firwin(N, [.1, .2]) # bandstop
In each of these cases, instead of scaling by 1./sum(h, axis=0), scale by
the DTFT of the filter at the center of the first band.
What are your preferences from the above (or, suggest an alternative)?
NULL AT NYQUIST ISSUE
Also, what do we want to do about having an even length filter with a
passband at Nyquist (that is pi radians frequency)? All even length filters
have a null at pi (because h[0]-h[1]+h[2]-h[3]... = 0 for linear phase, even
length). If arguments indicate a passband at Nyquist (that is pi radians
frequency), here are some options:
a) issue a warning, increase length by 1, and return the longer filter
[this is the behavior of another popular signal processing package]
b) design the filter anyway, and issue either an error if noScale is False
(since the scaling would cause a divide by 0 - see proposal below) or a
warning if noScale is True.
SUPPORT FOR NO SCALING
Currently, the filter is scaled so that the DC value of the filter is unity.
This filter no longer minimizes the integral of the square of the error
because the scaling is not natural. I propose we provide a boolean
"noScale" argument that will allow the filter to float according to the
actual least-squares filter. How does that sound?
--
View this message in context: http://www.nabble.com/firwin-upgrades-tp23246480p23246480.html
Sent from the Scipy-User mailing list archive at Nabble.com.
More information about the SciPy-User
mailing list