I don’t know about you but I have always been confused about the group delay, phase delay, and sample delay in digital signal processing… Let’s clear this all up once and for all!

  1. What is a sample delay?
  2. What is a phase delay?
    1. How to Calculate the Phase Shift from the Transfer Function?
    2. Example Phase Response Plot
  3. What is a group delay?
    1. How to Calculate Group Delay from the Phase Delay?
    2. Example 1: Linear phase=constant group delay
    3. Example 2: Nonlinear phase=non-constant group delay
    4. Where Does the Term “Group Delay” Come From?
  4. Why Is Constant Group Delay or Linear Phase Important?
  5. Summary
  6. Bibliography

What is a sample delay?

The first one to start off is the sample delay.

A system that delays the input by a constant number of samples introduces a delay to the signal.

Whenever you see the z1z^{-1} delay block in a DSP diagram or in a difference equation, it delays the signal by 1 sample.

Let’s look at an example.

Here, we have an example signal x[n]x[n].

Example waveform.

Figure 1. Some signal.

What happens to it if we delay it by 4 samples?

Example waveform delayed by 4 samples.

Figure 2. Signal delayed by 4 samples.

As you can see at the output of the delay, the signal is simply delayed by 4 samples. We denote the delayed signal by x[n4]x[n-4].

Remember that by the sample delay of a system, we refer to the delay of the whole signal by some number of samples between the output and the input. Pure delay elements, do not introduce any other change beyond the delay.

I have discussed the delay in samples in more detail in the following article & video.

What is a phase delay?

Let’s consider once again the output of the system delayed by 4 samples.

Waveform of a signal consisting of 2 sines delayed by 4 samples.

Figure 3. Signal consisting of 2 sines delayed by 4 samples.

This signal consists of 2 sines: one of them has period equal to 16 samples and the other one has period equal to 8 samples.

Waveform of a sine with period of 16 samples.

Figure 4. Sine with period of 16 samples.

Waveform of a sine with period of 8 samples.

Figure 5. Sine with period of 8 samples.

If you don’t know what the period of a signal is, it’s the smallest positive number of samples after which the signal starts repeating itself. For example, the “2-sine” signal repeats every 16 samples.

Both sines inside the signal were delayed by the same number of samples. But how did their phase advance?

The phase of a sine is a value in the [0,2π)[0, 2\pi) range. The period of a sine is equal to 2π2\pi. So its phase tells us at which point in the period we are.

For the sine, whose period is 8 samples, 4 samples are half of its period. Therefore, 4 samples correspond to a shift of its argument (phase) by π\pi (half of the 2π2\pi period). Thus, the phase delay (or phase shift) of this sine is π\pi.

However, for the sine, whose period is 16 samples, 4 samples are just one quarter of its period. Therefore, 4 samples correspond to a phase delay of 142π=π2\frac{1}{4} \cdot 2\pi = \frac{\pi}{2}.

See? A delay in samples means different phase delays for different sines. To calculate the phase shift of a sine given its sample delay or vice versa, we need to know the period or the frequency of the sine.

How to Calculate the Phase Shift from the Transfer Function?

If we have the transfer function of a digital system or its frequency response H(ejω)H(e^{j\omega}), we can easily calculate its phase response as

argH(ejω),(1) \arg H\left(e^{j\omega}\right),\quad (1)

where arg\arg returns the principal argument of the given complex number in radians. The principal argument is always in the (π,π](-\pi, \pi] range. Therefore, this phase is also called a wrapped phase because it is wrapped to the (π,π](-\pi, \pi] range.

Example Phase Response Plot

Here is an example phase response plot. It is the phase response of the second-order Butterworth IIR lowpass filter with the cutoff frequency set to 14\frac{1}{4} of the Nyquist frequency.

IIR lowpass filter phase response plot.

Figure 6. Phase response of the second-order Butterworth IIR lowpass filter with the cutoff frequency set to 14\frac{1}{4} of the Nyquist frequency.

As you can see, this phase response is clearly nonlinear; in fact, all IIR filters have nonlinear phase.

Ok, we know what is the sample delay and the phase delay. Then, what is the group delay?

What is a group delay?

“Group delay” is probably the most misleading term in the history of DSP but I admit, it does make sense.

To understand the group delay let’s look at an example.

In a pure delay system, all frequency components at the input are delayed by a constant number of samples.

What if each frequency was delayed by a different number of samples?

To use our “2-sine” signal again, let’s say we delay the sine with the period equal to 8 samples by 4 samples and the sine with the period equal to 16 samples by 8 samples.

Here you can see the output of the described frequency-dependent delaying system.

Waveform of a signal consisting of 2 sines delayed with a frequency-dependent delay

Figure 7. Signal consisting of 2 sines delayed with a frequency-dependent delay.

Looking at the sines separately, at the output of this system the delayed sines look as follows.

Waveform of the sine with period of 16 samples delayed by 8 samples

Figure 8. Sine with period of 16 samples delayed by 8 samples (phase delayed by π\pi).

Waveform of the sine with period of 8 samples delayed by 4 samples

Figure 9. Sine with period of 8 samples delayed by 4 samples (phase delayed by π\pi).

