Support

If you have a problem or need to report a bug please email : support@dsprobotics.com

There are 3 sections to this support area:

DOWNLOADS: access to product manuals, support files and drivers

HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects

USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here

NEW REGISTRATIONS - please contact us if you wish to register on the forum

Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright

Experimenting with IIR filters

Post any examples or modules that you want to share here

Experimenting with IIR filters

Postby steph_tsf » Wed Jul 17, 2013 11:58 pm

This is a simple .fsm containing a few IIR filters considered as blocks, easing the construction of more elaborate filters. All IIR filters get analyzed in realtime thanks to the FFT-based Spectrum Meter and Audio Analyzer.

Experimenting with IIR filters, you will discover the limits of the Bilinear Transform used by RBJ and many other people doing Audio DSP. Define a 1st-order lowpass frequency to 12 kHz, and you'll see what I mean. The asymptot is not straight anymore. The slope is not a 1st-order anymore.

Experimenting with IIR filters, you will discover that the dubious "BiQuad" primitive present in Flowstone toolbox is not a BiQuad, but instead a 4th-order Butterwoth Lowpass. Try defining a corner frequency like 12 kHz or so. You'll see that the dubious "BiQuad" enters into trouble with the asymptot, departing from a 4th-order. This means that the RBJ maths are inside, in other words the Bilinear Transform.

The genuine BiQuad, the one that should exist in Flowstone toolbox, is the block containing no more than five knobs. Connect it on ch4 input of the Analyzer, instead of the dubious Flowstone "Biquad".

Let's experiment with the genuine BiQuad.
The five knobs are the five degrees of liberty for properly setting up any IIR BiQuad. There is nothing complicated in this. You define the corner Frequency and the Q, just as usual. Now you think you need to decide about a lowpass, a bandpass, or a highpass. Actually this is a slight misconception. Fundamentally there is no choice required. Actually you can mix a lowpass with a bandpass and a highpass the way you want, using three coefficients going from - 1 till +1. Those are the red, green, blue knobs. Let's say you need a pure lowpass. Double click on the green and blue knobs, as this will reset them to zero which is the median position in this application. Adjust the red knob to +1. Your pure lowpass is done. If you want the lowpass to be an inverting one, adjust the red knob to -1. In case your lowpass corner frequency is close to Fs/2, you will see that the asymptot is not like it should. You need to add a slight highpass contribution using the blue knob. There is an unique blue knob position, restoring the nominal asymptot slope and shape untill Fs/2. As the bilinear transform used in the BRJ math doesn't do this, you needed to do it manually.

Cheers,
Steph
Attachments
IIR Lab (600).png
IIR Lab (600).png (108.14 KiB) Viewed 38215 times
IIR Lab.fsm
(975.51 KiB) Downloaded 1571 times
steph_tsf
 
Posts: 249
Joined: Sun Aug 15, 2010 10:26 pm

Re: Experimenting with IIR filters

Postby MyCo » Thu Jul 18, 2013 1:14 am

