About Phase Shifts in Filters
Normal EQs not only change the magnitude for certain frequencies but also change the phase. A phase change means that a frequency is delayed. This delay depends on the filter as well as the frequency.
As an example the following image shows a 1000 Hz sine wave which is filtered by a butterworth highcut at again 1000 Hz. The amplitude is reduced by 3 dB (max value ~0.707 instead of 1) but the sine wave is also delayed by a quarter cycle length (90 degree). This delay is the phase shift and depends on the filter type and frequency.
While this is normally not a big deal (humans are quite good at distinguishing different magnitudes at certain frequencies but very bad at hearing a signal’s phase) it can indirectly affect the magnitudes if a signal is summed with a phase-shifted version of the same signal. This can happen directly (send effect, parallel processing) or indirectly (multi-mic instrument like drums where only one mic is EQed). Depending on the phase shift’s amount it can lead to amplification (in phase) or attenuation. Since it is frequency dependent it produces an additional coloring which probably isn’t desired.
This only is a real problem if the phase shift is severe enough. The maximum amount of phase shift depends on the filter’s order. Most shelf and peak filters are second order, while a cut’s order is proportional to its slope. Generally speaking, as long as one is working with normal peak & shelf filters (and not too high Q-factors) or 6 and 12 dB/oct cuts, coloring due to the phase shift is probably not noticeable. Of course, the ear should have the final decision.
Introducing Linear Phase Filters
Another approach is to use a linear phase EQ. The main property of a linear phase EQ is to have a symmetric impulse response (IR). There are different ways to accomplish that which I try to explain below. The symmetric impulse response leads to these properties:
- Latency is introduces: The EQ must output something before an input signal gets in. This is not possible in realtime!
- Pre-Ringing: Since there is an output before an input appears, looking (inversely in time) like the output after the input there is always pre-ringing.
The amount of pre-ringing depends on the selected frequency, gain (if applicable) and Q-factor. In most cases it isn’t noticeable as it is masked by other audio. It can get audible, though, especially for low frequencies and high Q-factors. The statement on this side that QRange does LP-EQing without pre-ringing but only if all bands are flat is of course a joke as the plugin then only works as a gain.
Linear Phase Implementation
Since I haven’t looked into the source code, the next part of general linear phase EQs is based on presumption from my side. Although it sounds reasonable to me I might be totally wrong about how other LP EQs work internally.
“Normal” linear phase EQs operate in the frequency domain, that is either by directly drawing some frequency curve or by calculating a frequency response/IR from filtertype, Q-factor, gain and frequency. The processing will than take place via fast convolution which – as the name suggests – is rather high-performance.
As the processing is done via a known IR (a frequency response is simply another presentation of an IR), the filter’s IR is finite as it can only last as long as there’s data available. Some engineers thus named this kind of filter “Finite Impulse Response” or FIR filter.
IIR-Bases Linear Phase EQs
In most cases IIR filters try to emulate analog filters. Like analog filters their IR is not limited to a certain size. While every IIR’s IR decreases in amplitude (unless the filter is unstable) the IR’s length is infinite. Of course in reality the IR is either “muted” by being masked by noise or – as a digital filter – the sample resolution is reached and it is set to zero.
One other aspect is that an IIR filter can’t as such be linear phase. It is inherently not possible for an IIR filter to output something before an input is given. But it is still possible to do linear phase filtering with an IIR filter. One simply needs to process something with a filter and after that process it again but this time backwards. The phase shift created by the first processing will be reversed by the second, leading to a linear phase response. This is nothing new but of course only applicable for offline processing. Another aspect is that the forward processing must be done until the filter’s response is fully died down. Furthermore, as the filter is applied twice it is a little different to classic “analog-style” EQs. Cuts are only available in multiples of 12 dB/oct instead of 6 dB/oct and peak/shelf filters look a little bit different than their raw IIR counterparts.
The following plots show the magnitude and phase response of a highcut at 100 Hz with a Q-factor of 4. One can see that the slope as well as the resonance peak for the forward and backward filter doubles compared to the regular filter. The phase response on the other hand changes to zero phase.
The impulse input and impulse response is shown in the next graph.
The input is simple a single “1” sample (the top is clipped as the magnitude range iss only -0.1 to 0.1), the “normal” filter’s output and the output if processed forward and backward.
To approach this in real-time one needs to chop the audio into pieces, apply the forward and backward processing and put the processed pieces together again. For various reasons (transition between pieces etc.) this works way better if done with a 50% overlap and fading the pieces in and out (QRange uses a hann window for this).
Due to the chopping into blocks, the actual IR length is truncated. If the truncation actually shortens the IR (for example in the above graph to a range of -0.02 to 0.02 where there’s still signal) an error is introduced. In an FIR approach this will only affect the magnitude response but with IIR it also affects the phase response as the forward processing hasn’t finished (e.g. it didn’t fully go to zero) when the backward processing starts. Here are some graphs to show this effect (done with Christian Budde’s VST Plugin Analyser):
In “Short” latency mode there’s a phase shift of up to 10 degree but this goes down to below 0.4 degree in “Insane” mode. Also visible is that the gain at 100 Hz is down to about 8 dB in “Short” setting.
With cuts the phase shift becomes even more severe.
The phase shift for a cut at 100 Hz goes up to about 100 degree. This certainly is not linear phase. But on the other hand, even in “Short” latency mode the magnitude is attenuated by more than 30 dB when the phase shift reaches 45 degree. In “Insane” setting the attenuation is about 50 dB until the phase response even starts to change.
While QRange is not completely linear phase, the phase shift is still sufficiently low for any linear phase demanding application.
To finally get to the point, the main differences between IIR and FIR based LP-EQs are:
- Must collect samples before starting to process. This leads to longer latencies for the same IR length and thus bass resolution
- Can only use filters available as IIR filters
- As the forward and backward processing is truncated, the IR is not completely symmetric. This can lead to a (although mostly very low) remaining phase shift.
- While the output impulse response has FIR properties (it is finite), the actual response is not directly known to the implementation (e.g. plugin)
- Latency can be as low as half the IR size as latency-free fast convolution is available (convolution reverbs do this too)
- Arbitrary frequency responses are possible
- Perfect linear phase is possible
- The output impulse response is directly used by the implementation and thus known.