Gain Compensation after PeakNotch filter/EQ

woyteg's icon

Hi!
When I send white noise into a biquad Peak/Notch filter, obviously rms and peak will change. Anybody has a formula for calculating what gain-compensation will be neccessary? the most irritating (Although kind of logical) thing is, that also if a notch filter is applied peak will rise and attenuation is needed... Most important for me would be to estimate the compensation for the peak value, so I can prevent clipping.
(compression, limiting etc left aside!)
Thanks!

woyteg's icon

bump! Nobody? Please help!
I mean filters are around for a while, I really can't find any formulas for predicting/estimating the output peak (given filter, input peak input spectrum, what have you)..
any ideas?
thanks!

Roman Thilenius's icon

for pink noise it would be around 1/n, for white noise it will depend on the filter frequency, no?

woyteg's icon

hi roman,
Thanks for trying to help.
Not sure what n in your example is, but sure it will always be frequency dependent.
So, my problem is:
given a certain input signal (music, whatever), knowing anything you want about it (spectrum etc)
Knowing the filter (you can do anything with the filter)
can we predict the peak amplitude of the output?
(without simply filtering the whole input signal)
Prediction would be ideal to an accuracy of +-0.3 dB.

I've tried lots of things, but I can't believe there is no solution.. I've even shaped noise to the input signals spectrum etc.. can't believe there isn't a more analytical solution to this.

Roman Thilenius's icon

for noises or cosines one should at least be able to find a short cut.

but for music, i am not so sure.

dont forget that an absolute "gain" doesnt exist; there is only peaks and power to work with, and both are linked to a time variable.

predicting the power or peaks output of music through a biquad would require the same calculation the biquad does i think.

as most filters distort the phase, the frequency dependence can be quite critical for narrow bandish and/or harmonic input material.

ten years ago i asked here about how to avoid biquad explosions and the answer was similar i think. ^^

woyteg's icon

'for noises or cosines one should at least be able to find a short cut.'
yup, definitely,
'dont forget that an absulte "gain" doesnt exist, there is only peaks and power, and both are linked to a time variable.'
yes. Primarily I'm interested in peak, but as you say, these are linked. I guess if I find a good estimation for peak, I can find a good one for RMS too.
'predicting the power or peaks output of music through a biquad would require the same calculation the biquad does'
Yes, very nice formulation of the problem. I hope you are wrong to some degree. I hope to be predicting the maximum level(the peak value) of output given the input.
There are loads of statistical approaches one could take (think of sending 50% the input through the filter, or the loudest 20 % for example.)
Another Approach I am taking at the moment is filtering a unit step function, so it resembles the maxima values of the spectrum of the input file, sending it through the filter, looking for the peak value.
My worst approaches where 0.2 dB off on average (but with some cases off by 2 dB).. so there are solutions!
I'm just not happy with my solutions so far and was hoping I'm overlooking something, or you guys have an idea? Also my solutions need to be fast and efficient..
Kind of reassuring that you also think it's a hard problem (you see I'm pondering about this since a year now..) thanks again roman, still open for any ideas!

Roman Thilenius's icon

so, i am finished editing my last post now, maybe you need to change some quotes. ;)

the theoretical maximum peak of all times (i.e. for every material) can be found somehow, thats sure.

but i think we would have to set a range limit at the low end. so lets say the filter will never go under 8.1 Hz (note number 0)

now for the material. what is the worst one can supply the filter? a square wave?

and what about modulating the filter freuency .. and what about Q ... is Q always 0. in your application or do you want to include resonance as well?...

Roman Thilenius's icon

yeah that would be a straight forward abbreviation with that statistics thing. you´d just try around with some different material and see if you can tell where the possible maximum is. eventually you will end up with a table of ear/hand made constants which work ... without we would know why.

woyteg's icon

