Summing complex exponentials to understand the Discrete Fourier Transform

36 Views Asked by At

I am trying to recreate, using Matplotlib, the "Main idea of the Discrete Fourier Transform" shown in this video https://www.youtube.com/watch?v=d5Utdr8DagY&t=571s (start from 08:10).

I can easily create a series of cosines from their complex exponentials, for example:

import numpy as np
import matplotlib.pyplot as plt

M = 400
A = 1
k = np.linspace(0, M, M + 1)

fig, ax = plt.subplots(subplot_kw = {'projection': '3d'})

for n in range(1, 4):
    sig = A + (1j * (2 * np.pi) * n / M * k)
    sigcos = np.cos(np.imag(sig))
    sigsin = np.sin(np.imag(sig))
    ax.plot(k, sigsin, sigcos)

This gives me the expected results as follows:

enter image description hereenter image description here

However, if I modify the code to sum the real and imaginary parts of the complex exponentials, the result is not as shown in the video. Rather, it seems the frequencies are summed instead.

import numpy as np
import matplotlib.pyplot as plt

M = 400
A = 1
k = np.linspace(0, M, M + 1)

sig = A + (1j * (2 * np.pi) * 1 / M * k)

fig, ax = plt.subplots(subplot_kw = {'projection': '3d'})
for n in range(2, 7):
    print(n)
    newsig = A + (1j * (2 * np.pi) * n / M * k)
    # sig = sig + newsig
    sig = (np.real(sig) + np.real(newsig)) + (1j * (np.imag(sig) + np.imag(newsig)))

sigcos = np.cos(np.imag(sig))
sigsin = np.sin(np.imag(sig))
ax.plot(k, sigsin, sigcos)

enter image description here

I tried simply adding the two complex numbers and explicitly expanding to add real and imaginary parts. However, the results are the same.

How should I add each signal of increasing frequency to get the results shown in the video?