DSPRelated.com
Forums

seeking scipy examples of swept-coefficient (time varying) filters

Started by Robert Poor March 8, 2020
I've been pleased with ease of use of the scipy.signal package for implementing bandpass filters: the `signal.butterworth()`, `signal.sosfilt_zi()` and `signal.sosfilt()` functions do just what I expect for a filter with constant center frequency and bandwidth.

But now I'd like to make the frequency and bandwidth settings be time varying functions themselves, and I'm not sure how to do that.

One nuance: I'm processing a buffer at a time, so I need to capture the filter state at the end of one buffer and re-initialize the filter state at the onset of the next.  

Can anyone offer guidance or examples on how to do that, preferably in scipy?


P.S. Acknowledging Steve Pope's observation that:

> Lattice filters are stable if the coefficients for the recursive part > of the filter are in the range (-1,+1). One can ramp between, or > even switch between two such sets of coefficients without instabilities.
... I should probably rephrase my question to "can anyone offer guidance on implementing lattice filters in scipy?"
I should have mentioned: as Steve Pope points out in:

https://groups.google.com/d/msg/comp.dsp/bAUKDSnvLzw/ejI-J-aQzusJ

> Lattice filters are stable if the coefficients for the recursive part > of the filter are in the range (-1,+1). One can ramp between, or > even switch between two such sets of coefficients without instabilities.
... I should probably rephrase my question to be "can anyone offer guidance or examples of implementing lattice filters in scipy?"
Robert Poor  <rdpoor@gmail.com> wrote:

>I should have mentioned: as Steve Pope points out in:
>https://groups.google.com/d/msg/comp.dsp/bAUKDSnvLzw/ejI-J-aQzusJ
>> Lattice filters are stable if the coefficients for the recursive part >> of the filter are in the range (-1,+1). One can ramp between, or >> even switch between two such sets of coefficients without instabilities.
>... I should probably rephrase my question to be "can anyone offer >guidance or examples of implementing lattice filters in scipy?"
I have no familiarity with scipy, unfortauntely. You may want to ask this question on Stack Exchange. Lattice filters are an excellent choice if you need to vary the coefficients on a sample by sample (or otherwise rapid) basis, but I think you said you are processing blocks of data, with coefficients fixed between blocks, so in that case any of the basic filter topologies will be equivalent. One the other hand, if after filtering, you need to "stitch" the blocks together, and want to do some sort of smothing between blocks so that there is not a glitch, lattice topology might make that easiter. Steve
On Monday, March 9, 2020 at 5:12:59 PM UTC-7, Steve Pope wrote:
> > ...I think you said you are processing blocks of data, with > coefficients fixed between blocks
That's half right: I am processing blocks of data, but the coefficients will be changing on a sample-by-sample basis. I think I can construct a lattice filter from first principles in scipy (with luck), so what I really need to learn is how to derive the A[n] and B[n] coefficients as a function of the human readable parameters: center frequency and bandwidth.
Robert Poor  <rdpoor@gmail.com> wrote:

>That's half right: I am processing blocks of data, but the coefficients >will be changing on a sample-by-sample basis. > >I think I can construct a lattice filter from first principles in scipy >(with luck), so what I really need to learn is how to derive the A[n] >and B[n] coefficients as a function of the human readable parameters: >center frequency and bandwidth.
Great. That is a filter synthesis problem of which there are many methods. Steve