first of all, sorry if all this sounds a bit mystical there's a commercial product connected to this.
yes, the statistical approach would work, but is both intellectually unsatisfying and slow(or fast and inaccurate).
Material at the input is unknown (music), the filter is a generic biquad so yes, there is feedback/resonance. (which is, in fact the problem I am quite sure. If it was a FIR filter, I think the problem would be much easier.) All biquad coefficients are known and constant.

I actually think there are many approaches (statistics, machine learning, what have you) but I am playing around with filters and z-transforms and stuff for too long now and it's both frustrating and annoying that I don't seem to be able to solve this. What do you think about the (pre-filtered/shaped) impulse response thing?

'the theoretical maximum peak of all times (i.e. for every material) can be found somehow, thats sure.'
so you also think this CAN be solved analytically?

woyteg's icon

with 'unknown music' in my previous post i mean we can access the music the input is known, but it could be anything and I can't prepare for whats coming. you know what i mean, right?

Roman Thilenius's icon

>>What do you think about the (pre-filtered/shaped) impulse response thing?

i believe deconvolution will work very well for EQ bands. if you build the EQ adaptive in addition that gives you the perfect sound. of course it is a CPU hog. a highpass->lowpass cascade of 2 FIR might be able to do the same.

>>so you also think this CAN be solved analytically?

maybe we are just to blind to see it (i am actually very tired right now). but: the usual literature doesnt reveal anything in that direction, and that might be a negative sign.

Roman Thilenius's icon

you know, the usual approach for a eq plug-in would be to add some auto gain at the end, which is fed with control signals from the beginning of the lookahead window in realtime. then you have an eq which never changes the power of the input.

woyteg's icon

"maybe we are just to blind to see it (i am actually very tired right now). but: the usual literature doesnt reveal anything in that direction, and that might be a negative sign.''
100% agreed.
'you know, the usual approach for a eq plug-in would be to add some auto gain at the end, which is fed with control signals from the beginning of the lookahead window in realtime. then you have an eq which never changes the power of the input.'
This would change the dynamics though, you're talking about a compressor post EQ ing if I understand you correctly. Actually I think this makes a lot of sense, still, it is not quite what I'm after..

Roman Thilenius's icon

hm.

a biquad (and most other filters) always works with two successive samples of the input material.

so there are 217 billion possible "peak" results even when the filter is fixed.

Roman Thilenius's icon

wouldnt the worst case be a cosine?

if the input material is a cosine at 500Hz, a notch/peak filter at 500Hz would raise the power for almost 6 dbA when the filter setting is at +6 dbA, isnt it?

(thats what i meant with "1/n" in my first post)

Roman Thilenius's icon

well actually, the peaks would be + 6dbA.

the measurement of dbA for cosines is another story :D

Roman Thilenius's icon

yeah i think thats it. that means you would have to have quite a big safety headroom.

and this only works for peak filters, not when you substract something from the input.

for a notch filter at -3 dbA the maxmimum peak of the output will always be the same as the maximum peak of the input, because it might be that the input doesnt have anything at all at this frequency band.

your original idea (making sure that the signal does not get louder after equeing) could be solved by designing the whole thing like this: whenever you raise one of the filter bands, the same amount of power has to be deducted from the sum of all filterbands. for only one filterband you would do that right in the biquad object.

woyteg's icon
Max Patch
Copy patch and select New From Clipboard in Max.

Hi Roman, sorry I was really busy these days. Thanks again for your thoughts, but no :)
Of course you are right, that solution sounds safe. But it also is not solving the problem : predicting the peak output, given the input and the filter.
While your solution is safe, it is unnecessarily so for most inputs. Most inputs would get attenuated much too much. And, well that's what you can always do, but nobody wants that.
Also, I'm not even sure if you are right... one would have to try. As my first post says, your idea about the notch filter seems wrong (I had the same idea and tried it)
look at this, it seems to prove us wrong, right?

Roman Thilenius's icon

impressive example. +4 db only from phase offsets^^. getting richer from increasing the debt. seems to work everywhere today.

did you try yet if at least my other statement is true? sinewave + amplification of peak filter at the same frequency == maximum output?