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

Experimenting with IIR filters

Post any examples or modules that you want to share here

Re: Experimenting with IIR filters

Postby MyCo » Thu Jul 18, 2013 7:12 pm

I thought you wanted to measure the error of the filter. So I say you, you can't measure the error of a filter without comparing its input with its output. The "silence" example that I mentioned was just to illustrate, that even when you see a -inf noise floor in your setup, there still can be an error because of the difference between input and output. Or to make it more clear:
let's say you have a filter that does nothing, but introducing an error. Then you'll see the same noise floor in your setup on the sine output and on your filter output. But let's say the whole thing is pitchshifted or just slightly delayed then you wouldn't see it. But you'll definitely see it, when you substract the filter output from the filter input.
User avatar
MyCo
 
Posts: 718
Joined: Tue Jul 13, 2010 12:33 pm
Location: Germany

Re: Experimenting with IIR filters

Postby steph_tsf » Fri Jul 19, 2013 12:23 am

@ MyCo : thanks for this. I agree that comparing the input with the output is a better method. However, a filter being supposed to be a filter, hence modifying the audio that's passing through it, how do you make a difference between "allowed differences" and "distortion or noise"?

In case there is noise or distortion added to the input, you'll see them as random bumps and holes in the Bode plot. In other words, if the filter is producing noise and/or distortion, the Magnitude plot and the Phase plot delivered by the Analyzer will become fuzzy. Let's try this. Here is the setup (see the attached .fsm).

The analyzer is used with ch1 as reference, and ch2 as signal to be analyzed in magnitude and phase.
We don't need the Impulse response.

There is a selector connected to ch2, the channel to be analyzed :
- a copy of the reference signal, with a 1% attenuation for hitting different pixels for the Mag and the Phase
- the signal as filtered by a triple 2P2Z
- the signal as filtered by a triple "handmade BiQuad"
- and a fourth signal I will describe later on

Let's start the Analyzer :
ch 1 : off (no need to display it)
ch 2 : Analyzer
ch3 : Off
ch 4 : Off
reference : ch1
impulse : off

timebase : 0.2 (s)
FFT length : 1024

CPU load should be less than 30%
this means that the audio cycle can go undisturbed
our measurements will be reliable

Triangular windows
True Bars for the gain/phase rendering
LPF Off for the rendering
20 dB top
40 dB range

now the Frequency control surfaces :
show them using the new "F" button
select linear Frequency
full

Let's check the various knobs :
Frequency 500 Hz or so
V1 -20 dB pink noise amplitude
V2 -30 dB sinus amplitude
F1 10 Hz this is the bad guy
V3 -46 dB I'll explain later on

set the audio On
set the timebase to 0.2 (s)

When switching the source (the four inputs), you get the following sequence :
- a perfectly flat and steady red/blue line, those are the Magnitude and Phase nearly overlapping (you analyze the reference)
- a quite disturbed gain and phase plot, time-varying in a random way with bumps and peaks (2P2Z)
- I would say a slightly less disturbed gain and phase plot, time-varying in a random way with bumps and peaks (handmade BiQuad)
- a quite disturbed gain and phase plot, time-varying in a random way, nearly the same as the two above

So what is that fourth signal?
Look the .fsm
Actually we generate as second, non-correlated random signal (seed inside is 5 instead of 2).
We filter it using the pink filter.
We attenuate by V2 (it reads -46 dB).
And we add this ... to the signal used as reference.
Now you understand the meaning of the whole setup.
The aim is to set V3, in such a way that when selecting the 4th source, we get a gain and phase nearly the same taste as when analyzing 2P2Z and/or "handmade BiQuad"

Now let's go back to the input.
Our reference signal is a -20 dB pink noise plus a -30 dB sinus at 400 Hz.
When we add a -46 dB (V3) uncorrelated pink noise to it, we get the Analyzed gain and phase nearly the same taste as when analyzing 2P2Z and/or "handmade BiQuad".
Does it mean that 2P2Z and/or "handmade BiQuad" act like adding a -46 dB noise / distortion ?

What was the highpass corner frequency in the triple BiQuads ?
It is F1, set to 10 Hz.
Does it mean that on such Audio Platform (I mean Flowstone), one cannot program BiQuads operating in the sub-audio frequencies ?

Let's determine F1, leading to an undisturbed gain and phase.
Let's select 2P2Z.
I would say F1 needs to be 90 Hz for getting a peaceful, steady gain and phase.
Let's operate V3 for getting nearly the same taste on the fourth input : a -73 dB attenuation seems adequate.
Does it mean that 2P2Z and/or "handmade BiQuad" set to 90 Hz act like adding a -73 dB noise / distortion ?

