• WANTED: Happy members who like to discuss audio and other topics related to our interest. Desire to learn and share knowledge of science required. There are many reviews of audio hardware and expert members to help answer your questions. Click here to have your audio equipment measured for free!

Does Phase Distortion/Shift Matter in Audio? (no*)

gberchin

Member
Joined
Apr 22, 2023
Messages
12
Likes
23
My understanding is polarity and 180deg inversion of phase are exactly the same in the steady state, but not at the beginning of the impulse. Is this wrong?

This is exactly correct.

Polarity inversion does not change the waveform in any way except that it is everywhere negated. Doesn't matter whether steady-state or transient; all it does is change the algebraic sign.

Phase shift of 180° is like applying a Hilbert Transform twice. In the steady-state, i.e., for one or more sinewaves that started at t = -infinity and continue unchanged to t = +infinity, it is the same as polarity inversion. But for transient waveforms, it is very different. See Figure 6 here for the impulse response of a Hilbert Transform, and imagine what convolving with it twice would do to transients.
 

KSTR

Major Contributor
Joined
Sep 6, 2018
Messages
2,785
Likes
6,230
Location
Berlin, Germany
This is exactly correct.

Polarity inversion does not change the waveform in any way except that it is everywhere negated. Doesn't matter whether steady-state or transient; all it does is change the algebraic sign.

Phase shift of 180° is like applying a Hilbert Transform twice. In the steady-state, i.e., for one or more sinewaves that started at t = -infinity and continue unchanged to t = +infinity, it is the same as polarity inversion. But for transient waveforms, it is very different. See Figure 6 here for the impulse response of a Hilbert Transform, and imagine what convolving with it twice would do to transients
One distinguished ASR member does not agree: https://www.audiosciencereview.com/.../analytical-analysis-polarity-vs-phase.29331/
180deg phase shift at all frequencies is equivalent to a polarity flip.
 

j_j

Major Contributor
Audio Luminary
Technical Expert
Joined
Oct 10, 2017
Messages
2,282
Likes
4,792
Location
My kitchen or my listening room.
Well, if you rotate the FFT of an entire song by pi, what do you do with the negative frequency half. Somebody should try that sometime. :) Or, just look at what a rotation of (cos(pi)+i*sin(pi) ) is.

Gonna be fun to do the two hilbert transforms in the real domain, though.
 

KSTR

Major Contributor
Joined
Sep 6, 2018
Messages
2,785
Likes
6,230
Location
Berlin, Germany
When we use a FIR filter design package and instruct it to generate the impulse response of a target that has unity magnitude and 180° phase at all frequencies, how does the impulse response look like? A simple negative Unit Impulse. That's enough of any additional practical proof on top of the math.
 

j_j

Major Contributor
Audio Luminary
Technical Expert
Joined
Oct 10, 2017
Messages
2,282
Likes
4,792
Location
My kitchen or my listening room.
When we use a FIR filter design package and instruct it to generate the impulse response of a target that has unity magnitude and 180° phase at all frequencies, how does the impulse response look like? A simple negative Unit Impulse. That's enough of any additional practical proof on top of the math.
Indeed. I'm somewhat puzzled this is an issue. Now anything other than zero or 180 gets "interesting".
 

KSTR

Major Contributor
Joined
Sep 6, 2018
Messages
2,785
Likes
6,230
Location
Berlin, Germany
Gonna be fun to do the two hilbert transforms in the real domain, though.
Well, if you rotate the FFT of an entire song by pi, what do you do with the negative frequency half. Somebody should try that sometime.
Indeed. I'm somewhat puzzled this is an issue. Now anything other than zero or 180 gets "interesting".
Yep. The IR of a 90deg filter (FIR filter kernel from an IFFT), say one with 8192 samples, spreads across the whole length, it's basically a sweep.
Convolved with itself, and back we are with a single -1 sample in the 16383 (2N-1) resulting Kernel. EDIT: I will do the experiment to check if this actually holds true, that is.
Likewise, convolving a 60deg filter three times will give (EDIT 'should', see above)the same result.

That means you can actually transform a complete song with two successive FIR 90deg shifters (or any other combination which sum up to 180deg everywhere) into its flipped polarity sister. The only requirement is that you don't truncate the intermediate convolution results. And if the filter size is larger than the song then there is no loss of precision even at the lowest frequencies, including any DC offset in the recording ;-)
 
Last edited:

j_j

