Hello all, i am designing a low pass filter and high pass filter to pass my audio samples. in matlab i checked out both butterworth and chebyshev(cheby2) 3rd order filter. I have observed there is a lot of differance in the phase plot of both the filters. Now my query went to what actuall effect of phase in audio? please anybody help me in solving this. Looking for the reply, With warm regards, -Prasad

# Importance of phase in Audio

Started by ●July 26, 2006

Reply by ●July 26, 20062006-07-26

mailprassi@gmail.com wrote: ...> i am designing a low pass filter and high pass filter to pass my > audio samples. in matlab i checked out both butterworth and > chebyshev(cheby2) 3rd order filter. > I have observed there is a lot of differance in the phase plot of > both the filters. > Now my query went to what actual effect of phase in audio? please > anybody help me in solving this.there is some basic stuff that i think everybody agrees with and then some other stuff that becomes more controversial. a few years ago, the JAES published a letter i wrote where i was a bit critical of Andrew Horner, who was writing a lot of papers on Wavetable Synthesis (not to be confused with the PCM sample playback that the marketing dept. of some soundcard chip manufacturers like to call "wavetable synthesis") with many good parts in some the papers, who, without any real justification, was just setting the phase components of all of the harmonics of his wavetable tone to 0. i thought (and still think) that it was both unnecessary to zero the phase of the harmonics in wavetable, changed the waveshape and potentially made for discernable differences. here is the more uncontroversial (for single mono-channel sounds, for stereo if there is phase shift applied to one channel that is different than what is applied to the other, you will notice a difference): 1. a delay line is a sorta "all-pass filter" (APF) that causes a linear phase shift (with respect to frequency) which gets translated to constant "phase delay" and constant "group delay" (w.r.t. frequency) and the two are equal to each other. the transfer function in the z-plane is: H(z) = z^(-N) where N is the number of samples delay. the continuous-time (s-plane) transfer function is: H(s) = e^(-s*N*T) where 1/T is the sampling frequency. if the delay is short enough that you cannot detect the delay, the phase shift is also undetectable. if the delay is long enough for you to detect it (that is somehow you noticed that the audio is delayed) then the sole effect of the phase shift is nothing but delaying the sound. accounting for the delay, there would be no additional effect. i think this is obvious. 2. there is another kind of APF which is not phase linear (nor, as a consequence, constant phase delay or group delay w.r.t. frequency). these APFs have a z-plane transfer function of: H(z) = (1- p*z^N) / (z^N - p) = (z^(-N) - p) / (1 - p*z^(-N)) which can be made out of a single delay line (of length N samples) and some feedback, scaling (p can be anything so that |p| < 1)), and summers. if N=1, it's a simple 1st-order APF and p is equal to the single pole while q=1/p is the reflected zero. if N>1, then there are more poles and zeros (ya gotta factor the S.O.B.) but all the poles will have zeros reflected about the unit circle with the mapping q=1/p. if you were to represent this as a continuous-time system (s-plane), the transfer function would be H(s) = (e^(-s*N*T) - p) / (1 - p*e^(-s*N*T)) . so the question might be, what effect of this APF on phase will be detectable? if |p| is close to 1 and the length of the delay is perceptually long (you will hear *both* the recursively delayed input signal and the first undelayed input scaled by -p) say N*T = 1/2 second, there will clearly be a perceived effect. it will sound like some echo box or, as the delay is shortened, a cheap reverberator. but there will be values of p and N*T that the effect of the APF becomes less noticable or not noticeable. if |p| << 1 or if N*T <<< 1 second (notice the 3 "<<<"), you might not notice the effect on any kind of signal. even with these APFs, the discernability of phase shift will also depend on the nature of the input signal. in the case of the a solid tone that has been on forever (no transients), i don't think any of us will detect an effect of any APF, if there are no amplitude non-linearities in the signal chain (make sure speakers/amps are not overdriven). an example to try with MATLAB (or whatever) is comparing this bandlimited square wave: x(t) = cos(w0*t) - (1/3)*cos(3*w0*t) + (1/5)*cos(5*w0*t) - (1/7)*cos(7*w0*t) ... (stop at some finite term less than Nyquist) to this waveform y(t) = cos(w0*t) + (1/3)*cos(3*w0*t) + (1/5)*cos(5*w0*t) + (1/7)*cos(7*w0*t) ... clearly x(t) and y(t) do not have similar waveshape. y(t) is not a simple delayed version of x(t). x(t) approaches a square wave (with finite number of terms) and y(t) becomes very spikey (which is why i put in the non-linearity caveat). if your speakers or amp or anything else in the signal chain do not clip those spikes in y(t), and if you make sure that the number of terms is low enough that the highest frequency term is well below Nyquist, i doubt any of us will hear a difference between x(t) and y(t). i might have posted a MATLAB program demonstrating this in the past (can't find it now). Now that being said, even in cases where absolute phase cannot be heard, the *change* in phase (with respect to time) causes a frequency detuning (equal to that time rate of change) and if that detuning is sufficiently large (that's another whole perceptual thing that needs to be explored in a decent scholarly sense), you will hear a difference. also, that APF thought experiment above (with sufficiently large |p| and N*T) will show an effect of phase shift on *transient* and changing signals (not constant tones that were on forever). but my complaint with Horner in the AES letter is that these transient (quasi-periodic) signals are the interesting ones we are trying to synthesize with Wavetable Synthesis. so, if you apply identical APFs to both channels of your stereo system, you will probably not hear much difference unless both the feedback coefficient, p, and delay length, N*T, get sufficiently large and that these APFs are applied to dynamic music/audio. in some special cases, you can find that the APFs have no discernable effect. r b-j

