All Pass filters for phase correction

Ross21
 KVRist
 70 posts since 25 Jun, 2011
All Pass filters for phase correction
Hi,
I'm building a three band system in which some bands use IIR filters. This means that the phase response of one band differs from others which can cause frequency cancellations, etc (especially around the cross over's splitting points).
Reading about this issue I found that one can use 1 pole AP (all pass) or 2 pole AP on some specific bands. The logic is to fit the phase response of one band with the other.
However, 1 Pole AP and 2 pole AP are very crude tools for this mission. 1 pole AP has a 180 [deg] phase response with 90 [deg] around the cutoff.
What if I need, as an example, a 45 [deg] phase shift? How about more complex phase curves?
I'm looking for a tool (Python? MATLAB? other ?) to design a complex phase response system which doesn't effect the magnitude (frequency response).
Any ideas ?
I'm building a three band system in which some bands use IIR filters. This means that the phase response of one band differs from others which can cause frequency cancellations, etc (especially around the cross over's splitting points).
Reading about this issue I found that one can use 1 pole AP (all pass) or 2 pole AP on some specific bands. The logic is to fit the phase response of one band with the other.
However, 1 Pole AP and 2 pole AP are very crude tools for this mission. 1 pole AP has a 180 [deg] phase response with 90 [deg] around the cutoff.
What if I need, as an example, a 45 [deg] phase shift? How about more complex phase curves?
I'm looking for a tool (Python? MATLAB? other ?) to design a complex phase response system which doesn't effect the magnitude (frequency response).
Any ideas ?

Z1202
 KVRian
 1051 posts since 12 Apr, 2002
Re: All Pass filters for phase correction
I can't answer your question, but off the top of my head I would consider redesigning the bands so that only filters with responses of the form H^2 (where H is some other filter's response) would be used in each of the bands, including the splitting filters (kinda LinkwitzRiley style). In that case off the top of my head I'd guess that their phase responses can be exactly compensated with allpasses. But maybe I'm mistaken... Also don't know how far are you with your design and whether that's an option for you at all.

Fender19
 KVRist
 253 posts since 30 Aug, 2012
Re: All Pass filters for phase correction
I built a 4band Compressor several years ago using IIR filters combined with allpass filters for "phase compensation".
All the math worked on paper but in actual practice I found it an audible mess. What you have to keep in mind are the transient responses. Even though phase compensation works in the math it is really only true for steadystate situations. You could still hear phasey interactions when band gains were changed (i.e., the transient response was not good).
Long story short, I ended up using linear phase FIRs instead. No phase shifts, period. All bands stayed time and phasealigned regardless of gain. Sounded much more solid.
All the math worked on paper but in actual practice I found it an audible mess. What you have to keep in mind are the transient responses. Even though phase compensation works in the math it is really only true for steadystate situations. You could still hear phasey interactions when band gains were changed (i.e., the transient response was not good).
Long story short, I ended up using linear phase FIRs instead. No phase shifts, period. All bands stayed time and phasealigned regardless of gain. Sounded much more solid.

matt42
 KVRian
 1106 posts since 9 Jan, 2006

camsr
 KVRAF
 6931 posts since 17 Feb, 2005
Re: All Pass filters for phase correction
Yep, that's going to be a problem. The phase response of the "series" filter in one band would be required in all the other bands. This isn't a rule or anything, it's possible if there's harmonic distortion or other decorrelating elements in the one band, it would be possible to filter that band in series without the same cancellations.

Ross21
 KVRist
 70 posts since 25 Jun, 2011
Re: All Pass filters for phase correction
What should be the minimum FIR length (in samples) to build a decent 3 band crossover (say 12/18/24 db per octave) ?Fender19 wrote: ↑Mon Apr 15, 2019 2:18 pmI built a 4band Compressor several years ago using IIR filters combined with allpass filters for "phase compensation".
...
Long story short, I ended up using linear phase FIRs instead. No phase shifts, period. All bands stayed time and phasealigned regardless of gain. Sounded much more solid.
I guess it is a few thousands of samples at least ??