What is interesting, now both sines have the same phase delay, π\pi. However, you can see that the output in Figure 7 looks different visually from the input although these are still those two sines; if you’re unsure that they are different, check the first nonzero samples of the delayed signal. The relative position of the sines changed and, thus, the waveform changed.

As you might guess at this point, the group delay is exactly the number of samples by which a single frequency component is delayed.

In our example, the group delay of the frequency corresponding to period 8 is 4 and the group delay of the frequency corresponding to period 16 is 8.

In the previous example, where the whole input was delayed by 4 samples, you saw that if the group delay is constant for all frequencies, the system does not alter the waveform visually, it simply delays it; we get a delay system as in the definition of the sample delay.

So constant group delay is equivalent to sample delay.

How to Calculate Group Delay from the Phase Delay?

Group delay can be easily calculated from the phase delay of the system

grd[H(ejω)]=ddω{argH(ejω)},(2) \text{grd}\left[ H(e^{j\omega})\right] = - \frac{d}{d\omega}\{\arg H\left(e^{j\omega}\right)\},\quad (2)

where

  • H(ejω)H(e^{j\omega}) is the complex frequency response of the system,
  • argH(ejω)\arg H(e^{j\omega}) is its phase response, and
  • ddω\frac{d}{d\omega} denotes the derivative with respect to the angular frequency ω\omega in radians per sample (ω=2πf/fs\omega = 2\pi f / f_s, where ff is a frequency in Hz and fsf_s is the sampling rate).

Example 1: Linear phase=constant group delay

Let’s look at an example of a constant-group delay filter.

Here is the phase response of our delay by 4 samples.

Wrapped phase response plot

Figure 10. Wrapped phase response of a 4-sample delay system.

You can see that the phase is wrapped: when it reaches π-\pi it jumps up to π\pi.

If we unwrap the phase, the phase response looks as follows.

Unwrapped phase response plot

Figure 11. Unwrapped phase response of a 4-sample delay system.

By the way, these plots were obtained using scipy.signal.freqz, numpy.angle, numpy.unwrap, and the matplotlib library 🙂

The derivative of the phase response with respect to the frequency is simply the tilt coefficient of this linear function. In this case, the derivative is constant at each frequency ω\omega (because the phase is linear) and can be calculated from the plot grid. Therefore, the group delay of this filter (negated derivative) is equal to 4ππ=(4)=4-\frac{-4\pi}{\pi} = -(-4) = 4. We obtained the group delay at each frequency: it is constant and equal to 4. Therefore, this system is a delay of 4 samples. And indeed it has linear phase.

Note: You can also calculate the group delay from the analytical form of the phase response. In the case of a pure delay of 4, the frequency response is ej4ωe^{-j4\omega} so the phase response is 4ω-4\omega. Thus, the negated derivative is 4.

Example 2: Nonlinear phase=non-constant group delay

Here is the plot of the group delay of the second-order Butterworth IIR lowpass filter with the cutoff frequency set to 14\frac{1}{4} of the Nyquist frequency whose phase response you’ve seen in Figure 6.

IIR lowpass filter group delay plot.

Figure 12. Group delay of the second-order Butterworth IIR lowpass filter with the cutoff frequency set to 14\frac{1}{4} of the Nyquist frequency.

This group delay was calculated with the scipy.signal.group_delay function.

As you can see, a nonlinear phase response resulted in a non-constant group delay.

Where Does the Term “Group Delay” Come From?

The group delay takes its name from the continuous frequency domain. Mathematically speaking, group delay describes the time delay of an infinitesimally small range of frequencies around some particular frequency ω\omega. This range of frequencies can also be called a “group” of frequencies, hence the name group delay. Clever, I know 😉

Why Is Constant Group Delay or Linear Phase Important?

If a system has linear phase, it means that its phase response is a linear function of angular frequency, typically of the form ωt0-\omega t_0.

If a system has linear phase, it has constant group delay t0t_0, which can be easily calculated by inserting argH(ejω)=ωt0\arg H\left(e^{j\omega}\right) =-\omega t_0 into Equation 2.

Well, if a system has a constant group delay, then it means that it does not alter the input waveform visually; its behavior can be represented as a frequency-dependent amplitude scaling and a frequency-independent delay.

Why is it important? Well, as you could see for the 2 sines example, the change in the outlook of the signal can be drastic. Also such drastic changes make the outcome less predictable when we start mixing multiple signals together. If the group delay is not constant we may run into phase cancellation issues.

That’s why we typically (but not always) prefer linear phase (=constant group delay) systems.

Unfortunately, only finite impulse response (FIR) filters can have linear phase and, thus, linear-phase systems introduce significant delay… But that’s a topic for another article 😎

Summary

In this article, you learned what is sample delay, phase delay, and group delay. You now know what is the difference between these three.

You also learned that systems (filters) with linear phase have constant group delay so their effect on the system can be described by a frequency-dependent gain and a frequency-independent delay in samples. Systems with linear phase are more predictable and, thus, more desirable.

With this knowledge you won’t be confused again when you stumble upon one of these “delay” terms!

If you want to know which other bits and pieces of knowledge are necessary for writing software that processes sound, check out my free Audio Plugin Developer Checklist!

Bibliography

[OppenheimSchafer10] Alan V Oppenheim, Ronald W. Schafer, Discrete-Time Signal Processing, 3rd Edition, Pearson 2010.