Reply by Tim Wescott June 22, 20112011-06-22
On 06/22/2011 09:50 AM, glen herrmannsfeldt wrote:
> ombz<andreas.weiskopf@n_o_s_p_a_m.gmail.com> wrote: >> Vladimir, Tim, Michael, > >> Thank you for your helpful answers. As Tim pointed out correctly, >> the aim has been a "hard switch", from one to the next sample. > > It seems to me that a hard switch is dangerous if the goal > is a low-pass filter. Even if you remove all the filter > artifacts, there is still a discontinuity with high frequency > components that, I would think, shouldn't be there.
That's what I would expect. In audio-land, you'd switch and you'd hear a pop or a click. OTOH, if such a discontinuity is acceptable it certainly makes the system design easy.
>> I think I'll have to evaluate options 1 to 3 in detail. I've already >> implemented the 2nd option with a cross fade on 1 sample, but >> the artifacts are still visible. Some more samples to cross-fade >> might do the thing. Option 1 might do it as well. I think option >> 3 would be too much computation*. Same holds for zero-cross check : >> I think it involves too much computation. > > It seems useful to consider the way an analog filter might work. > > You could switch between the outputs of two analog filters, > or you could switch different resistors and/or capacitors > into a filter circuit. If you switch capacitors, you should > consider the effect of the charge on the capacitor at switch time. > > If you switch capacitors such that the voltage on the capacitor is > the same, it seems that might minimize the transient. > > In both an IIR digital filter and an active analog filter, > (expecially one with negative feedback) there are artifacts > due to the value in the feedback at the time of the switch. > > -- glen
-- Tim Wescott Wescott Design Services http://www.wescottdesign.com Do you need to implement control loops in software? "Applied Control Theory for Embedded Systems" was written for you. See details at http://www.wescottdesign.com/actfes/actfes.html
Reply by glen herrmannsfeldt June 22, 20112011-06-22
ombz <andreas.weiskopf@n_o_s_p_a_m.gmail.com> wrote:
> Vladimir, Tim, Michael,
> Thank you for your helpful answers. As Tim pointed out correctly, > the aim has been a "hard switch", from one to the next sample.
It seems to me that a hard switch is dangerous if the goal is a low-pass filter. Even if you remove all the filter artifacts, there is still a discontinuity with high frequency components that, I would think, shouldn't be there.
> I think I'll have to evaluate options 1 to 3 in detail. I've already > implemented the 2nd option with a cross fade on 1 sample, but > the artifacts are still visible. Some more samples to cross-fade > might do the thing. Option 1 might do it as well. I think option > 3 would be too much computation*. Same holds for zero-cross check : > I think it involves too much computation.
It seems useful to consider the way an analog filter might work. You could switch between the outputs of two analog filters, or you could switch different resistors and/or capacitors into a filter circuit. If you switch capacitors, you should consider the effect of the charge on the capacitor at switch time. If you switch capacitors such that the voltage on the capacitor is the same, it seems that might minimize the transient. In both an IIR digital filter and an active analog filter, (expecially one with negative feedback) there are artifacts due to the value in the feedback at the time of the switch. -- glen
Reply by Vladimir Vassilevsky June 22, 20112011-06-22

ombz wrote:

> Vladimir, Tim, Michael, > > Thank you for your helpful answers. As Tim pointed out correctly, the aim > has been a "hard switch", from one to the next sample. > I think I'll have to evaluate options 1 to 3 in detail. I've already > implemented the 2nd option with a cross fade on 1 sample, but the artifacts > are still visible. Some more samples to cross-fade might do the thing. > Option 1 might do it as well. I think option 3 would be too much > computation*. Same holds for zero-cross check : I think it involves too > much computation.
Zero cross check is preferred option if the filter is implemented in the hardware. All you have to do is reload a coefficient on toggle of the sign bit of the corresponding data. Vladimir Vassilevsky DSP and Mixed Signal Design Consultant http://www.abvolt.com
Reply by ombz June 22, 20112011-06-22
Vladimir, Tim, Michael,

Thank you for your helpful answers. As Tim pointed out correctly, the aim
has been a "hard switch", from one to the next sample.

I think I'll have to evaluate options 1 to 3 in detail. I've already
implemented the 2nd option with a cross fade on 1 sample, but the artifacts
are still visible. Some more samples to cross-fade might do the thing.
Option 1 might do it as well. I think option 3 would be too much
computation*. Same holds for zero-cross check : I think it involves too
much computation.

I don't fully understand option 5: would I have to add a all-pass stage
after the Butterworth, in order to linearize phase, and then I'd see less
artifacts?

Best regards,
Andreas

* In fact I don't have to filter 1 signal but up to 4096 at a time where
some of them remain filtered at fc0 and others will be submitted to switch
to be filtered at fc1 - or they remain at fc1 and will be filtered at fc0.