Fender19
 KVRist
 253 posts since 30 Aug, 2012
Re: All Pass filters for phase correction
It depends on the frequency. A crossover point at 4k doesn't require too many samples but at 200Hz it can require a hundred or more. It depends on how steep you want the roll off and how much stop band attenuation you want.Ross21 wrote: ↑Tue Apr 16, 2019 4:40 amWhat should be the minimum FIR length (in samples) to build a decent 3 band crossover (say 12/18/24 db per octave) ?Fender19 wrote: ↑Mon Apr 15, 2019 2:18 pmI built a 4band Compressor several years ago using IIR filters combined with allpass filters for "phase compensation".
...
Long story short, I ended up using linear phase FIRs instead. No phase shifts, period. All bands stayed time and phasealigned regardless of gain. Sounded much more solid.
I guess it is a few thousands of samples at least ??
Also, if you are using a "sinc" filter kernel the rolloff is not in dB/oct. It's basically "brick wall" where the actual slope and attenuation depends on number of sample points, filter kernel and window function. There are other filter kernels you can use for different slopes but it's not "cookbook" AFAIK.
Selecting all those options is where the "art" of plugin design comes in.
BTW  a "trick" you can use with IIR filters is "subtractive" filtering. For example, instead of trying to match a low pass to a high pass to create a smooth crossover you simply subtract one or the other from the input signal. For example, High pass = Input  Low pass. This guarantees the (unaltered) signal will recombine to unity and the phase shifts line up. The slopes of the two filters will not be the same but that usually doesn't matter. Sometimes this is all you need for something like a compressor.

mystran
 KVRAF
 5278 posts since 12 Feb, 2006 from Helsinki, Finland
Re: All Pass filters for phase correction
FIR filters are usually not designed for db/octave, but in general, you should usually think of the length of the FIR filter in terms of wavelength at cutoff (or equivalently "zero crossings") rather than samples. Longer filters give you a steeper transition from passband to stopband, but in order to get the same shape (at least to a good approximation) at half the cutoff, you need to make the filter twice as long in terms of samples (which keeps it same length in terms of wavelength at cutoff). For windowed designs, you can in fact simply stretch the whole filter in time.Ross21 wrote: ↑Tue Apr 16, 2019 4:40 amWhat should be the minimum FIR length (in samples) to build a decent 3 band crossover (say 12/18/24 db per octave) ?Fender19 wrote: ↑Mon Apr 15, 2019 2:18 pmI built a 4band Compressor several years ago using IIR filters combined with allpass filters for "phase compensation".
...
Long story short, I ended up using linear phase FIRs instead. No phase shifts, period. All bands stayed time and phasealigned regardless of gain. Sounded much more solid.
I guess it is a few thousands of samples at least ??
If you'd like Signaldust to return, please ask Katinka Tuisku to resign.

mystran
 KVRAF
 5278 posts since 12 Feb, 2006 from Helsinki, Finland
Re: All Pass filters for phase correction
This works if all you want to do is split the signal and then recombine. Unfortunately, as soon as you do any processing with the individual bands (ie. even change the gain of one of them) it's no longer quite sufficient and you start to get "phasing" problems.Fender19 wrote: ↑Tue Apr 16, 2019 8:05 amBTW  a "trick" you can use with IIR filters is "subtractive" filtering. For example, instead of trying to match a low pass to a high pass to create a smooth crossover you simply subtract one or the other from the input signal. For example, High pass = Input  Low pass. This guarantees the (unaltered) signal will recombine to unity and the phase shifts line up. The slopes of the two filters will not be the same but that usually doesn't matter. Sometimes this is all you need for something like a compressor.
What you really need is a crossover design that (1) sums back to allpass and (2) keeps all individual bands in phasealignment. It's the second property that allows you to manipulate the bands (at least with linearphase processing, such as gain adjustments) without causing phase problems. Note that it's impossible to design a (causal, at least) IIR crossover network that is phasecoherent and sums back to the original signal without phaseshifts (ie. you will always have to accept allpass response or use a linearphase filter instead).
The classic design that satisfies both properties is LinkwitzRiley. In The Art of VA Filter Design, Vadim (Z1202) describes some elliptic filters (or at least filters based on elliptic filters; see the book) that supposedly work as well if you don't mind some ripple (although I haven't personally looked at those, other than observing that they are mentioned in the book).
If you'd like Signaldust to return, please ask Katinka Tuisku to resign.