Major Contributor
Audio Luminary
Technical Expert
Joined
Oct 10, 2017
Messages
2,282
Likes
4,792
Location
My kitchen or my listening room.
Yep. The IR of a 90deg filter (FIR filter kernel from an IFFT), say one with 8192 samples, spreads across the whole length, it's basically a sweep.
Convolved with itself, and back we are with a single -1 sample in the 16383 (2N-1) resulting Kernel. EDIT: I will do the experiment to check if this actually holds true, that is.
Likewise, convolving a 60deg filter three times will give (EDIT 'should', see above)the same result.

That means you can actually transform a complete song with two successive FIR 90deg shifters (or any other combination which sum up to 180deg everywhere) into its flipped polarity sister. The only requirement is that you don't truncate the intermediate convolution results. And if the filter size is larger than the song then there is no loss of precision even at the lowest frequencies, including any DC offset in the recording ;-)
Well, you're in trouble if you do the first 90 rotation on every line,then convert back to time domain, because it's gonna be complex (imaginary DC and Pi). But yes, the math works out if you keep complex intermediates.
 

gberchin

Member
Joined
Apr 22, 2023
Messages
12
Likes
23
Indeed. I'm somewhat puzzled this is an issue. Now anything other than zero or 180 gets "interesting".
Yes ... "interesting" is the keyword. The implication is that the Hilbert Transform of a Hilbert Transform is a negative impulse. And that the convolution of two impulse responses, both of infinite extent, can collapse into an impulse. I'll admit that I have trouble visualizing it, but I can't argue with the math.

So I learned something today, and I count it a good day when I learn something.
 

KSTR

Major Contributor
Joined
Sep 6, 2018
Messages
2,785
Likes
6,230
Location
Berlin, Germany
Well, you're in trouble if you do the first 90 rotation on every line,then convert back to time domain, because it's gonna be complex (imaginary DC and Pi). But yes, the math works out if you keep complex intermediates.
Hhm, actually that's not what I meant, I was referring to the time domain and direct convolution done there, with a +90 (or -90) deg kernel of finite length and thus finite bandwidth. I also have direct time-domain kernel/sequence generators, literally a bank of cosine oscillators.
I'll try to use these and make a test run to see if two convolutions with a 90deg kernel will render a true polarity inversion, provided the kernel is at least as long as the signal. If it is shorter some error must appear but I don't exactly know how it will look like and now I'm curious to find out.
 

j_j

Major Contributor
Audio Luminary
Technical Expert
Joined
Oct 10, 2017
Messages
2,282
Likes
4,792
Location
My kitchen or my listening room.
I must also point out that multiplying a signal by a real constant is exactly the same as multiplying the transform of the signal.

Ergo, since a phase shift of 180 degrees is represented as -1 + zero * i in complex form, it had better work to represent it as just -signal. Otherwise you've broken all of linear algebra.

This also shows transparently that any rotation other than 180 degrees must add an imaginary component to the signal.
 

j_j

Major Contributor
Audio Luminary
Technical Expert
Joined
Oct 10, 2017
Messages
2,282
Likes
4,792
Location
My kitchen or my listening room.
Hhm, actually that's not what I meant, I was referring to the time domain and direct convolution done there, with a +90 (or -90) deg kernel of finite length and thus finite bandwidth. I also have direct time-domain kernel/sequence generators, literally a bank of cosine oscillators.
I'll try to use these and make a test run to see if two convolutions with a 90deg kernel will render a true polarity inversion, provided the kernel is at least as long as the signal. If it is shorter some error must appear but I don't exactly know how it will look like and now I'm curious to find out.
Using a real kernel, it ought to work.
 

andyc56

Active Member
Joined
May 14, 2016
Messages
122
Likes
170
Yes ... "interesting" is the keyword. The implication is that the Hilbert Transform of a Hilbert Transform is a negative impulse. And that the convolution of two impulse responses, both of infinite extent, can collapse into an impulse. I'll admit that I have trouble visualizing it, but I can't argue with the math.

So I learned something today, and I count it a good day when I learn something.

Are you Greg, the FDLS guy?
 

UliBru

Active Member
Technical Expert
Joined
Jul 10, 2019
Messages
124
Likes
338
I'll try to use these and make a test run to see if two convolutions with a 90deg kernel will render a true polarity inversion, provided the kernel is at least as long as the signal. If it is shorter some error must appear but I don't exactly know how it will look like and now I'm curious to find out.

A quick test with a sample music track (9.469.740 samples) and applied 1st and 2nd Hilbert transform shows:
HilbertTime1.png


The arbitrary waveform snippet of the track shows the result after a first phase shift by 90°
After the second 90° phase shift the result is
HilbertTime2.png


