# How to calculate arbitrary phase shift in discrete signal?

When I have digital audio signal, represented in samples, I can easily phase-shift the signal by 180° by simply inverting the value of each sample.

But what if I want to phase shift an arbitrary voice audio signal by say +90° or -90°?

How do I transform an arbitrary, discrete signal by phase-shifting it by an arbitrary phase angle?

The answers to this question explain the solution for the continuous-time case. In discrete time, the solution is completely analogous. The impulse response of a phase shifter with phase shift $\theta$ is given by

$$h[n]=\cos(\theta)\delta[n]+\sin(\theta)g[n]\tag{1}$$

where $g[n]$ is the impulse response of an (ideal) discrete-time Hilbert transformer. Eq. $(1)$ shows that the solution is just a linear combination of the identity system and a Hilbert transformer (which performs a $90$ degree phase shift).

• I used to build analog phase shifters using this approach in the 90's, as vector modulators. The quadrature splitter was built with all pass filters for providing a broad frequency range for the 90° splitter (the products I worked on covered 10MHz to 500MHz), after the splitter were two bi-phase attenuators (one with a DC value proportional to the cosine of the desired phase shift and the other with a DC value proportional to the sine of the desired phase shift and then the output of the two attenuators were summed through a 0° combiner. Multipliers (mixers) work as well but are reflective. – Dan Boschen Sep 2 '18 at 1:51

The problem is that you need a phase shift that is constant across all frequencies.

You'd classically do that with a Hilbert transformation.

• Erm, OK, could you elaborate a tiny bit? I can do discrete hilbert tranformation, and then what? – polemon May 4 '18 at 11:03
• My (second) guess would be to make an analytic representation by taking your signal $s(t)+i H[s(u)](t)$, then multiply with $e^{i\phi}$ to shift your phase, and then take the real part of the result. This seems to be the same as taking FFT, multiply with $e^{i\phi}$, make it the FFT symmetric again, calculate IFFT. – BNJMNDDNN May 4 '18 at 12:04
• after the HT you've got a 90° shifted signal – Marcus Müller May 4 '18 at 12:44
• @MarcusMüller what if I want to shift the signal by an arbitrary amount? Can I use HT and pass a parameter that denotes the phase shift? – polemon May 7 '18 at 2:48
• No. But arbitrary phase shifts are a different problem, and you should ask a new question, with details about what you want to solve! – Marcus Müller May 7 '18 at 6:04

To implement a phase shift you can use all pass structures which pass a wide range of frequencies with constant amplitude and only changing the phase. Note that these are dispersive structures when the phase is constant which means the time delay of each frequency component is changing (since time delay is the derivative of phase with frequency) so may cause significant distortion (you may actually want a constant delay and not a constant phase?). Also it is not possible to have a constant phase over ALL frequencies so you would specify a finite band of interest and minimize error in that band in your implementation. For more details on all pass filter structures see https://en.m.wikipedia.org/wiki/All-pass_filter

• Well, most DAWs provide for the ability to phase shift a channel between -180° to 180°. I want to replicate and understand that function better. Hence my question. For my understanding, it is a constant phase shift of all frequencies by an arbitratry (i.e. user selectable) amount. – polemon Sep 2 '18 at 0:23
• If you shifted an audio channel that contains a broad range of frequencies by a fixed phase over all frequencies, my understanding is that it would significantly distort the signal. Is that the intention? What is the purpose of the phase shift in this application? – Dan Boschen Sep 2 '18 at 0:27
• Some instruments are recorded from several positions. For instance a drum can be recorded from the top and bottom. Let's call the top one mic A and the bottom one mic B. Some (most) frequencies of mic B will be phase-shifted by 180° compared to mic A. That's a simple example. Whenever there's one instrument recorded by several microphones from various angles, that might create a problem, when pre-mixing that channel (i.e. mixing all microphones into one compound channel for an instrument, for instance). – polemon Sep 2 '18 at 0:55
• Would a delay correction then be the best solution? A delay would align the signals in time without introducing dispersive distortion – Dan Boschen Sep 2 '18 at 0:59
• Possibly. I'm more interested in the signal processing algorithm itself, rather than the actual use-case scenarios, though. I'm wondering about the concept and the math behind it. Less so about the practical application. – polemon Sep 2 '18 at 1:56