The tikzmagic extension is already loaded. To reload it, use:
  %reload_ext tikzmagic

The Dirac Comb function

The continuous-time comb function $C_T(t)$ is an important tool in signal processing and sampling theory and given by

$$C_T(t)=T\sum_{n=-\infty}^{\infty}\delta(t-nT).$$

Let us first draw this Dirac comb function. Due to the infinitely small width of the Dirac impulse, it is tough to numerically model the Dirac comb in continuous time. Let us therefore resort to discrete time for the visualization:

T = 2                      # time distance between pulses
Fs = 1000                  # sampling frequency, used for discretizing the system
t = np.arange(-6, 6, 1/Fs) # time range to consider
comb = np.zeros_like(t)
comb[::int(Fs*T)] = T     # Comb becomes T every T*Fs samples
plt.plot(t, comb)

As shown, the Dirac comb is a periodic repetition of the Dirac impulse, where the distinct impulses are $T$ apart.

In this notebook we will look at different representations of the comb function and its Fourier transform. The relations in time- and frequency domain are nicely visualized by this diagram:

 

The diagram shows, that the comb function can either be represented as a sum of Dirac impulses by $$C_T(t)=T\sum_{n=-\infty}^{\infty}\delta(t-nT)$$ or equivalently as a sum of complex exponentials that have frequencies $nt/T$: $$C_T(t)=\sum_{n=-\infty}^{\infty}\exp(j2\pi nt/T).$$

This representation might not be intuitive. Therefore, let us try to reproduce this equation numerically. First, let us see that we can reformulate this with the identity $$ \cos(2\pi nt/T)=\frac{1}{2}\left(\exp(j2\pi nt/T)+\exp(-j2\pi nt/T)\right). $$ We summarize the exponential terms for positive and negative frequencies into a single cosine, and get $$ C_T(t)=1+\sum_{n=1}^\infty2\cos(2\pi nt/T), $$ where the term $1$ corresponds to $1=\exp(j2\pi\cdot0t/T)=\exp(0)$.

Let us create a function that shows the sum of the first $N$ terms of the series and see how the resulting function looks like:

T = 2  # time-distance between diracs
Fs = 10000 # sampling frequency
def combApprox(N):
    t = np.arange(-2.5, 2.5, 1/Fs)
    sigSum = np.ones_like(t)
    for n in range(1,N+1):
        part = 2*np.cos(2*np.pi*n*t/T)
        sigSum = sigSum + part
        if n < 50:
            plt.plot(t, part, 'b-')
    plt.plot(t, sigSum, 'r-', lw=2, zorder=-1)
    

plt.figure(figsize=(7,6))
plt.subplot(221); combApprox(0)
plt.subplot(222); combApprox(1)
plt.subplot(223); combApprox(2)
plt.subplot(224); combApprox(3)

plt.figure(figsize=(8,3)); combApprox(8)

As visible, the cosine-functions add up constructively at $t=nT$ to a high value. For $t\neq nT$, the different cosine waves have different signs and magnitudes and average out to become a small value close to zero. The more cosines are considered (i.e. higher $N$), the tighter and higher become the peaks of the sum.

 

Looking at the animation it becomes apparent that the peaks become higher and narrower with increasing $N$. Though, there are significant amounts of sidelobes occuring next to the main peaks. These sidelobes are partially there because of Gibbs phenomenom. Here, the so-called ringing and overshooting/undershooting is especially strong due to the high discontinuity of the comb function. A thorough mathematical analysis is out of scope here, but the interested reader can e.g. refer to "Ohm/Lüke: Signalübertragung" Sec. 2.12 for a treatment of the convergence of this series.

To overcome the mathematical convergence problems, let us work completely in the discrete domain, where the numerical treatment is much simpler. In the discrete domain with signals of length $L$, the comb function is given by

$$ C_K[n]=\sum_{k=0}^{L/K-1}\delta[n-kK] $$

where we require $L$ to be dividable by $K$. Literally, $C_K[n]$ represents a function that has a peak every $K$ samples:

L = 256
K = 64
n = np.arange(L)
C_K = np.zeros(L)
C_K[::K] = 1
plt.stem(n, C_K);
(0, 256)

Above, we show a Dirac comb, where the combs are of distance $K=64$ and the sequence has the length $L=256$. Let us now verify the expression for the comb as a sum of complex exponentials: $$C_K[n] = \frac{1}{K}\sum_{k=0}^{K-1}\exp(j2\pi nk/K)$$

