IIR_Lab : a design help for digital audio filters

Status
This old topic is closed. If you want to reopen this topic, contact a moderator using the "Report Post" button.
Hmm, wiggles should be visible at Q = sqrt(2)/2. They get worse at higher Q. Attaching a few screen grabs from IIR lab on my side.
Hey, for the last three plots, you selected a Rect. Window for the BodeGen. You need to remember that the BodePlot gets "brute force" computed using the White (Noise) test signal, not periodic, hence the importance of the Windows. Use the Triangle Windows and you'll see the change.

From what I can tell at a glance the filters seem to be direct form 1 and I get that the blending is controlled by the numerator coefficients. The BP looks like the 0dB peak gain form and the weighting of each form by the HP, BP, or LP coefficient entered in the UI is clear.
You are all right. In an infinite resolution system, Direct Form I is numerically equivalent to Direct form II. However, in a finite resolution system (like simulated here), Direct Form I needs to be used for avoiding saturation.

What's not clear to me is how the numerator coefficients are calculated.
You used the term "blending". You almost answered the question. Consider the three canonical numerators : HP, BP and LP. The Cookbook formulae for audio EQ biquad filter coefficients from Robert Bristow-Johnson is the classic source. IIR_Lab linearly combines the HP, BP and LP numerators using the weighting factors you manually specify. By specifying 0.0 1.0 0.0 like you did, you know by advance it is the pure bandpass peaking at 0dB. By specifying 1.0 0.0 1.0 you know by advance it is the infinite depth notch. By specifying 1.0 -1.0 1.0 you know by advance it is the pure phase shifter. Up to you to manually specify any other pattern, and IIR_Lab will graph the corresponding 2nd order transfer function (BodePlot), and distorsion spectrum (SpectrumPlot).
 
Last edited:
Use the Triangle Windows and you'll see the change.
I tried that too. From what I can tell triangle lowpasses the noise used for Bode generation. Fewer high frequency errors but doesn't change the low frequency errors. Seems like a less brute force Bode would be helpful.

IIR_Lab linearly combines the HP, BP and LP numerators using the weighting factors you manually specify
Ah, so it is that simple. Thanks.
 
I tried that too. From what I can tell triangle lowpasses the noise used for Bode generation. Fewer high frequency errors but doesn't change the low frequency errors. Seems like a less brute force Bode would be helpful.
Be careful what you say. You need to understand the implications of a non-periodic signal being FFT processed. You also need to understand the uncompromized "what you see is what you get" IIR_Lab purpose.
A bad move would be to compute the BodePlot in an analytical way, only looking at the IIR coefficients. Doing so, you'll get smooth BodePlot curves, but they can't reflect anymore the arithmetic errors introduced by the finite-lenght representation.
For IIR_Lab, the "brute force" BodePlot computing is thus the only way.
There are three ways for improving the BodePlot rendering when dealing with very low frequency IIRs like 40 Hz. One could use a Pink noise as test signal (more energy in the bass), one could do the FFT on more than 65536 samples, and one could apply a more elaborate Windows than the Triangle one.
An more elaborate test signal for the BodePlot would be a pink noise (a good match with the BodePlot log frequency scale) for providing the needed wideband signal, additionned to some bandpass filtered pink noise (for adding energy in any wanted frequency band). The flip side would be that, due to the added complexity, most people would not understand the setup.
 
Last edited:
Direct impulse calculation, swept sine, chirp, and structured noise all work too. Music's power spectral density tends to fall in the 1/sqrt(f) to 1/f range so structured f^(-0.75) noise is probably the most realistic default. It would be interesting to compare the results from that to an FFT of the impulse and see if there's a meaningful difference. My guess would be the method's analytic capability will limit on the noise structuring in which case one of the simpler, deterministic methods would be just as informative. One would have to try it and see but, generally, I've found swept sine or direct impulse more useful than MLS.

Another straighforward approach is to filter some real music and calculate the transfer function as the ratio of the FFTs of the input and output.
 
Another straighforward approach is to filter some real music and calculate the transfer function as the ratio of the FFTs of the input and output.
Call it hyper brute force when the test signal is a 3 minute song. As generally a song starts with a fade-in and stops with a fade-out, if you manage to do a FFT on the whole song (plus some added silence for meeting the power of two FFT lenght), you meet the periodic criterion so the uncertainty on the FFT result vanishes. In such hyper brute force context, if you continue getting wobbles in the Bode Plot, then for sure you know the IIR filters introduce non linearities do to their finite-lengt binary word representation. You need to compute a FFT on at least 8 million samples. That's still a lot, even nowadays with GHz computers.

