I have noticed that scipy.signal lacks the simplest class of IIR filters
(in fact the one I use most frequently). Specifically: - RC (single-pole) - Notch - Band-pass (inverted notch) - Anti-DC (zero at DC) These are of course very easy to construct and use with sp.signal.filter (and/or filtfilt). But I think it might be beneficial for some users to have them in scipy. Due to their size, they can be make a bit faster by running the loop in Cython instead of using sp.signal.filter (though I've never had use for this optimization). Would this be a useful contribution? Sturla _______________________________________________ SciPy-User mailing list [hidden email] http://mail.scipy.org/mailman/listinfo/scipy-user |
On Oct 29, 2012, at 8:09 AM, Sturla Molden wrote: > I have noticed that scipy.signal lacks the simplest class of IIR filters > (in fact the one I use most frequently). Specifically: > > - RC (single-pole) > - Notch > - Band-pass (inverted notch) > - Anti-DC (zero at DC) > > These are of course very easy to construct and use with sp.signal.filter > (and/or filtfilt). But I think it might be beneficial for some users to > have them in scipy. > > Due to their size, they can be make a bit faster by running the loop in > Cython instead of using sp.signal.filter (though I've never had use for > this optimization). > > Would this be a useful contribution? I think so. -Travis > > > Sturla > > > > > > > > > > > > > > > > _______________________________________________ > SciPy-User mailing list > [hidden email] > http://mail.scipy.org/mailman/listinfo/scipy-user _______________________________________________ SciPy-User mailing list [hidden email] http://mail.scipy.org/mailman/listinfo/scipy-user |
This would be great- I've built some filters (for electrophysiology
and imaging time series) but more directed standard filters would be very convenient. Filter design is complex and intimidating to dive into. Let me know if I can help ag On Oct 29, 2012, at 11:56, Travis Oliphant <[hidden email]> wrote: > > On Oct 29, 2012, at 8:09 AM, Sturla Molden wrote: > >> I have noticed that scipy.signal lacks the simplest class of IIR filters >> (in fact the one I use most frequently). Specifically: >> >> - RC (single-pole) >> - Notch >> - Band-pass (inverted notch) >> - Anti-DC (zero at DC) >> >> These are of course very easy to construct and use with sp.signal.filter >> (and/or filtfilt). But I think it might be beneficial for some users to >> have them in scipy. >> >> Due to their size, they can be make a bit faster by running the loop in >> Cython instead of using sp.signal.filter (though I've never had use for >> this optimization). >> >> Would this be a useful contribution? > > I think so. > > -Travis > >> >> >> Sturla >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> _______________________________________________ >> SciPy-User mailing list >> [hidden email] >> http://mail.scipy.org/mailman/listinfo/scipy-user > > _______________________________________________ > SciPy-User mailing list > [hidden email] > http://mail.scipy.org/mailman/listinfo/scipy-user SciPy-User mailing list [hidden email] http://mail.scipy.org/mailman/listinfo/scipy-user |
In reply to this post by Travis Oliphant-6
On Mon, Oct 29, 2012 at 4:56 PM, Travis Oliphant <[hidden email]> wrote:
+1 for IIR filter code. How much faster is "a bit"? Ralf _______________________________________________ SciPy-User mailing list [hidden email] http://mail.scipy.org/mailman/listinfo/scipy-user |
On 29.10.2012 20:43, Ralf Gommers wrote:
> How much faster is "a bit"? They are so short that the extra overhead from scipy.signal.lfilter might double the run-time. On the other hand, they are so fast that it might not matter anyway. I.e. they will always be faster than other IIR filters we use with scipy.signal.lfilter. (And replicating the machinery of scipy.signal.lfilter takes a bit of work, i.e. filtering along axes, etc. So I am in favor of just computing the coefficients.) Sturla _______________________________________________ SciPy-User mailing list [hidden email] http://mail.scipy.org/mailman/listinfo/scipy-user |
On Tue, Oct 30, 2012 at 5:18 PM, Sturla Molden <[hidden email]> wrote:
Sorry for being dense, but I'm still not completely clear about what you're planning to do now. I think I should read the above as "no Cython code". Which sounds good to me. Ralf _______________________________________________ SciPy-User mailing list [hidden email] http://mail.scipy.org/mailman/listinfo/scipy-user |
On 30.10.2012 18:24, Ralf Gommers wrote:
> Sorry for being dense, but I'm still not completely clear about what > you're planning to do now. I think I should read the above as "no Cython > code". Which sounds good to me. "No Cython code" is what I meant, yes. Sturla _______________________________________________ SciPy-User mailing list [hidden email] http://mail.scipy.org/mailman/listinfo/scipy-user |
In reply to this post by andrew giessel-2
I do a lot of work in the DSP area, and could try to help.
I have code that I use to implement IIR filters (not computing coeffs, that's a different subject), but it's using boost::python c++. You could use it as a guide, I suppose. OTOH, there's not much to an IIR filter. _______________________________________________ SciPy-User mailing list [hidden email] http://mail.scipy.org/mailman/listinfo/scipy-user |
In reply to this post by ralfgommers
On 30.10.2012 18:24, Ralf Gommers wrote:
> > Sorry for being dense, but I'm still not completely clear about what > you're planning to do now. I think I should read the above as "no Cython > code". Which sounds good to me. The code is very simple, though it will also need analog filter design, error checking, proper documentation, and tests. Sturla import numpy as np def RC(Wn, btype='low'): """ digital equivalent of an RC circuit """ f = Wn/2.0 x = exp(-2*np.pi*f) if btype == 'low': b,a = np.zeros(2),np.zeros(2) b[0] = 1.0 - x b[1] = 0.0 a[0] = 1.0 a[1] = - x elif btype = 'high': b,a = np.zeros(2),np.zeros(2) b[0] = (1.0+x)/2.0 b[1] = -(1.0+x)/2.0 a[0] = 1.0 a[1] = - x else: raise ValueError, "btype must be 'low' or 'high'" return b,a def notch(Wn, bandwidth): """ Notch filter to kill line-noise. """ f = Wn/2.0 R = 1.0 - 3.0*(bandwidth/2.0) K = ((1.0 - 2.0*R*np.cos(2*np.pi*f) + R**2)/(2.0 - 2.0*np.cos(2*np.pi*f))) b,a = np.zeros(3),np.zeros(3) a[0] = 1.0 a[1] = - 2.0*R*np.cos(2*np.pi*f) a[2] = R**2 b[0] = K b[1] = -2*K*np.cos(2*np.pi*f) b[2] = K return b,a def narrowband(Wn, bandwidth): """ Narrow-band filter to isolate a single frequency. """ f = Wn/2.0 R = 1.0 - 3.0*(bandwidth/2.0) K = ((1.0 - 2.0*R*np.cos(2*np.pi*f) + R**2)/(2.0 - 2.0*np.cos(2*np.pi*f))) b,a = np.zeros(3),np.zeros(3) a[0] = 1.0 a[1] = - 2.0*R*np.cos(2*np.pi*f) a[2] = R**2 b[0] = 1.0 - K b[1] = 2.0*(K-R)*np.cos(2*np.pi*f) b[2] = R**2 - K return b,a _______________________________________________ SciPy-User mailing list [hidden email] http://mail.scipy.org/mailman/listinfo/scipy-user |
Free forum by Nabble | Edit this page |