>There's a form which is basically two all-pass filters added together >which has the virtue of the "state energy" being evenly distributed in >the z^-1 which is much more tolerant of coefficients changing (though >you would still probably want to change them a little bit with e.g. >each sample, over a period of a few milliseconds. > >HTH, > >-Michael > > >On Jun 20, 4:18=A0am, "ombz" <andreas.weiskopf@n_o_s_p_a_m.gmail.com> >wrote: >> Hi everybody >> >> I'd like to have a 2nd order low-pass filter with real-time
controllable
>> cut-off frequency (fc). I am working on a 16-bit fixed-point processor
an=
>d >> therefore I've chosen a DF2 SOS structure to implement a Butterworth
LPF.
>> In order to simplify things, I've made up a table containing g, a1 and
a2
>> of the filter for different cut-off frequencies =3D fn*(0.006250,
0.00625=
>0, >> 0.012500, 0.025000, 0.050000 etc.) with fn =3D fs/2. So far so good,
the
>> filter works for the different fc alone. >> But when I try to switch the fc on the fly, I have overflow problems in
t=
>he >> output for several dozens (up to some hundreds) of samples until the
resu=
>lt >> is stable again. >> I think the problem might be due to the DF2 and the states are
different
>> between the different fc and therefore I'd have to reset the states
when
>> switching fc. Indeed this solves the overflow problem. But I don't like
t=
>he >> fact of resetting the filter states since this introduces a "gap" in
the
>> output. >> Is there any possibility to implement to controllable fc more >> properly/correctly? >> >> Thank you a lot for your help >> >> Andreas > >
Reply by Michael Shonle June 20, 20112011-06-20
There's a form which is basically two all-pass filters added together
which has the virtue of the "state energy" being evenly distributed in
the z^-1 which is much more tolerant of coefficients changing (though
you would still probably want to change them a little bit with e.g.
each sample, over a period of a few milliseconds.

HTH,

-Michael


On Jun 20, 4:18=A0am, "ombz" <andreas.weiskopf@n_o_s_p_a_m.gmail.com>
wrote:
> Hi everybody > > I'd like to have a 2nd order low-pass filter with real-time controllable > cut-off frequency (fc). I am working on a 16-bit fixed-point processor an=
d
> therefore I've chosen a DF2 SOS structure to implement a Butterworth LPF. > In order to simplify things, I've made up a table containing g, a1 and a2 > of the filter for different cut-off frequencies =3D fn*(0.006250, 0.00625=
0,
> 0.012500, 0.025000, 0.050000 etc.) with fn =3D fs/2. So far so good, the > filter works for the different fc alone. > But when I try to switch the fc on the fly, I have overflow problems in t=
he
> output for several dozens (up to some hundreds) of samples until the resu=
lt
> is stable again. > I think the problem might be due to the DF2 and the states are different > between the different fc and therefore I'd have to reset the states when > switching fc. Indeed this solves the overflow problem. But I don't like t=
he
> fact of resetting the filter states since this introduces a "gap" in the > output. > Is there any possibility to implement to controllable fc more > properly/correctly? > > Thank you a lot for your help > > Andreas
Reply by Tim Wescott June 20, 20112011-06-20
On 06/20/2011 05:19 AM, Vladimir Vassilevsky wrote:
> > > ombz wrote: >> Hi everybody >> >> I'd like to have a 2nd order low-pass filter with real-time controllable >> cut-off frequency (fc). I am working on a 16-bit fixed-point processor >> and >> therefore I've chosen a DF2 SOS structure to implement a Butterworth LPF. >> In order to simplify things, I've made up a table containing g, a1 and a2 >> of the filter for different cut-off frequencies = fn*(0.006250, 0.006250, >> 0.012500, 0.025000, 0.050000 etc.) with fn = fs/2. So far so good, the >> filter works for the different fc alone. >> But when I try to switch the fc on the fly, I have overflow problems >> in the >> output for several dozens (up to some hundreds) of samples until the >> result >> is stable again. >> I think the problem might be due to the DF2 and the states are different >> between the different fc and therefore I'd have to reset the states when >> switching fc. Indeed this solves the overflow problem. But I don't >> like the >> fact of resetting the filter states since this introduces a "gap" in the >> output. >> Is there any possibility to implement to controllable fc more >> properly/correctly? > > There are 4 common ways to minimize artifacts when changing the filter > coefficients on the fly. Which one is the best depends on your hardware > and requirements. > > 1. Fade in the signal, change coefficients, fade out. > 2. Make two filters: "old" and "new" working in parallel. Fade in the > old filter, fade out the new. > 3. Interpolate the coefficients so the change is smooth. > 4. Change a coefficient when the signal value which is multiplied by > this coefficient is crossing zero.
It seems that there's a fifth option, based on an observer canonical form (see "Linear Systems", Kailath, Prentice-Hall, 1980, pp 35-37). But I'm too lazy to flesh it out right now... -- Tim Wescott Wescott Design Services http://www.wescottdesign.com Do you need to implement control loops in software? "Applied Control Theory for Embedded Systems" was written for you. See details at http://www.wescottdesign.com/actfes/actfes.html
Reply by Tim Wescott June 20, 20112011-06-20
On 06/20/2011 05:40 AM, glen herrmannsfeldt wrote:
> ombz<andreas.weiskopf@n_o_s_p_a_m.gmail.com> wrote: > >> Thanks for your fast reply. I was thinking of the same thing. And in my >> opinion what you propose should work. The problem is that I should be able >> to switch from one sample to another. In a simplified case there might only >> be 2 distinct fc. >> Therefore I'll try the following: >> - having 2 filters for the 2 fc >> - in case of switch I'll chose simply the output of the selected fc > > The exact effect of a linear combination of two filters isn't > so obvious to me. It might not be so hard to compute the > effect, though. > > You could either precompute, in a big table, the interpolation > values between the two, or generate them as needed. Also, the > speed to do the transition isn't so obvious.
I think the OP is talking about a hard switch, from one sample to the next. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com Do you need to implement control loops in software? "Applied Control Theory for Embedded Systems" was written for you. See details at http://www.wescottdesign.com/actfes/actfes.html
Reply by glen herrmannsfeldt June 20, 20112011-06-20
ombz <andreas.weiskopf@n_o_s_p_a_m.gmail.com> wrote:
 
> Thanks for your fast reply. I was thinking of the same thing. And in my > opinion what you propose should work. The problem is that I should be able > to switch from one sample to another. In a simplified case there might only > be 2 distinct fc. > Therefore I'll try the following: > - having 2 filters for the 2 fc > - in case of switch I'll chose simply the output of the selected fc
The exact effect of a linear combination of two filters isn't so obvious to me. It might not be so hard to compute the effect, though. You could either precompute, in a big table, the interpolation values between the two, or generate them as needed. Also, the speed to do the transition isn't so obvious. -- glen
Reply by Vladimir Vassilevsky June 20, 20112011-06-20

ombz wrote:
> Hi everybody > > I'd like to have a 2nd order low-pass filter with real-time controllable > cut-off frequency (fc). I am working on a 16-bit fixed-point processor and > therefore I've chosen a DF2 SOS structure to implement a Butterworth LPF. > In order to simplify things, I've made up a table containing g, a1 and a2 > of the filter for different cut-off frequencies = fn*(0.006250, 0.006250, > 0.012500, 0.025000, 0.050000 etc.) with fn = fs/2. So far so good, the > filter works for the different fc alone. > But when I try to switch the fc on the fly, I have overflow problems in the > output for several dozens (up to some hundreds) of samples until the result > is stable again. > I think the problem might be due to the DF2 and the states are different > between the different fc and therefore I'd have to reset the states when > switching fc. Indeed this solves the overflow problem. But I don't like the > fact of resetting the filter states since this introduces a "gap" in the > output. > Is there any possibility to implement to controllable fc more > properly/correctly?
There are 4 common ways to minimize artifacts when changing the filter coefficients on the fly. Which one is the best depends on your hardware and requirements. 1. Fade in the signal, change coefficients, fade out. 2. Make two filters: "old" and "new" working in parallel. Fade in the old filter, fade out the new. 3. Interpolate the coefficients so the change is smooth. 4. Change a coefficient when the signal value which is multiplied by this coefficient is crossing zero. Vladimir Vassilevsky DSP and Mixed Signal Design Consultant http://www.abvolt.com
Reply by ombz June 20, 20112011-06-20
Hi Glen,

Thanks for your fast reply. I was thinking of the same thing. And in my
opinion what you propose should work. The problem is that I should be able
to switch from one sample to another. In a simplified case there might only
be 2 distinct fc.
Therefore I'll try the following:
- having 2 filters for the 2 fc
- in case of switch I'll chose simply the output of the selected fc


>ombz <andreas.weiskopf@n_o_s_p_a_m.gmail.com> wrote: > >> I'd like to have a 2nd order low-pass filter with real-time
controllable
>> cut-off frequency (fc). I am working on a 16-bit fixed-point processor
and
>> therefore I've chosen a DF2 SOS structure to implement a Butterworth
LPF.
>> In order to simplify things, I've made up a table containing g, a1 and
a2
>> of the filter for different cut-off frequencies = fn*(0.006250,
0.006250,
>> 0.012500, 0.025000, 0.050000 etc.) with fn = fs/2. So far so good, the >> filter works for the different fc alone. >> But when I try to switch the fc on the fly, I have overflow problems in
the
>> output for several dozens (up to some hundreds) of samples until the
result
>> is stable again. > >I haven't actually tried this, but my thought would be that you >slowly change the coefficients over some number of cycles (samples). >That is, linearly interpolate between the two and, following the >interpolation slowly go from one to the other. > >It seems to my likely to work for slow enough, less likely as >the change is done faster. > >> I think the problem might be due to the DF2 and the states are
different
>> between the different fc and therefore I'd have to reset the states
when
>> switching fc. Indeed this solves the overflow problem. But I don't like
the
>> fact of resetting the filter states since this introduces a "gap" in
the
>> output. > >-- glen >