In IIR_lab, you get the Spectrum Plot, dedicated to the representation of non-linearities. Spectrum Plot does the job of detecting non-linearities with a moderate length FFT provided you select a SpectrumGen test signal that's synchronized with the sampling frequency.

The Bode Plot is only there to graphically confirm that you have correctly set the IIR coefficients.

In IIR_lab, the Bode Plot shows wobbles in the frequency bands where there are non-linearities caused by the finite-lenght binary word representation, that you should see confirmed on the Spectrum Plot. Therefore, the less the test signal has energy (in the considered frequency bands), the more Bode Plot wobbles.
In IIR_Lab, the Bode Plot also shows wobbles due to the non-periodic nature of the test signal that's used (a White Noise). Using a more advanced Windowing function than the Triangle, one could reduce the wobbles. See how the Bode Plot degrades (huge wobbles) when selecting the Rect. Window. Remember to never draw conclusions basing on the Bode Plot, when the Bode Plot got computed using a Rect. Window.

When you see wobbles in the Bode Plot you need to ask yourself : a) is my BodeGen Signal Level correct (you may have set it to -60 dB in a previous session) - b) am I using the BodeGen Triangle Window - c) am I testing using Double Float - d) is the Spectrum Plot clean ?
 
Last edited:
The argument seems to be more that the whole song has to be processed for transfer function extraction via FFT comparison to be valid. I'm not seeing how that holds. Certainly, some intelligence is required in selecting input data points from a recording---a bunch of zeros wouldn't be very useful---but that's also a requirement for approaches using random inputs. There's also some excess phase to be removed from the group delay with both approaches.

Personally, the more I think about this the more I'm inclined to run tracks through equivalent filter banks, one implemented with doubles, one with fixed point implementation equivalent to arm_biquad_cascade_df1_q31 / arm_biquad_cas_df1_32x64_q31 (Q1.31 storage, Q1.63 or Q2.62 accumulator), one with an arm_biquad_cascade_df1_fast_q31 equivalent (Q1.31 storage and Q2.30 accumulator) and look at the differences between the output samples. If the differences are underflows after converting back to 24 bit the filter banks can reasonably be said to be functionally equivalent. Back of the envelope it'd take about two hours to perform this measurement on the portion of my music collection I've ripped. So the bottleneck's me getting around to implementing the fixed point code---it's just about summer here, meaning my DIY pace is likely to slow down quite a bit until October.
 
Last edited:
Personally, the more I think about this the more I'm inclined to run tracks through equivalent filter banks, one implemented with doubles, one with fixed point implementation equivalent to arm_biquad_cascade_df1_q31 / arm_biquad_cas_df1_32x64_q31 (Q1.31 storage, Q1.63 or Q2.62 accumulator), one with an arm_biquad_cascade_df1_fast_q31 equivalent (Q1.31 storage and Q2.30 accumulator) and look at the differences between the output samples. If the differences are underflows after converting back to 24 bit the filter banks can reasonably be said to be functionally equivalent. Back of the envelope it'd take about two hours to perform this measurement on the portion of my music collection I've ripped.
While in less than two minutes, IIR_Lab delivers the Spectrum Plot. Provided you are using a synchronous (Fs/N) sinus, the Spectrum Plot graphically and accurately represents all kind of artefacts introduced by the finite-lenght word representation. For determining if an artefact is below the quantization level that's in use, read the Spectrum Plot and remember that 16-bit is -96 dB and 24-bit is -144 dB. The Spectrum Plot enables you to see the artefacts spectral pattern. IIR_Lab thus quickly and scientifically assesses if a given IIR filter is "bit exact" for a given input signal. Using different input signals (always within the Fs/N family), IIR_lab also helps you determine in which domain (frequency - level) a given filter deviates from remaining "bit exact". The operation speed of IIR_lab enables working interactively in a trial and error way for developing your engineering skills. Once you get confident about a given filter, having assessed it on IIR_Lab, nothing prevents you applying some hyper brute force as "real world" check : your two hours measurement using a full music track.
 
Last edited:
THD and IMD are measurements of the same underlying phenomena and hence are usually strongly correlated. I tend to prefer multitone IMD as it's a bit more thorough, though---synchronous sines are a subset of a THD sweep. As pointed out earlier there's no requirement to take the measurement at scale; 64k points is 64k points. But, having gotten the code together, there's no particular reason not to let the computer run whilst one goes to the pub.
 
Status
This old topic is closed. If you want to reopen this topic, contact a moderator using the "Report Post" button.