filter power?

DSP, Plugin and Host development discussion.
Post Reply New Topic
RELATED
PRODUCTS

Post

How do the digital filters set precise amount of cutting power? For example,I can set bandreject/notch filter that only cuts 0,1db max.I know you can change filter order but those are big steps,like 6db.So how can a filter be programed to be able to cut these small values? How it works inside to set the precise value?

Post

One way is to mix the original input signal with the filter output.

For instance if you mix-- EQOutput = (0.01 * FilterOutput) + FilterInput

Assuming the filter has unity gain, you are only barely changing the frequency response of the EQOutput. Adding an 0 dB signal with a tiny -40 dB signal.

IIR filters and other filters which do not have linear phase response, the result of the mix will have a "non-intuitive" amplitude and phase curve. Something an expert would expect but not a newbie. It is not rocket science, but if a frequency is phase-shifted on the filter output, it will not add with the original signal and give a sum you would expect without taking into account the phase shift.

For instance, with a sine-wave input signal-- If the filter output is -3 dB lower than the input at some frequency, but the filter output is also phase shifted by -45 degrees-- If the input peaks at 1.0 and the filter output peaks at 0.707-- Adding the signals together does not give 1.707 as one might expect.

If the peak of the filter output is 0.707 but shifted 45 degrees, the part of the filter output sine wave added to the 1.0 peak of the input, would have a value of 0.5, so at that certain point, it would be 1 + 0.5 = 1.5 AT THAT POINT rather than 1.707.

When phase shifted sines get added, the output is often phase shifted "somewhere in-between" the phase of both sines, and the peak of the sum happens wherever the two phase shifted sines happen to have the biggest sum. So the sum peak would usually be somewhere different in time than either the input peaks or the output peaks.

Apologies over-complicating the answer. Just wanted to caution that you can't just look at the frequency response of a filter, add it to the input, and get an accurate representation of what the sum output frequency response would look like. This is not incredibly complex. Merely not as simple as it would be if there were no phase shift involved.

RBJ's excellent filter cookbook equations-- For the shelving and peaking filters, he makes the design "with the assumption" that the prototype is adding a filter output to a certain percent of the "straight wire" unfiltered signal. But he solves the entire filter transfer function so that it "works like" adding a filter to the input, without actually having to do the explicit addition. The filter coffs he derives, does the "watered-down" filtering automatically without the summing step.

Post

thanks you very much! I am so happy someone is helping me

so you mix filtered signal with unfiltered,but if you mix two signals,they must be each -6db/-50% quieter so they dont clip when summed together.Doesnt this need to happen in this 64bit float point thing so you dont lose low level information?

also is there some other way to make filter only cut like 0,05db instead of the mixing with uncut signal technique that you mentioned above?

Post

Hi neodymDNB

You can either add or subtract the filter output from the input signal.

Considering an "easy example" of a peaking band in an EQ-- The easiest/fastest filters are IIR, which have frequency dependent phase shift. So consider an IIR bandpass filter output mixed with the input signal-- Typical second-order IIR bandpass has zero phase shift at the center frequency, Fc, the "top of the filter's peak".

So we can easily predict the boost/cut at the center frequency of the bandpass filter, though we would need to consider the effect of the phase shift to estimate the shape of the peaking band above or below that center frequency.

Assuming the bandpass filter has unity gain at the center frequency-- If you do EQOutput = Input + 1.0 * FilterOutput-- At the center frequency it is 1 + 1 = 2.

DBGain = 20 * log10(OutputLevel / InputLevel) = 20 * log10(2 / 1) = +6 dB

If you do EQOutput = Input + 3.0 * FilterOutput, the output = 4 X the input, which works out to +12 dB.

If you do EQOutput = Input + 0.122 * FilterOutput, the output = 1.122 X the input, which works out to +1 dB.

EQOutput = Input + 0.0292 * FilterOutput, the output = 1.0292, which works out to be +0.25 dB.

If you do EQOutput = Input + (-1 * FilterOutput), the result is 1 + (-1) = 0. So you get (theoretically) an infinitely deep notch at Fc.

EQOutput = Input + (-0.5 * FilterOutput) = 0.5, which is -6 dB
EQOutput = Input + (-0.75 * FilterOutput) = 0.25, which is -12 dB
EQOutput = Input + (-0.109 * FilterOutput) = 0.891, which is -1 dB