Reply by ●July 26, 20062006-07-26

robert bristow-johnson wrote:> > mailprassi@gmail.com wrote: > ... >> i am designing a low pass filter and high pass filter to pass my >> audio samples. in matlab i checked out both butterworth and >> chebyshev(cheby2) 3rd order filter. >> I have observed there is a lot of differance in the phase plot of >> both the filters. >> Now my query went to what actual effect of phase in audio? please >> anybody help me in solving this. >* snip *> > so, if you apply identical APFs to both channels of your stereo system, > you will probably not hear much difference unless both the feedback > coefficient, p, and delay length, N*T, get sufficiently large and that > these APFs are applied to dynamic music/audio. in some special cases, > you can find that the APFs have no discernable effect. >It seems that some are able to hear a pre-echo in transient sounds (e.g., percussions) filtered with certain linear-phase FIR filters. Thus, not only amplitude response and phase response affect the sound, but also the shape of the impulse response. Of course impulse response is defined by amplitude and phase response (and vice versa), however, pre-echo is explained more intuitively by the shape of the impulse response. Then again, I have never heard this phenomenom (or even tried to hear) and some claim that the pre-echo shouldn't be audible (in LP-FIR EQ applications). Audibility obviously depends on the impulse response. What I'm trying to say, is that when it comes to high-end audio, listener is the judge of good sound. Linear phase isn't everything, some even consider it bad. To answer the OPs question, there is likely no audible effect on sound caused by the non-linear phase. Nonlinear phase causes different parts of the signal to delay unequally. When the phase is sufficiently close to linear, this effect isn't audible. However, in extreme cases, two consecutive bandlimited pulses can even change places when filtered (due to delay of one pulse w.r.t. other). -- Jani Huhtanen Tampere University of Technology, Pori

Reply by ●July 26, 20062006-07-26

Prasad wrote:> Hello all, > > i am designing a low pass filter and high pass filter to pass my > audio samples. in matlab i checked out both butterworth and > chebyshev(cheby2) 3rd order filter. > I have observed there is a lot of differance in the phase plot of > both the filters. > Now my query went to what actuall effect of phase in audio? please > anybody help me in solving this.I got some interesting articles by googling for "is phase audible".

Reply by ●July 26, 20062006-07-26

