How does phase shift in filter work?

Started by ItsGiusto, October 20, 2023, 07:34:01 PM

Previous topic - Next topic

ItsGiusto

I have a bit of a theoretical question. I've never really understood how phase shifting works when applying a filter. Does it change the phase of a frequency, but keep the frequency at the same time in the time domain, or does it shift the frequency in time? I think that for theoretical infinite sine waves, the difference doesn't matter, but of course that's not the case in real life.

For example, I did a mod on my phase 90 to make the mix resistor switchable, to switch to just the wet signal. When you switch to just wet signal, it doesn't sound like a phaser anymore, because you're not getting the frequency cancellation. But you still can hear the pedal doing something, and it sounds more like a vibrato. If the wet signal were really just a phase shift, then I wouldn't expect for the wet signal to sound audible at all.

RickL

#1
Someone is going to chime in with a more detailed answer, but the basic idea in a phaser is that the amount of phase shift is varied by the LFO (low frequency oscillator - i.e. the speed control). Different frequencies are cancelled as different amount of phase shift is applied.

As the phase shift is getting greater, the pitch shifts down, as is getting lesser, the pitch shifts up. This is why when the dry signal is not mixed in it sounds like vibrato.

You can actually stop the phase at any point by just disconnecting one of the wires from the speed control and you'll get either static phase shift (i.e. static frequency notches), if you're mixing the shifted signal with the dry signal, or no noticeable difference in sound, if the dry signal isn't mixed in (because it is the change in phase that gives the pitch shift).

The exact same principle applies to chorus and flanging, except there is an actual time delay applied to the signal.

Rob Strand

#2
Quote from: ItsGiusto on October 20, 2023, 07:34:01 PMI've never really understood how phase shifting works when applying a filter. Does it change the phase of a frequency, but keep the frequency at the same time in the time domain, or does it shift the frequency in time?

There's a number of things going on:

1) The filter itself is an all-pass filter.  For each input frequency the output is phase-shifted by some amount.  The amount of phase-shift is fixed for each frequency and depends on the filter parameters.

2) However, for a phaser the filter parameters are not constant.  The modulation waveform changes the filter parameters via the LDR/JFET/OTA.  That means at a given frequency the phase shift is no longer fixed.  The amount of phase-shift varies with the modulation.  This is called a time variant filter and it behaves differently to the fixed filter in (1).

3) The phase modulation phase causes the waveform to be compressed or stretched in time - sort of like an accordion.  When that occurs the perceived pitch of the signal changes.  That's the vibrato effect you here when you listen to the output of the all-pass filters with the dry signal disconnected.

This is perhaps the trickiest part to understand.  If you just set the filter parameters different you will get a different phase shift but not the accordion effect.  The accordion effect requires the filter parameters to *keep* changing.  If you have one cycle of a sine wave input, suppose the start of the cycle is not phase shifted and the end of the cycle is phase shifted a lot (as the modulation has modified the filter's phase shift) then the distance between the start and the end of the cycle will occur at different times to the input waveform  - the frequency appears different.

4) When the vibrato signal is mixed with the dry signal you get frequency notches.  The notch frequencies are also modulated.  That is where the phaser sound comes from.

It's possible to show mathematically how the instantaneous pitch modified by the phase modulation. I've posted this in the past and IIRC Electric Druid has some notes on his website.
Send:     . .- .-. - .... / - --- / --. --- .-. -
According to the water analogy of electricity, transistor leakage is caused by holes.

ItsGiusto

#3
Thanks, I think I understand more now about why the phaser sounds like a vibrato than previously, which is due to the changing phase shift for each frequency compressing and expanding each frequency.

Here's another related question, though: Why does an all-pass filter's impulse response look like an impulse train that alternates between positive and negative for each impulse?
When I search for what it looks like, I get images like this:



This seems like the allpass filter does have a time-delay component to it, due to the fact that the impulses are shifting the signal in time. In fact, if I remember correctly, I think that this sort of positive-negative alternating impulse train with the magnitude of each one getting smaller is very similar to the impulse response that you'd use if you want to remove echo from a signal. I think this sort of impulse response is used in processing communications, like telephone lines, for this purpose. What does de-echoing, or at least the time-delay component, have to do with the all-pass nature of the filter?

Rob Strand

[Shorter re-post due to logout on non-public forums]

Quote from: ItsGiusto on October 20, 2023, 08:40:51 PMThis seems like the allpass filter does have a time-delay component to it, due to the fact that the impulses are shifting the signal in time. In fact, if I remember correctly, I think that this sort of positive-negative alternating impulse train with the magnitude of each one getting smaller is very similar to the impulse response that you'd use if you want to remove echo from a signal. I think this sort of impulse response is used in processing communications, like telephone lines, for this purpose. What does de-echoing, or at least the time-delay component, have to do with the all-pass nature of the filter

The alternation is more about the ringing of high order filters.

There is an equivalent delay for all-pass filters, and in fact other filters.  It's called Group Delay.   If you have a true/constant delay the phase response is linear with frequency.   Group delay tends to vary with frequency.   Physicists call this type of thing dispersive.

The characteristic of all-pass systems is the step response goes the wrong way at some point.  If you have a step response which is positive in the steady state then at some point earlier, usually not long after the application of the step input, the output will go negative.  Kind of abstract and not so intuitive but that's what it does.

Send:     . .- .-. - .... / - --- / --. --- .-. -
According to the water analogy of electricity, transistor leakage is caused by holes.

octfrank

While written for a digital all-pass the concepts are the same for analog http://experimentalnoize.com/manuals/FXCore/app_notes/an-8.pdf The section "Serial First-Order All-Pass" is the basis of a phase shifter and shows why phase shifters always have pairs of all-passes
Frank Thomson
Experimental Noize

Rob Strand

#6
Quote from: octfrank on October 20, 2023, 11:29:58 PMWhile written for a digital all-pass the concepts are the same for analog http://experimentalnoize.com/manuals/FXCore/app_notes/an-8.pdf The section "Serial First-Order All-Pass" is the basis of a phase shifter and shows why phase shifters always have pairs of all-passes
On page 10 there is a square-wave response.  You can see the negative undershoots.   That's the undershoots in the step response I was talking about.
Send:     . .- .-. - .... / - --- / --. --- .-. -
According to the water analogy of electricity, transistor leakage is caused by holes.

ItsGiusto

Thanks. This is all interesting, and I liked that paper. But this is touching on another related question: I really don't understand how phase works with regard to delay.

I believe I completely understand why a delay can be represented as a linear phase response: in my mind, it's because in order to delay a signal by a constant amount of time, that constant amount of time would be represented as a linearly increasing number of cycles as you go up in frequency, because the wavelength of higher frequencies is less.

But this still doesn't make intuitive sense for me, because I still feel like in a delay, you're actually, well, delaying the signal. The signal is moving forward in the time domain. Whereas, I could picture another system that doesn't move the signal forward in the time domain, but could still have that same linear frequency response. Such a system would keep the signal where is is now, but instead change the phase of the sine waves that make up the signal.

So, I guess, the core of my question is that I'm still wondering, why does phase shift sometimes seem to imply actually moving the signal forward in the time domain, and sometime seem to imply that the signal is staying put, but just having the phase of each component sine wave reconfigured. Once again, I know that in the case of dealing with infinite sine waves, this distinction doesn't matter. But in real life, we never actually have infinite sine waves.

octfrank

In simple terms phase shift is always due to a delay. If I delay it long enough it looks like it shifted forward in time, i.e. if delay is 330 degrees it looks like it is advanced 30 degrees.
Frank Thomson
Experimental Noize

ItsGiusto

Does that mean that an allpass filter really is delaying the signal that comes into it, not just altering the phase?


Rob Strand