Given a dB value, you can get the Output:Input ratio with the formula--
Gain = 10 ^ (DBValue / 20), or pow(10, DBValue / 20.0) or whatever.

So a simple formula to solve this peaking filter given the desired dB gain at Fc--

FilterGainCoff = (10.0 ^ (DBValue / 20.0)) - 1.0;

Then process-- EQOutput = Input + FilterGainCoff * FilterOutput;

Some computer POW functions can misbehave if you pass them zero. So you may need to trap out DBValues too-close to zero (unity gain) to avoid computer math errors. If the DBValue is 0, then FilterGainCoff ought to also be 0.

Because of the phase shifts (and other considerations), the result would be that cut bell shapes tend to be narrower than boost bell shapes, if you always use the same bandpass filter width, or Q, for all values of boost and cut. So it seems common to adjust the Q of the bandpass filter according to the amount of boost or cut, so that the shape/width of the boost-cut bell curve is about the same for any amount of boost or cut.

The bandpass filter needs adjusting narrower, the more boost you add. The bandpass filter needs adjusting wider the more cut you do, in order to keep all the boost-cut shapes about the same width. But if the bandpass filter is always unity gain and zero phase shift at the center frequency, the simple formula above ought to give predictable results for any positive or negative gain. So far as I know. Which isn't much.

Post

how it works in the bit depth department?

you have 16bit music,to mix filtered and unfiltered original you need to make both of them 6db quieter so they dont clip,but that way you permanently lose the bottom floor 1bit,the quitest 6dbs,that would be from -90 to -96db for 16 bit file

how is this problem solved?

Post

neodymDNB wrote:how it works in the bit depth department?

you have 16bit music,to mix filtered and unfiltered original you need to make both of them 6db quieter so they dont clip,but that way you permanently lose the bottom floor 1bit,the quitest 6dbs,that would be from -90 to -96db for 16 bit file

how is this problem solved?
Hi neodymDNB

Clipping can always happen in either analog or digital if something gets turned up too loud. If a user sets gains so high that it distorts, then generally it is the responsibility of the user to turn it back down so it doesn't clip anymore.

For instance if a bass track is already peaking near 0 dB-- And then the user decides its not phat enough and he boosts the bass bands by +15 dB. Then the EQ output is is gonna peak at +15 dB and it will distort if the EQ output is sent to an integer audio file or most computer audio interfaces. This boosting of an already hot file will clip regardless what kind of EQ algorithm you use, and regardless whether analog or digital.

To avoid such distortion, the user either has to turn down the track before it hits the EQ input, or turn down the EQ output before it gets written to audio file or sent to audio interface.

That's one reason its a good idea to ALWAYS process in floating point. Floats don't clip unless the overs get astronomically big. So one process in a chain could raise gain many dB into the red, but so long as some other downstream process turns the level down again, little if any information is lost. One reason that it is so common to see input and output gain controls on EQ's and other FX devices. And input/output meters!!

If you have a chain of integer effects, then if one of them clips, all of the following effects are clipped and you can't fix it just by turning down the final output.

You can't usually clip a float audio file either. However, a float audio file hotter thab 0 dB-- If you play it to an audio interface or save it to an integer file, it will clip. Unless you turn it down before integer save or playback.

If you have a very quiet bass track peaking at -16 db and you boost the bass by +15 dB, it wont clip. You don't have to worry about "dividing things by 2" before adding them, for ordinary EQ.

If you boost only 1 dB, then you are not making the original twice as big. Only a little bigger.

If you are boosting 18 dB then you are increasing the level by a factor of 8. In that case, dividing by 2 wouldn't be reliable clipping avoidance in any case.

EQ's can also cut. If you cut a track then it gets quieter, and to compensate you may need to turn up either the EQ input or output.

These level-matching procedures are sometimes called gain staging.

PS: The other big advantage of always doing float audio FX-- For instance if you write the first version of your program to read and write 16 bit audio, and so you write all your DSP, mixing and playback/record code to use 16 bit to agree with the 16 bit files your program uses--

Later on, when the users nag you into also supporting 24 bit integer files, you will have to write new versions of all your dsp, mixing, and play/record code. One set of routines to process the 16 bit and another set of routines to process the 24 bit.

There are many many file formats. It makes more sense to always use float under the hood, and convert to/from whatever formats are in the audio files, or demanded by the audio interfaces. Thataway you can add support for a new file format without having to change any of your dsp code.

Post Reply

Return to “DSP and Plugin Development”