One can argue that those measurements mean nothing.
Surely the Analyzer gets fooled by delays.
I played with the delay compensation knob.
Indeed, when analyzing the reference signal, as soon as we introduce a delay, we get time-varying gains and phases.
Adding 20 samples delay, we get nearly the same gain disturbances than when setting F1 to 10 Hz.
Adding 1 sample delay, we get nearly the same gain disturbances than when setting F1 to 90 Hz.

Are there delays in the 2P2Z Filter when configured as highpass ?
I would say no. However, the phase is in advance (positive phase) for the frequencies approaching F1 and below.

A better test would be to extract the gain curve by comparing the two following signals :
- the reference signal, filtered by an allpass filter exhibiting the same phase as 2P2Z (= reference for the Analyzer)
- the reference signal, filtered by 2P2Z (= signal to be analyzed)
What is your opinion ?

Is there a standard test to be carried out, more reliable than what I'm doing ?
Attachments
IIR Lab - comparing THD and noise.fsm
(1.26 MiB) Downloaded 1367 times
IIR Lab - comparing THD and noise (600).png
IIR Lab - comparing THD and noise (600).png (106.13 KiB) Viewed 29789 times
steph_tsf
 
Posts: 249
Joined: Sun Aug 15, 2010 10:26 pm

Re: Experimenting with IIR filters

Postby steph_tsf » Fri Jul 19, 2013 3:27 am

I've got a PM asking to setup a bandpass filter. Here we go. I did a very simple one using three 2nd-order bandpass cells in series. See the attached .fsm.

If you get lost with the Triple Bandpass Control, double click on all knobs. They will reset to neutral and deliver a decent bandpass filter centered on 1 kHz.

Fc is the central frequency
kF is large when the bandwidth needs to be large (coefficient defining the edge frequencies, relative to Fc)
QC defines the Q of the central cell
QE defines the Q of the two cells at the edges

Steph
Attachments
IIR Lab - bandpass filters (600).png
IIR Lab - bandpass filters (600).png (78.94 KiB) Viewed 29783 times
IIR Lab - bandpass filters.fsm
(1.85 MiB) Downloaded 1428 times
steph_tsf
 
Posts: 249
Joined: Sun Aug 15, 2010 10:26 pm

Re: Experimenting with IIR filters

Postby steph_tsf » Sat Jul 20, 2013 3:37 am

Using three IIR BiQuads in series, one can approach the following classic filters :

- 1/3 octave filter
- 1/2 octave filter
- 1/1 octave filter
- 3/2 octave filter

See attached .fsm

What's the method for implementing "exact and official" 1/1 octave, 1/2 octave, and 1/3 octave filters ? Are there more than 3 IIR BiQuads required?
Attachments
IIR Lab - octave, half octave, third octave filters.fsm
(1.03 MiB) Downloaded 1316 times
steph_tsf
 
Posts: 249
Joined: Sun Aug 15, 2010 10:26 pm

Re: Experimenting with IIR filters

Postby steph_tsf » Wed Jul 31, 2013 11:55 pm

This is an update featuring the new 5-channel analyzer with built-in signal generator, scope, VU-meters and polarity control. A few cosmetic changes to the Highpass, Lowpass and Universal BiQuad filters.

The Universal BiQuad now can materialize 1st-order IIR filters, on top of 2nd-order IIR filters.
For accessing 1st-order IIR filters, you need to set the Q knob to zero.
The 1st-order mode gets confirmed by the disappearance of the BP knob.
Attachments
IIR Lab (new filters, new analyzer).fsm
(799.53 KiB) Downloaded 1292 times
IIR Lab (new filters, new analyzer).png
IIR Lab (new filters, new analyzer).png (73.78 KiB) Viewed 29747 times
steph_tsf
 
Posts: 249
Joined: Sun Aug 15, 2010 10:26 pm

Re: Experimenting with IIR filters

Postby steph_tsf » Fri Aug 02, 2013 12:51 am

Here is the Linkwitz Transform illustration.

Ch1 is the reference channel.

The closed box resonance model got arbitrary set to 1000 Hz, with a resonance about +10 dB (Q=3). This is ch2. A resonance frequency of 1000 Hz got chosen instead of 100 Hz or 65 Hz for centering the graph around 1 kHz, getting a high resolution graph without needing a 32K FFT size. The .png got taken with a 8192 samples FFT size (and 1 sec timebase for not overloading the PC CPU).

The maximum Linkwitz Transform boost got arbitrary set to +20 dB.

In case the resonance of your actual closed box is 65 Hz instead of 1000 Hz, all you need to do is to multiply the frequencies by a factor equal to 65/1000. In this example, the Linkwitz Transform won't be 314 Hz anymore. It will be 20 Hz.