For filter tests I would rather go the "theoretical way". With this I mean: calculate the response, instead of measuring it. I've attached a schematic where I've put your biquad into my "Filter Construction Kit". I had to change the coeffs to make it fit (you don't use signs for your a coeffs).
The filter is quite interesting, because it can give several responses at once. But when you take a closer look, you'll notice that it is extremely "jumpy". There is no smooth transition when you turn the knobs. So it won't be very useful for automation stuff. Maybe it's a good "steady" filter, so you tweak it once and let it stay.

BTW: I've noticed you use Direct Form 2 for processing. This might look nice in code, because you save some memory and therefor memory access time, but it has a major disadvantage: It introduces a lot of rounding noise! That's the major reason, why you don't see it very often in filter code written for floating point.

BTW2: In your filter code there are 2 lines that don't look right to me:
Code: Select all
input = input + epsilon;
...
input = input - epsilon;

You should never ever assign something to an input (streamin, monoin, polyin,...). This can have bad influence on any code that is compiled after your code, because it'll see different values. Also the last line (input = input - epsilon), wouldn't change anything in your code, because you don't read "input" anymore. So my tip is, do it like that:
Code: Select all
in = input + epsilon - epsilon;

Because there is no optimizer involved, this passes straight into assembler.
Attachments
Filter-test.fsm
(106.9 KiB) Downloaded 1501 times
User avatar
MyCo
 
Posts: 718
Joined: Tue Jul 13, 2010 12:33 pm
Location: Germany

Re: Experimenting with IIR filters

Postby steph_tsf » Thu Jul 18, 2013 1:56 am

MyCo wrote:For filter tests I would rather go the "theoretical way". With this I mean: calculate the response, instead of measuring it.
I guess you are in a context like needing to display a response curve preview, like in a mixing console or an equalizer. Actually I'm in a different business area. I'm in a lab where we get "devices" possibly faulty, needing to be analyzed, needing to get debunked sometimes. Just like the Flowstone toolbox "BiQuad" is. Only an Analyzer of this kind will tell you the truth.

MyCo wrote: I've attached a schematic where I've put your biquad into my "Filter Construction Kit". I had to change the coeffs to make it fit (you don't use signs for your a coeffs).
Poles and zeros. Nice approach. Unfortunately most people are unfamiliar with such representation. Tell me, what's the exact issue with the "a" coeffs? And tell me, how would you get rid of the asymptotic distortion occurring when the filter corner frequency approaches Fs/2?

MyCo wrote: The filter is extremely "jumpy". There is no smooth transition when you turn the knobs. So it won't be very useful for automation stuff.
Agree, my BiQuad implementation is not intended for a mixing desk automation or effect automation. If you can make it evolve, supporting automation, that would be fantastic. Hope the average Flowstone user can manage the five parameters.

MyCo wrote:I've noticed you use Direct Form 2 for processing. It introduces a lot of rounding noise!
This is something I will measure using the Analyzer, in "Spectrum" mode. I will define a 4th-order Butterworth highpass at 5 Hz (the internal boost factor in the IIR gets huge), and compare the 1 kHz sinus degradation (harmonics and noise) passing through it. I will compare Direct Form 2 with Direct Form 1. Have you tried this yet?

MyCo wrote: In your filter code there are 2 lines that don't look right to me ... So my tip is, do it like that:
Code: Select all
in = input + epsilon - epsilon;
Because there is no optimizer involved, this passes straight into assembler.
Thanks for checking the BiQuad Code, making it more robust.
steph_tsf
 
Posts: 249
Joined: Sun Aug 15, 2010 10:26 pm

Re: Experimenting with IIR filters

Postby MyCo » Thu Jul 18, 2013 3:05 am

steph_tsf wrote:Poles and zeros. Nice approach. Unfortunately most people are unfamiliar with such representation. Tell me, what's the exact issue with the "a" coeffs? And tell me, how would you get rid of the asymptotic distortion occurring when the filter corner frequency approaches Fs/2?


The problem with the a coeffs is that there are different understandings of "what are the coeffs". Let's take the Direct Form 1 for a biquad:
Code: Select all
y = b0*x + b1*x1 + b2*x2 - a1*y1 - a2*y2

I take the coeffs from this equation exactly as you can read it. And you use it like this:
Code: Select all
y = b0*x + b1*x1 + b2*x2 + a1*y1 + a2*y2

As you can see your a's are inverted, and you don't use subtraction in your filter processing code. But that's just "interpretation".

I don't see the "asymptotic distortion" that you mentioned. When you mean that the mag. filter response goes through the roof when you come near to nyquist, than you should observe the pole/zero plot. In most cases a pole either hits or leaves the unit circle, this makes a filter unstable. So basically you have to turn the filter code back into Pole/Zero movements and then make sure that the poles stay inside the unit circle... and then turn everything back into coeff calculations. Maybe there is an easier way... but then I don't know that.

steph_tsf wrote:This is something I will measure using the Analyzer, in "Spectrum" mode. I will define a 4th-order Butterworth highpass at 5 Hz (the internal boost factor in the IIR gets huge), and compare the 1 kHz sinus degradation (harmonics and noise) passing through it. I will compare Direct Form 2 with Direct Form 1. Have you tried this yet?


Not exactly that, but there was a discussion about filter accuracy some time ago, where filters where compared. And the direct form 2 results were the worst.
Edit: I found the thread:
http://synthmaker.co.uk/forum/viewtopic ... 490#p91475
User avatar
MyCo
 
Posts: 718
Joined: Tue Jul 13, 2010 12:33 pm
Location: Germany

Re: Experimenting with IIR filters

Postby steph_tsf » Thu Jul 18, 2013 12:04 pm

MyCo wrote:The problem with the a coeffs is that there are different understandings of "what are the coeffs".
Indeed, myself and Flowstone we are not tuned to Wikipedia definition of Coefficients. See attached picture.

Flowstone doesn't follow Wikipedia's definition by swapping the retroactive coefficients with the non-retroactive coefficients (a <-> b swap).

I don't follow Wikipedia's definition by not considering the retroaction as negative (sign inversion of the retroactive coefficients). We are not in the operational amplifier world, where the retroaction gets implicitely defined as negative. Here, concerning digital BiQuads, we get two retroactions (the two coefficients), thus we must consider them in the general case as "a retroaction" which can be negative or positive. Introducing a negative sign here is confusing. I deeply regret that Wikipedia's definition of the coefficients adds negative signs to the retroactive coefficients.

Is Wikipedia's definition the same as Matlab IIR Filter Design package?
Attachments
Wikipedia Direct Form 1 - Direct Form 2 (600).png
Wikipedia Direct Form 1 - Direct Form 2 (600).png (76.54 KiB) Viewed 38195 times
Flowstone 2P2Z Biquad.png
Flowstone 2P2Z Biquad.png (30.19 KiB) Viewed 38195 times
steph_tsf
 
Posts: 249
Joined: Sun Aug 15, 2010 10:26 pm

Re: Experimenting with IIR filters

Postby steph_tsf » Thu Jul 18, 2013 12:11 pm

MyCo wrote:
steph_tsf wrote:I don't see the "asymptotic distortion" that you mentioned.
Please Check out the two attached .fsm.
Because of the Bilinear Transform that's used when computing the BiQuad coefficients (RBJ math and the likes), the BiQuads don't behave well past Fs/4. A typical example is the asymptot of a lowpass filter. Is there a better transform available, taking this into account? Adding a small highpass fraction when dealing with lowpass filters past Fs/4?
Attachments
IIR Lab (Asymptot distortion from Bilinear Transform) (600).png
IIR Lab (Asymptot distortion from Bilinear Transform) (600).png (117.58 KiB) Viewed 38194 times
IIR Lab (correction of Asymptot distortion from Bilinear Transform).fsm
(1.81 MiB) Downloaded 1553 times
IIR Lab (Asymptot distortion from Bilinear Transform).fsm
(1.91 MiB) Downloaded 1540 times
steph_tsf
 
Posts: 249
Joined: Sun Aug 15, 2010 10:26 pm

Re: Experimenting with IIR filters

Postby steph_tsf » Thu Jul 18, 2013 12:42 pm

By the way, is it possible to reassess the Flowstone BiQuad primitive?
- a more appropriate short name would be "Lowpass"
- a more appropriate long name would be "Double Biquad Lowpass"
- a more appropriate quick help text would be "Two lowpass Biquad IIR filters in series providing 24dB per octave attenuation past the cutoff frequency"

The "Cutoff" port should be renamed "Fr"
The associated long name should be "Relative frequency cutoff (0.0 - 0.5)"

The "Res" port should be renamed "Q"
The associated long name can remain "Resonance"

As soon as this is out of the way, we can create a better "BiQuad" primitive in the spirit of the "generalized" BiQuad, now compatible with automation. That new "BiQuad" could take as input parameters :
- Fr (a float between 0.0 and 0.5)
- Q (a float between 0.001 and 1000), and when Q is less than 0.001 the BiQuad reconfigures as a 1st order IIR, only reading the Lowpass and Highpass parameters
- Lowpass contribution (a float without any restriction)
- Bandpass contribution (a float without any restriction)
- Highpass contribution (a float without any restriction)
When Lowpass, Bandpass and Highpass equal unity, we natively get back the unity transfer function, whenever the value of Q.

There could be two variants of such "generalized" BiQuad :
- one variant applying the Bilinear Transform, suffering from asymptot distortion when Fr is greater than Fs/4
- one experimental variant applying a more elaborate Transform, for ironing out asymptot distortion
Attachments
Flowstone BiQuad primitive is wrongly documented.png
Flowstone BiQuad primitive is wrongly documented.png (17.59 KiB) Viewed 38192 times
steph_tsf
 
Posts: 249
Joined: Sun Aug 15, 2010 10:26 pm

Re: Experimenting with IIR filters

Postby steph_tsf » Thu Jul 18, 2013 3:33 pm

MyCo wrote:There was a discussion about filter accuracy some time ago, where filters where compared. And the direct form 2 results were the worst. http://synthmaker.co.uk/forum/viewtopic.php?f=12&t=12027&p=91490#p91475
The attached .fsm relies on the Audio Analyzer configured in "Spectrum" mode for visualizing distortion.

First of all you need to select a FFT size equal to 8192 for getting a clear spectrum display.
The FFT size got set to 128 in order to decrease the size of the .fsm, for not exceeding the Flowstone forum attachment size limit of 2MB.

As you can see, I setup two Highpass filter banks with a very low corner frequency, adjustable between 0.3 Hz and 3.0 Hz. The top one is the 2P2Z Flowstone primitive. The bottom one is a "handmade" BiQuad. The idea is to compare the spectrum of the signal directly after the Sine generator, directly after the 2P2Z Flowstone primitives, and directly after the "handmade" BiQuads.

Looking at the 500 Hz signal that's delivered by the Flowstone Sine primitive, I would say that the system noise floor is -160 dB roughly, which is an excellent figure for audio applications. There are however spurious spectrum rays extending to -125 dB, quite a disappointment. The Flowstone Sine primitive should be replaced by some more elaborate sinus generator, for determining if those spurious spectrum rays come from the signal generator, of from the system noise floor.

Let's now look to the signal after going through three IIR BiQuads in series configured as highpass filters with a frequency corner equal to 0.95 Hz. This is extreme testing as with a 0.95 Hz corner frequency (to be compared to the 44,100 Hz sampling frequency), the resonating part of the BiQuad is producing a huge gain. Clearly the noise floor gets raised by something like 15 dB or so. After the three BiQuads, the system noise floor appears to be -145 dB instead of -160 dB. The spurious spectrum rays magnitudes have not changed, they are still extending to -125 dB or so.

There appears to be no spectrum difference between the 2P2Z Flowstone primitive, and the "handmade" BiQuad. They both appear to raise the noise floor by 15 dB or so, when configured as a 0.95 Hz highpass.

If you dare lowering the BiQuad corner frequency, say you set it at 0.30 Hz, you will make all BiQuads kaput. This is a severe irrecoverable kaput, as even if you restore a healthy corner frequency like 3.00 Hz, all BiQuads will remain kaput. You need to exit Flowstone and reload the .fsm, for getting all BiQuads out of their "kaput" status. I don't like this. Is there a workaround like installing a -0.999/+0.999 clipping at the output of each BiQuad?

Do you agree with my findings? Any comment welcome.
Attachments
THD sinus generator (600).png
THD sinus generator (600).png (93.69 KiB) Viewed 38185 times
THD 0.95 Hz highpass (600).png
THD 0.95 Hz highpass (600).png (96.41 KiB) Viewed 38185 times
IIR Lab - comparing THD and noise.fsm
(117.09 KiB) Downloaded 1505 times
steph_tsf
 
Posts: 249
Joined: Sun Aug 15, 2010 10:26 pm

Re: Experimenting with IIR filters

Postby MyCo » Thu Jul 18, 2013 4:58 pm

Interesting... I've just had a look at the assembler code of the "biquad" primitive and it really looks like that there are 2 biquads in series in it. But don't know if this is just for getting the 12dB rolloff.

I don't think that the RBJ filters are designed by using bilinear transform. They are just designed using z-plane and then the coeffs are just calculated from P/Z coordinates. So when there is a problem, just go back to the z-plane.

Regarding your comparison of the filter: I don't know if you can measure the error noise generated by a filter with a setup like this. You would have to measure the difference of the input vs. the output in a band that is not affected by the filter. Let's say your filter would generate silence, then you would read -inf noise in your setup, but the error of the filter would be infinitely high, because it doesn't do what it should do.
User avatar
MyCo
 
Posts: 718
Joined: Tue Jul 13, 2010 12:33 pm
Location: Germany

Re: Experimenting with IIR filters

Postby steph_tsf » Thu Jul 18, 2013 6:48 pm

MyCo wrote:Interesting... I've just had a look at the assembler code of the "biquad" primitive and it really looks like that there are 2 biquads in series in it. But don't know if this is just for getting the 12dB rolloff.
Trust the Analyzer. There is no mystery anymore. The Flowstone "biquad' primitive rollof is 24 dB/octave. Clearly this is a 4th-order Lowpass made of two BiQuads in series.

MyCo wrote:I don't think that the RBJ filters are designed by using bilinear transform.
Yes they are. Would be interesting to ask RBJ what kind of more elaborate transform he advises, for dealing with the asymptot distorsion on filters having their Fr above Fs/4.

MyCo wrote:Regarding your comparison of the filter: I don't know if you can measure the error noise generated by a filter with a setup like this.
You may have not realized, the IIR filter that's used for confronting the two BiQuad implementations is a highpass whose Fc is below 1 Hz. That filter doesn't output silence. That filter is outputting the whole audio spectrum, at full amplitude. If you setup Fc just on the edge before both BiQuads get kaput, you will hear digital noise and other weird things coming from your loudspeaker, adding to the 500 Hz sinus test signal.
steph_tsf
 
Posts: 249
Joined: Sun Aug 15, 2010 10:26 pm

Next

Return to User Examples

Who is online

Users browsing this forum: No registered users and 89 guests