Andor wrote:> > I got some interesting articles by googling for "is phase audible"."article_s_" (plural)? i got one hit. some guy's powerpoint in pdf about watermarking and hiding bits: When is phase audible? =B7 Sometimes ... in certain compound tones with frequency components lying within a critical band s(t) =3D A*[ (1/2)*cos((w1-w2 )*t) + cos(w1*t + phi) + (1/2)*cos((w1+w2 )*t) ] that's not the only case. but it's another good special "pathological" case. i invite anyone with MATLAB to run this program (or translate it to Mathcad or Octave or Python or Mathematica or whatever). the waveform transistions in such a way that it looks pathologically different, but sounds the same. especially if max_harmonic is about 10 or 15. ___________________ % % square_phase.m % % a test to see if we can really hear phase changes % in the harmonics of a Nyquist limited square wave. % % (c) 2004 rbj@audioimagination.com % if ~exist('Fs') Fs =3D 44100 % sample rate, Hz end if ~exist('f0') f0 =3D 110.25 % fundamental freq, Hz end if ~exist('tone_duration') tone_duration =3D 2.0 % seconds end if ~exist('change_rate') change_rate =3D 1.0 % Hz end if ~exist('max_harmonic') max_harmonic =3D floor((Fs/2)/f0) - 1 end if ~exist('amplitude_factor') amplitude_factor =3D 0.25 % this just keeps things from clipping end if ~exist('outFile') outFile =3D 'square_phase.wav' end % make sure we don't uber-Nyquist anything max_harmonic =3D min(max_harmonic, floor((Fs/2)/f0)-1); t =3D linspace((-1/4)/f0, tone_duration-(1/4)/f0, Fs*tone_duration+1); detune =3D change_rate; x =3D cos(2*pi*f0*t); % start with 1st harmonic n =3D 3; % continue with 3rd harmonic while (n <=3D max_harmonic) % lessee if it's an "even" or "odd" term if ((n-1) =3D=3D 4*floor((n-1)/4)) x =3D x + (1/n)*cos(2*pi*n*f0*t); else x =3D x - (1/n)*cos(2*pi*(n*f0+detune)*t); detune =3D -detune; % comment this line in an see some end % funky intermediate waveforms n =3D n + 2; % continue with next odd harmonic end x =3D amplitude_factor*x; % x =3D sin(pi/2*x); % toss in a little soft clipping plot(t, x); % see sound(x, Fs); % hear wavwrite(x, Fs, outFile); % remember ___________________ if you run this under ideal linear playback conditions, it's unlikely you'll be able to hear the change in waveshape. if there is a slight non-linearity in between, you may very well. i have an ongoing disagreement with Andrew Horner who has just published, in the JAES, his umpteenth paper about Wavetable Synthesis where he just assumes, at the very beginning, that phase is inaudible and he can set phase to whatever he wants.=20 r b-j

Reply by ●July 26, 20062006-07-26

ooops. robert bristow-johnson wrote: ...> if you run this under ideal linear playback conditions, it's unlikely > you'll be able to hear the change in waveshape. if there is a slight > non-linearity in between, you may very well. i have an ongoing > disagreement with Andrew Horner who has just published, in the JAES, > his umpteenth paper about Wavetable Synthesisthis was copied from an earlier post of mine and i didn't read it enough to see it contained dated information. Andrew published that paper a couple of years ago. he may have published continuations to it since, but i can't remember.> where he just assumes, at > the very beginning, that phase is inaudible and he can set phase to whatever he wants. > > r b-j

Reply by ●July 27, 20062006-07-27

robert bristow-johnson wrote:> Andor wrote: > > > > > I got some interesting articles by googling for "is phase audible". > > "article_s_" (plural)? i got one hit. some guy's powerpoint in pdf > about watermarking and hiding bits:Don't know which Google you used, mine revealed this: http://www.google.ch/search?hl=de&q=is+phase+audible&meta= The second hit seemed quite relevant. There's more further down. Regards, Andor

Reply by ●July 27, 20062006-07-27

Andor wrote:> robert bristow-johnson wrote: > > Andor wrote: > > > > > > > > I got some interesting articles by googling for "is phase audible". > > > > "article_s_" (plural)? i got one hit. some guy's powerpoint in pdf > > about watermarking and hiding bits: > > Don't know which Google you used,i used quotes (which i mistakenly thought you did).> mine revealed this: > > http://www.google.ch/search?hl=de&q=is+phase+audible&meta= > > The second hit seemed quite relevant.ya.> There's more further down.i'm wondering - did anyone run my MATLAB program? you can use the axis() command to zoom in and look at the waveform. r b-j

Reply by ●July 27, 20062006-07-27

robert bristow-johnson wrote: ...> i'm wondering - did anyone run my MATLAB program? you can use the > axis() command to zoom in and look at the waveform.Yes. A normal square wave I get with this code: % x = x - (1/n)*cos(2*pi*(n*f0+detune)*t); x = x - (1/n)*cos(2*pi*(n*f0)*t); The wave that your original code x = x - (1/n)*cos(2*pi*(n*f0+detune)*t); % x = x - (1/n)*cos(2*pi*(n*f0)*t); generates sounds like a flanged version of the first. Very audible difference. Regards, Andor

Reply by ●July 27, 20062006-07-27

Andor wrote:> robert bristow-johnson wrote: > ... > > i'm wondering - did anyone run my MATLAB program? you can use the > > axis() command to zoom in and look at the waveform. > > Yes. A normal square wave I get with this code: > > % x = x - (1/n)*cos(2*pi*(n*f0+detune)*t); > x = x - (1/n)*cos(2*pi*(n*f0)*t); > > The wave that your original code > > x = x - (1/n)*cos(2*pi*(n*f0+detune)*t); > % x = x - (1/n)*cos(2*pi*(n*f0)*t); > > generates sounds like a flanged version of the first. Very audible > difference.try it with a reduced number of harmonics. maybe with max_harmonic = 10. r b-j