Z1202
 KVRian
 1051 posts since 12 Apr, 2002
Re: All Pass filters for phase correction
Actually the book has a description of a general framework for the filters which sum up to an allpass. "Elliptic LinkwitzRiley" are just a particular case of that. This was developed based on our discussion here at KVR including you and Max M.mystran wrote: ↑Tue Apr 16, 2019 1:43 pmThe classic design that satisfies both properties is LinkwitzRiley. In The Art of VA Filter Design, Vadim (Z1202) describes some elliptic filters (or at least filters based on elliptic filters; see the book) that supposedly work as well if you don't mind some ripple (although I haven't personally looked at those, other than observing that they are mentioned in the book).
However when we're talking about simply phasecompensating a filter, such as e.g. a lowshelving filter which could be used as a part of the band's processing (rather than a part of the crossover), we need an allpass whose phase response matches the one of a filter in question. In that case, given the filter has a response of the form (H1(s)/H2(s))^2 we could compensate the phase shift using an allpass H1(s)*H2(s)/H1(s)*H2(s) (up to the sign, which I ignore for simplicity of argument). Now that I explicitly wrote this formula out, I notice that the original filter must be maximum phase, so we either can convert it to maximum phase, or (probably a better idea) convert it to "zerophase numerator": H1(s)H1(s)/H2^2(s) in which case the compensating allpass simply becomes H2(s)/H2(s). Notice the obvious similarity to the generalized LinkwitzRiley. Disclaimer: all of that written off the top of my head, mistakes are possible.

mystran
 KVRAF
 5278 posts since 12 Feb, 2006 from Helsinki, Finland
Re: All Pass filters for phase correction
This is rather offtopic, but I just can't resist: (causal, stable) maximumphase filters are also handy when you want to replace the (scalar) feedback coefficient of an allpass filter with an IIR filter. This would obviously be a rather silly thing to do with allpass filters based on unitdelays, but it makes it possible to build allpass comb filters that have frequency dependent decay times, while still keeping the unitary frequency response and efficient delaybased implementation.
If you'd like Signaldust to return, please ask Katinka Tuisku to resign.

Fender19
 KVRist
 253 posts since 30 Aug, 2012
Re: All Pass filters for phase correction
Actually, LwR doesn't work well either (I've tried it) and the reason is the transient response. Run a square wave through a LinkwitzRiley crossover and see what happens to the edges of the recombined signal  especially when you start manipulating band gains.
IMO, the best crossover filter for multiband processors is linear phase FIR. HOWEVER, some people complain about the "preringing" of FIRs  so it's all a matter of taste in practical application, i.e., the art of audio design.

mystran
 KVRAF
 5278 posts since 12 Feb, 2006 from Helsinki, Finland
Re: All Pass filters for phase correction
The allpass phaseshift will distort the timedomain waveform and transient response. This certainly tends to be audible (for better or worse) especially at low crossover frequencies and more so with increasing filter orders. Whether you prefer this phaseshift or FIR preringing (and latency) in any given situation is obviously largely a matter of taste.Fender19 wrote: ↑Wed Apr 17, 2019 7:54 amActually, LwR doesn't work well either (I've tried it) and the reason is the transient response. Run a square wave through a LinkwitzRiley crossover and see what happens to the edges of the recombined signal  especially when you start manipulating band gains.
However, the phasecoherence (ie. all bands have the same phaseshift) of LinkwitzRiley filters means that the overall magnitude response is still a simple sum of the magnitude responses of the individual bands and the phaseshift (undesirable as it may be) is independent of the band gains. In other words, the result is essentially equivalent to first applying singleband allpass filter and then using a linearphase crossover to do the multiband processing.
If you'd like Signaldust to return, please ask Katinka Tuisku to resign.