# How to achieve an arbitrary phase shift? [duplicate]

To help demonstrate why a time delay appears as a linear phase shift and not a constant phase shift I wanted to plot what a constant phase shift looks like.

I have been looking at the Hilbert transform, which shifts the phase (of positive frequencies) by $$-90^\circ$$, but I was unable to find a transform or technique that allowed shifting the phase by an arbitrary amount.

How can I shift the phase of a signal arbitrarily?

• Take FFT, then find the magnitude and phase, and add arbitrary phase. adding constant phase only make your signal complex and do nothing special! – Mohammad M Jul 4 '19 at 21:00
• If you use an FFT a different value needs to be added to each frequency, based on the ratio of the frequencies. – Moti Jul 5 '19 at 6:57

You can't design a filter that creates a phase shift that's constant with frequency for real valued input (if that's what you are trying to do).

A Hilbert transformer appears to be doing this. However, the problem is, you can't implement a perfect Hilbert transformer since it's non causal with an infinite length impulse response.

The tricky part is that the DC and Nyquist components of the spectrum have to be real valued and that the phase at these frequencies is constrained to $$0$$ or $$\pi$$. Any phase shifter would have to have a transition band from DC to the to target phase and from the target phase to Nyquist.

That's exactly what happens if you design a real-world Hilbert transformer: you trade off the size of the transition bands against the length & complexity of the filter.

The class of filters that only manipulate phase and not the amplitude are called allpass filters. One can easily show that

• Allpass filters have a phase that's monotonously decreasing
• For an allpass filter of oder $$N$$ the phase from DC to Nyquist decreases by $$N \cdot \pi$$
• Allpass have zeros that are inverses of the poles,
• The z-transform numerator polynomial is the reverse of denominator polynomial

Of course you can always design an "approximation" that's good enough for your requirement. You'd have to specify the target bandwidth, max phase error, max amplitude error and then deploy a suitable FIR or IIR design method

Even an approximate design of absolute phase shift is quite difficult, especially if you have latency or causality constraints. Constant relative phase shift is a lot easier. A popular technique is to run a signal through two parallel allpass filters which are designed to have a constant phase difference over the frequency area of interest. The outputs have identical amplitude as the input but have approximately constant phase shift with respect to each other (although not with respect to the input)