#11
The differences between true delay, phase delay and group delay are quite difficult to explain.  I can give mathematical definitions but they leave you with no intuition about what is going on.

In very loose terms.  Time delay doesn't need any explanation.  Phase is more of a steady state idea.  Group delay perhaps more of a transient idea.

Think about a signal being time delayed by half a cycle, that's 180 deg.  Then think about just inverting the polarity - not even phase shifting really.  Then think about a filter with 180deg phase shift.  If we look at those signal on an oscilloscope we can't tell the difference because in steady state it's all the same.  (So that's your infinite sinewave intuition kicking in.) The key differences show up when when you apply the signal.  The delayed signal comes out delayed with the same polarity.  The inverted signal comes out straight away but the initial part of the the waveform is upside down.  The phase-shifted waveform sort of appears like the time delay, but it doesn't really because a filter's transient response messes with the initial wave shape.

For the last case you can get some intuition from fig 5 and fig 6 on page 2.
https://radio-labs.com/designfile/dn004.pdf

The waveform sort of starts immediately but it does reach full output until some time later.  So it has no delay because the output appears immediately but also some effective delay because it doesn't get to full output until some time later.  Clearly not a true delay.

Analog networks all have this blurry starting edge.  Such networks tend to have a phase response which is non-linear and what follows from that is a frequency dependent delay.  The thing is for real networks all these effects are linked (in order for the maths/physics to be consistent).  As for how delay is created in analog networks.  In simple terms energy stored in capacitors and inductors then released later.  It's not a matter of how does the network "know" when to let out the signal.  It's more a matter of the maths/physics doing what it does and that looks like a delay.

A similar thing happens when the signal stops as well.

I know I haven't been precise in any of the above but you should be able to see how things can come about.  All the above applies to non-time varying filters.  When you have modulated filter like a phase you have all the additional complications that I listed earlier, especially the ability to change the pitch - in this case the filter is in a permanent a state of change which is bending the waveform.



This shows that the observed signal with the blurry delay is a result of the transient response of the network cancelling out (or beating with) the steady state response of the network.


Send:     . .- .-. - .... / - --- / --. --- .-. -
According to the water analogy of electricity, transistor leakage is caused by holes.

Mark Hammer

"Delay" is an appropriate term to use if one is comparing a single cycle of a wave to a phase-shifted version of same.  But "delay" is a term that conjures up a definite start and end-point; i.e., if some is delayed, then it started after something else, and may end after it as well.  If we are comparing a steady-state oscillation, with a phase-shifted version of itself, then it's a little confusing, and maybe even misleading to describe it as "delayed", since there is no real start or end that would permit measurement of the "delay".

Not a criticism of anyone.  Just a reminder that "group delay", "phase-shift" and similar terms are with reference to phase, and not to time.  Sometimes, yes, significant phase-shift can sound a bit like time delay, and very short time-delays can sound like phase shift (see here: https://www.diystompboxes.com/smfforum/index.php?topic=131306.0 ), but time and phase are cousins, not identical twins.

Rob Strand

#13
Quote from: Mark Hammer on October 21, 2023, 01:43:05 PMNot a criticism of anyone.  Just a reminder that "group delay", "phase-shift" and similar terms are with reference to phase, and not to time.  Sometimes, yes, significant phase-shift can sound a bit like time delay, and very short time-delays can sound like phase shift (see here: https://www.diystompboxes.com/smfforum/index.php?topic=131306.0 ), but time and phase are cousins, not identical twins

I did an experiment comparing group delay and true delay and I found in practice group delay was a good analog.   The experiment was something like:
- use headphones
- true delay to one ear, group delay to the other ear
- signal was a short-term transient
- try to adjust the delay so the sound appears to come from in directly front (ie. matched delay)

The filters were digital and IIRC had reasonably high order.
Send:     . .- .-. - .... / - --- / --. --- .-. -
According to the water analogy of electricity, transistor leakage is caused by holes.