So clearly the result looks like flipped with polarity. But it might be shifted by some delay. So the proof is now to add the two signals. In perfect case it should be 0.
Indeed the blue line in the chart already shows the sum. The frequency response of the music track and the sum looks like

HilbertMagnitude.png


We can see that the level of the sum is about -300 dB below the original level. This is simply caused by the resolution of the 64 bit double float calculation.
So we can conclude that the double phase shift is equal to flipping the polarity.

There is a weak part in this consideration. For very low frequencies (down to DC) we get some DC offset in the sum. Of course shifting DC by 90° causes some headache.
Anyway the length of the sample track is not long enough. Possibly it must be infinite to get a sum without DC offset.
 

KSTR

Major Contributor
Joined
Sep 6, 2018
Messages
2,785
Likes
6,230
Location
Berlin, Germany
As for the DC offset, maybe it could work like this:
Pad the song left and right with zeros to fit in a larger FFT size (maybe >= 2x), but remove (subtract the sample average) and note the DC offset of the whole sequence with padding.
Do the transforms, remove any DC and then subtract the noted DC.
 

pma

Major Contributor
Joined
Feb 23, 2019
Messages
4,608
Likes
10,778
Location
Prague
Another test on phase audibility, best with headphones at moderate medium level.
 

Attachments

  • PhaseTest_PMA_mono.zip
    1.6 MB · Views: 29

UliBru

Active Member
Technical Expert
Joined
Jul 10, 2019
Messages
124
Likes
338
Uli, how did you implement the transforms? Using a 16M FFT?
Hi Klaus,

basically it is caclulated like this
FFTFromReal(signal) (here the given length 9.469.740 samples)
Set DC to zero
(Re, Im) becomes (-Im, Re) by multiplying with i
IFFTToReal

My remarks about DC are not really correct. It should be clear that a 90° phase shift of DC should not change the DC. As the transform subroutine described above sets DC to 0 I have expanded it by calculating the DC of the signal and adding it after IFFT. Thus the 90° shifted signal contains the same DC as before (can you really imagine a 90° phase shift of DC?). And now a 2nd shift also keeps the DC. There is no logic in advance to change the DC sign with a 2nd shift until you exactly know that there are 2 shifts in sequence (applying a polarity switch would be preferred here). So indeed I have doubled the DC in my example and my conclusion was wrong.
 

MRC01

Major Contributor
Joined
Feb 5, 2019
Messages
3,486
Likes
4,113
Location
Pacific Northwest
The problem, which Renee explains in the page linked above, is the intuitive notion of a phase shift as sliding the entire waveform along the time axis some distance left or right (forward or back in time). For a steady-state sin/cos wave, slide it a half wavelength and you get the same thing as a polarity flip. But for a general musical signal, no amount of sliding any fixed distance will be the same as a polarity flip.

Sure, the transforms above do show that a 180* phase shift is the same as a polarity flip, but that 180* phase shift is at all frequencies, not the same thing as sliding the entire waveform by some fixed time delta T. For a single sin/cos wave they are the same because there's only 1 frequency!
 

j_j

Major Contributor
Audio Luminary
Technical Expert
Joined
Oct 10, 2017
Messages
2,282
Likes
4,792
Location
My kitchen or my listening room.
First, "sliding the signal back and forth" adds a phase shift to every frequency of phi = 2 * pi * f * t, where phi is the phase shift in radians, f is the frequency in Hz, and t is the time in seconds. This shows that you only get a phase shift of "pi" at ONE FREQUENCY, so sliding the waveform back and forth can not provide inversion of anything but one single frequency.

Second, once again, a phase shift of a signal in complex space is exactly described by a multiplication of the signal by cos phi + i * sin phi, where phi is the phase shift. Please note that at only 0 and pi phase shift is this not a complex signal. The i is the 'imaginary number' representing the quadraphase signal.

This is why your head hurts so very much trying to do a 90 degree phase shift of a real signal. This is also why 'DC' makes your head ache, because the DC and Pi components of the FFT are STRICTLY REAL. After you multiply the DC and Pi components by anything but 1 or -1, they have an imaginary component. If you take the IFFT with complex numbers at zero and pi, you get a complex OUTPUT. This is related to the problem in Laplace transforms, by the way, where you have to have matching number of poles and zeros, but that's only for old analog people to grok.

Remember, the DC and Pi result of any FFT for a real input ARE BOTH REAL. ALWAYS. Every other element can be real or not, and the negative (second half) of the FFT will be the complex conjugate of the first half, for each frequency. (remember that "frequency goes UP until you get to pi, then back down.) This is not a "good idea" its the basic math.
 
  • Like
Reactions: OCA
Top Bottom