def combApprox_discrete(N, K, L):
    n = np.arange(L)
    sigSum = 0
    for k in range(N):
        part = np.exp(2j*np.pi*n*k/K)
        plt.plot(n, part.real, 'b-')
        sigSum = sigSum + part
    plt.plot(n, sigSum.real, 'r-', lw=2)
    
plt.figure(figsize=(8,6))
plt.subplot(221); combApprox_discrete(1, K, L)
plt.subplot(222); combApprox_discrete(3, K, L)
plt.subplot(223); combApprox_discrete(8, K, L)
plt.subplot(224); combApprox_discrete(K, K, L)

Apparently, the expression with a sum of complex exponentials also holds for the discrete case. In particular, we see that the expression is exact when summing up exactly $K$ exponentials. This can be directly shown from the geometric series summation formula:

$$ \sum_{k=0}^{n-1}r^k=\frac{1-r^n}{1-r} $$

For $n\neq iK$, we identify $r=\exp(j2\pi n/K)$ to find

$$ KC_K[n]=\sum_{k=0}^{K-1}\exp(j2\pi n/K)^k=\frac{1-\exp(j2\pi n/K)^K}{1-\exp(j2\pi n/K)}=\frac{1-\exp(j2\pi n)}{1-\exp(j2\pi n/K)}=\frac{1-1}{1-\exp(j2\pi n/K)}=0 $$

For $n=iK$, we have

$$ KC_K[n]=\sum_{k=0}^{K-1}\exp(j2\pi iK/K)=\sum_{k=0}^{K-1}1=K, $$

showing the peaks of the comb function at evenly spaced distances $K$.

The Fourier Transform of the Comb function

Especially, when analyzing the effect of aliasing when sampling a signal, the Fourier Transform of the comb function is essential to know. Formally, it is given by

$$\begin{align} \mathcal{F}\{C_T(t)\}&=TC_{1/T}(f) \\ \mathcal{F}\left\{T\sum_{n=-\infty}^{\infty}\delta(t-nT)\right\}&=T\frac{1}{T}\sum_{n=-\infty}^{\infty}\delta\left(f-\frac{n}{T}\right). \end{align}$$

This means, that the Fourier Transform of a comb function remains to be a comb function, and the wider the peaks are apart in time-domain, the closer they become in frequency domain: If the peaks are e.g. $2s$ apart in time domain, they will be $1/(2s)=0.5Hz$ apart in frequency domain. Or, alternatively, if the peaks in time domain occur with frequency $f_0$, the peaks in the frequency domain are $f_0$ apart.

Let us visualize this with calculations in the discrete domain:

def comb(T):
    result = np.zeros(len(t))
    result[::int(Fs*T)] = 1
    return result

def ft(x):
    """Calculate the Fourier transform of a given signal x"""
    return np.fft.fftshift(np.fft.fft(x)) * Fs / len(x)
Fs = 1000
t = np.arange(0, 2, 1/Fs)
f = np.linspace(-Fs/2, Fs/2, len(t), endpoint=False)

T1 = 0.1
C_T1 = comb(T1)
T2 = 0.05
C_T2 = comb(T2)

plt.subplot(221); plt.plot(t, C_T1)
plt.subplot(222); plt.plot(f, abs(ft(C_T1)*T1))

plt.subplot(223); plt.plot(t, C_T2)
plt.subplot(224); plt.plot(f, abs(ft(C_T2)*T2))

Conclusion

Let us summarize the findings:

  • The comb function $\displaystyle C_T(t)=T\sum_{n=-\infty}^{\infty}\delta(t-nT)$ consists of periodic peaks with distance $T$.
  • Or, equivalently: The comb function $C_T(t)$ consists of periodic peaks that occur with frequency $F=1/T$ (i.e. there are $F$ peaks in one second).
  • The Fourier Transform of the comb function is a comb function. When peaks occur with distance $T$ in time domain, they occur with distance $1/T$ in frequency domain.
  • Or, equivalently: The Fourier Transform of a comb with peak frequency $F$ is a comb function with peak distance $F$.

Do you have questions or comments? Let's dicuss below!

Share this article


Related Affiliate Products

Related posts


DSPIllustrations.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to amazon.com, amazon.de, amazon.co.uk, amazon.it.