We start building a Linkwitz Transform prototype producing a maximum +20 dB boost towards the very low frequencies, that we adjust for becoming symmetric with the closed box resonance. This is ch5.

We then build a copy the Linkwitz Transform prototype, put it after the closed box resonance model, and finely tune it for getting a flat frequency response. This is ch3.

As finishing touch, we may add a high slope Highpass filter for protecting the speaker against the very low frequencies, and the huge cone excursion they demand. This is ch4. Such Highpass filter is introducing a strong phase distorsion.

It may be preferable to tweak the Linkwitz Transform for less maximum boost (in fact, +20dB is a lot of boost), by accepting a +6dB/octave slope between 35 Hz and 100 Hz (350 Hz to 1000 Hz in our Fx10 model) instead of a flat frequency response. We'll deal with this in the future.
Attachments
IIR Lab (Linkwitz Transform 20dB) (500).png
IIR Lab (Linkwitz Transform 20dB) (500).png (54.79 KiB) Viewed 29693 times
IIR Lab (Linkwitz Transform 20dB).fsm
(443.5 KiB) Downloaded 1296 times
steph_tsf
 
Posts: 249
Joined: Sun Aug 15, 2010 10:26 pm

Re: Experimenting with IIR filters

Postby steph_tsf » Mon Aug 05, 2013 10:41 pm

I've got a PM asking modulatable bandpass filters. Here we go. Instead of calculating the five IIR BiQuad coefficients using Ruby, we do it using Blue (DSP code) taking advantage of the sin1 and cos1 functions. Need to pay attention to the arguments of sin1 and cos1. In Blue (DSP code), sin1 and cos1 need the argument to be in Radians. The argument doesn't need to be multipied by (2 * Pi).

Here is the DSP code for calculating generalized IIR BiQuad coefficients basing on the Bilinear Transform. This is a "generalized" BiQuad as it features a single output delivering any combination of lowpass, bandpass and highpass.
For getting a pure lowpass with a gain of 0 dB, you specify lp=1.0, bp=0.0, hp=0.0.
For getting a notch, you specify lp=1.0, bp=0.0, hp=1.0.

Code: Select all
streamin fr;
streamin q; // will crash if Q=0
streamin lp;
streamin bp;
streamin hp;

streamout a0;
streamout a1;
streamout a2;
streamout b1;
streamout b2;

float alpha;
float x0, x1, x2;
float lpf0, lpf1, lpf2;
float bpf0, bpf1, bpf2;
float hpf0, hpf1, hpf2;

alpha = (sin1(fr)) * 0.5 / q;
x0 = 1.0 + alpha;
x1 = -2.0 * cos1(fr);
x2 = 1.0 - alpha;

b1 = x1 / x0;
b2 = x2 / x0;

lpf0 = ((1.0 - cos1(fr)) * 0.5) / x0;
lpf1 = lpf0 * 2.0;
lpf2 = lpf0;

bpf0 = (sin1(fr) * 0.5) / (x0 * q);
bpf1 = 0;
bpf2 = -1.0 * bpf0;

hpf0 = ((1.0 + cos1(fr)) * 0.5) / x0;
hpf1 = -2.0 * hpf0;
hpf2 = hpf0;

a0 = lpf0*lp + bpf0*bp + hpf0*hp;
a1 = lpf1*lp + bpf1*bp + hpf1*hp;
a2 = lpf2*lp + bpf2*bp + hpf2*hp;

Here is the DSP code for calculating bandpass IIR BiQuad coefficients using the Bilinear Transform. This is a simplification of the Generalized BiQuad IIR filter.

Code: Select all
streamin fr;

streamout a0;
streamout a1;
streamout a2;
streamout b1;
streamout b2;

float alpha;
float x0, x1, x2;
float q = 0.900;

alpha = (sin1(fr)) * 0.5 / q;
x0 = 1.0 + alpha;
x1 = -2.0 * cos1(fr);
x2 = 1.0 - alpha;

b1 = x1 / x0;
b2 = x2 / x0;

a0 = (sin1(fr) * 0.5) / (x0 * q);
a1 = 0;
a2 = -1.0 * a0;

Fr is the central frequency of the bandpass, relative to the sampling frequency Fs (usually 44,100 Hz).
Q gets hard coded as constant in the DSP code.

This is all about coefficients.
Where do we manipulate audio samples for actually implementing the BiQuad IIR filter?
Actually, we are relying on the 2P2Z Flowstone primitive. Such primitive needs five coefficients as input, the five coefficients that we just computed : a0, a1, a2, b1, b2.

