Pangram verdict · v3.3
We believe this text is mainly human-written, with some AI content.
AI likelihood · overall
HumanArticle text · 856 words · 3 segments analyzed
In the previous post on this topic, we’ve seen how the Discrete-Time Fourier Series (DTFS) and transform (DTFT) are used to analyze infinite-duration periodic and non-periodic discrete signals. Now, it’s time to turn to realistic digital signal processing where signals are not only discrete, but also finite in duration. Analyzing signal samples Suppose we have samples of a signal - it’s a list of numbers: We want to analyze the frequencies present in this signal; in other words, to find the coefficients in a series of complex exponentials that reconstructs the signal. One option is to assume that is an infinite domain signal with zero values outside our samples, and then compute its DTFT: However, this is a continuous function of frequency , so it’s difficult compute on an actual computer; we cannot evaluate and store it for all , so we have to choose which to compute it for. We'll soon see how this choice is made. But there's an alternative way to look at the problem. We only have samples of the signal , so we can assume they represent a single period of a periodic signal. And in that case, we can use DTFS; recall that the coefficients of the series are: As we’ve seen in the post on the DTFS, this series can be used to reconstruct a discrete, periodic signal precisely. Since our signal is finite and we assume it’s just one period of a periodic signal, it means we can also reconstruct precisely using a DTFS. This is the main insight behind the Discrete Fourier Transform (DFT). First, by convention [1] we define: And then: This is called the Discrete Fourier Transform of . The term transform may be a bit puzzling here - after all, we’re just using the series coefficients - so isn’t it more proper to just say series? Perhaps, though in mathematics a transform has a pretty general meaning of "a mapping that takes a mathematical object and produces another object"; in that sense, "transform" is proper here because we take an object - and produce another object - . Moreover, DFT and DTFT are intimately related. Recall how we said earlier that the DTFT is tricky to compute because is a continuous variable? Well, the DFT gives us a way to sample that variable into the discrete domain: So the DFT can be seen as exactly equally spaced samples of the DTFT. Computing the DFT Since the goal of this post is specifically to demonstrate computable methods of applying Fourier analysis to discrete digital signals, here’s the Python code to calculate the DFT of a signal: def dft(x): """Return X[k] = sum_n x[n] exp(-2 pi i k n / N).""" N = len(x) n = np.arange(N) X = np.empty(N, dtype=complex) for k in range(N): weights = np.exp(-2j * np.pi * k * n / N) X[k] = np.sum(x * weights) return X It shouldn’t be hard to see the correspondence between this code and the mathematical formula for . Python’s Numpy code is vectorized by default, so the weights array is computed in whole for every k (because n is an array of indices ). DFT and the complex roots of unity In my earlier post on the complex roots of unity, we’ve seen how powers of the roots of unity form an orthogonal basis for . Now let’s show the beautiful theoretical connection between this fact and the DFT. Recall that the -th roots of unity can be written as: Since all are just powers of , we can write them as: The conjugates of the roots of unity are roots of unity themselves: With being the same as , so when we enumerate all the roots of unity, we’re also enumerating their conjugates, just in a reversed order. With that in mind, let’s denote [2] , and examine the sequence: The vectors formed by (element-wise) raising to integer powers from to can be collected into a matrix: In the roots of unity post, we’ve proven that the rows of this matrix form an orthogonal basis over . In other words, any vector in can be represented as a linear combination of the rows of . I hope you can see where this is going! Let’s consider the signal as a column vector in . The DFT of can be computed by multiplying by the matrix : Take a minute to convince yourself this is true, by working through the multiplication for a specific row , e.g. is computed via row-column multiplication the third row (counting from 0) of and . Our is called the Fourier Matrix or the DFT Matrix. Previously we’ve seen Python code that directly computes the DFT; here’s a version that does this via the matrix multiplication approach: def dft_matrix(N): """Construct F[k, n] = W_N**(k*n), where W_N = exp(-2 pi i / N)."""
# W_N is a primitive N-th root of unity: W_N**N = 1.
# Its powers give all N roots of z**N - 1 = 0. root = np.exp(-2j * np.pi / N) indices = np.arange(N) # Rows correspond to frequency bins k; columns to sample indices n.