For making up a 1/3 octave bandpass filter, three such bandpass filters are put in series with different values for Q and for Fr.

On the attached .fsm, Fr gets generated in a static way using a knob delivering a Float in the range (0.0 ... 0.5).

What's a "modulatable" filter ?
Actually, the Fc input of the bandpass filter is a stream (Blue). This is the reason why the IIR coefficients need to be calculated using Blue (DSP) code.
The Fc input can thus serve as modulation input, synchronously sampled at Fs just like audio is, making the bandpass filter a "modulatable" one. In such context, Fc is usually coming from a very low frequency oscillator (say 10 Hz maximum), or any other slow-varying continuous waveform generator sampled at Fs, considered as Blue audio stream. The bandpass filter becomes thus a realtime variable one, the centre frequency is now continuously changing over time, and there can't be artifacts because everything (the modulating wave and the signal output wave) remains synchronously sampled at Fs (usually 44,100 Hz).

Say you need to override the slow-varying and continuously-varying Fc value using a manual knob. Fc will endure abrupt changes. Depending on the user input, the feedback part of the IIR BiQuad filter may tend to instability. This generates audible artifacts sounding like zipping or unzipping a coat or a jacket. Up to you to provide a "de-zipper", kind of lowpass filter, smoothing transitions between subsequent Float values. There are two Flowstone primitives available, taking care of this.

In the early eighties, DSP hardware was powerful enough for handling all 16-bit audio samples arriving at 44,100 Hz (say a 16-channel digital mixing console), but barely powerful enough or lacking memory and/or programming ease for managing de-zipping also at 44,100 Hz. Those early systems had a kind of de-zipping running at 100 Hz or so, in a lightweight Round-Robin sequencer, one knob after the other. Some generated audible artifacts in case the user was harsh with the controls. Most sound engineers mistrusted digital mixing consoles, back in those pioneering times - and they were right.

Back in 1993, ten years after the arrival of the CD, I remember how we managed to "measure" zipping noise possibly generated by our experimental digital mixing desk based on the Analog Device SHARC (DSP) and Crystal Semiconductor DACs. We used to play the "On Every Street" CD from Dire Straits on a Tannoy Canterbury "Dual Concentric" loudspeaker, loudly, our ears close to the speaker, with some colleague exercising the "monkey test" on the console knobs.
Back in 1993, if you were telling your boss that a true de-zipping was maybe feasible at Fs, using a 6th order Taylor approximation for the sinus and cosinus calculation of the IIR coefficients, along with two divisions, he was telling "you are mad, this is pure waste, how dare you asking the precious DSP to compute something else than audio samples, at Fs".
Back in 1993, a typical de-zipping scheme consisted of exploiting a sinus and cosinus table in ROM (quite short because of memory size constraint), and interpolating into it, not at Fs but at a slower frequency like Fs/256 for each knob, this way you could manage 256 knobs without overloading the DSP, without over-complicating the main do_loop.

Now the battle is over. Using Flowstone, any decent PC is able to execute the de-zipping at the audio sampling frequency, and if you do so, in theory there can't be audible zipping artifacts.

Steph
Attachments
Bandpass BiQuad IIR (300).png
Bandpass BiQuad IIR (300).png (24.61 KiB) Viewed 29680 times
IIR Filters Collection - modulatable (500).png
IIR Filters Collection - modulatable (500).png (69.63 KiB) Viewed 29693 times
IIR Filters Collection - modulatable.fsm
(1.93 MiB) Downloaded 1363 times
steph_tsf
 
Posts: 249
Joined: Sun Aug 15, 2010 10:26 pm

Re: Experimenting with IIR filters

Postby tester » Fri Sep 06, 2013 9:56 pm

...is not opening in FS303 (crash on startup). Maybe was saved with "audio on" and this causes a problem?
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
tester
 
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

Re: Experimenting with IIR filters

Postby steph_tsf » Sat Sep 21, 2013 9:58 am

tester wrote:...is not opening in FS303 (crash on startup). Maybe was saved with "audio on" and this causes a problem?
Hi, just coming back from holiday. Audio is not "on" on the saved file, the file opens normally under FS303, and doesn't crash. Look the attached file, try this slightly modified version (now the BiQuad outputs audio on DS out). If it still crashes on your side, try replacing the "DS out" by "ASIO out".
Attachments
IIR Filters Collection - modulatable.fsm
(792.88 KiB) Downloaded 1342 times
steph_tsf
 
Posts: 249
Joined: Sun Aug 15, 2010 10:26 pm

Previous

Return to User Examples

Who is online

Users browsing this forum: No registered users and 31 guests