1

I am trying to get to the circular convolution formula from the product of the DFT of two input signals. I came across this webpage, which contains the following.

enter image description here

Could someone help me to solve that equation?

I have something like this

$$ x_3(n) = \frac{1}{N} \sum^{N-1}_{k=0} \exp{\left [ \frac{j 2 \pi k n}{N} \right ]} \left [ \sum^{N-1}_{m=0} x_1(m) \exp{\left [ \frac{-j 2 \pi k m}{N} \right ]} \right ] \left [ \sum^{N-1}_{m=0} x_2(m) \exp{\left [ \frac{-j 2 \pi k m}{N} \right ]} \right ] $$

I am not sure what is next. The following doesn't seem to be right.

$$ \begin{aligned} x_3(n) &= \frac{1}{N} \sum^{N-1}_{k=0} \left [ \sum^{N-1}_{m=0} x_1(m) \exp{\left [ \frac{-j 2 \pi k m}{N} \right ] \exp{\left [ \frac{j 2 \pi k n}{N} \right ]}} \right ] \left [ \sum^{N-1}_{m=0} x_2(m) \exp{\left [ \frac{-j 2 \pi k m}{N} \right ]} \right ]\\ \\ &= \frac{1}{N} \sum^{N-1}_{k=0} \left [ \sum^{N-1}_{m=0} x_1(m) \exp{\left [ \frac{-j 2 \pi k (m-n)}{N} \right ]} \right ] \left [ \sum^{N-1}_{m=0} x_2(m) \exp{\left [ \frac{-j 2 \pi k m}{N} \right ]} \right ]\\ \end{aligned} $$

Eduardo Reis
  • 353
  • 3
  • 9

1 Answers1

3

Let $x$ and $y$ be signals of $N$ samples each, numbered as $x(0),\ldots,x(N-1)$. Then their DFTs are $X$ and $Y$, which also have $N$ entries each: \begin{eqnarray} X(k) &=& \sum_{n=0}^{N-1}x(n)e^{-2\pi i kn/N},\\ Y(k) &=& \sum_{m=0}^{N-1}y(m)e^{-2\pi i k m/N}, \end{eqnarray} where the indices run from $0$ to $N-1$.

The $k^{\textrm{th}}$ entry of the entry-by-entry product of $X$ and $Y$ is \begin{equation} \begin{split} X(k)Y(k) ~=& \left(\sum_{n=0}^{N-1}x(n)e^{-2\pi i kn/N}\right)\left(\sum_{m=0}^{N-1}y(m)e^{-2\pi i k m/N}\right)\\ ~=& \sum_{n=0}^{N-1}\sum_{m=0}^{N-1}x(n)y(m)e^{-2\pi i k(n+m)/N} \end{split} \end{equation}

Now we consider the $\ell^{\textrm{th}}$ entry of the IDFT of this entry-by-entry product: \begin{equation} \begin{split} \mathsf{IDFT}(XY)(\ell) ~=& \frac{1}{N}\sum_{k=0}^{N-1}X(k)Y(k)e^{2\pi i\ell k/N }\\ ~=& \frac{1}{N}\sum_{k=0}^{N-1}\left[\sum_{n=0}^{N-1}\sum_{m=0}^{N-1}x(n)y(m)e^{-2\pi i k(n+m)/N}\right]e^{2\pi i\ell k/N }\\ ~=& \frac{1}{N}\sum_{n=0}^{N-1}\sum_{m=0}^{N-1}x(n)y(m)\sum_{k=0}^{N-1}e^{-2\pi i k(n+m-\ell)/N} \end{split} \end{equation} The sum over $k$ is equal to 0 unless \begin{equation} n+m-\ell=0~\textrm{mod}~N~~~(m=\ell-n~\textrm{mod}~N), \end{equation} in which case it is equal to $N$: \begin{equation} \sum_{k=0}^{N-1}e^{-2\pi i k(n+m-\ell)/N} = N\delta_{m,\ell-n~\textrm{mod}~N}, \end{equation} where $\delta_{a,b}$ is the Kronecker delta. One intuitive way to see this is to see that

$\bullet$ if the exponent is not 0, we are adding all $N$ of the $N^{\textrm{th}}$ roots of unity (view them in the complex plane), which will cancel one another out when added; As noted by the OP, my struck-through claim is true for all $n$, $m$, and $\ell$ only if $N$ is prime. The correct proof is to note that if $e^{-2\pi i(n+m-\ell)/N}\neq 1$, then \begin{equation} \begin{split} \sum_{k=0}^{N-1}e^{-2\pi i k(n+m-\ell)/N} &=~ \sum_{k=0}^{N-1}\left(e^{-2\pi i (n+m-\ell)/N}\right)^k\\ &=~\frac{ 1- \left(e^{-2\pi i (n+m-\ell)/N}\right)^N}{1 - e^{-2\pi i (n+m-\ell)/N}}\\ &=~\frac{ 1- e^{N\times(-2\pi i (n+m-\ell)/N)}}{1 - e^{-2\pi i (n+m-\ell)/N}}\\ &=~\frac{ 1- e^{-2\pi i (n+m-\ell)}}{1 - e^{-2\pi i (n+m-\ell)/N}}\\ &=~\frac{ 1- 1}{1 - e^{-2\pi i (n+m-\ell)/N}} ~~=~~ 0. \end{split} \end{equation}

$\bullet$ if the exponent is 0, then we are adding 1 $N$ times.

(Another not as intuitive away can be found in this video.)


So far, we have \begin{equation} \begin{split} \mathsf{IDFT}(XY)(\ell) ~=& \frac{1}{N}\sum_{n=0}^{N-1}\sum_{m=0}^{N-1}x(n)y(m)N\delta_{m,\ell-n~\textrm{mod}~N}\\ ~=& \sum_{n=0}^{N-1}\sum_{m=0}^{N-1}x(n)y(m)\delta_{m,\ell-n~\textrm{mod}~N} \end{split} \end{equation} When we perform the sum over $m$, the only nonzero term is the one for which $m=\ell-n~\textrm{mod}~N$, so \begin{equation} \begin{split} \mathsf{IDFT}(XY)(\ell) ~=& \sum_{n=0}^{N-1}x(n)y(\ell -n~\textrm{mod}~N). \end{split} \end{equation} The expression on the right-hand side is the $\ell^{\textrm{th}}$ entry of the circular convolution of $x$ and $y$. \begin{equation} \mathsf{IDFT}(XY)(\ell) = (x\circledast y)(\ell), \end{equation} so $\mathsf{IDFT}(XY) = x\circledast y$.

Joe Mack
  • 616
  • 3
  • 7
  • This answer also reminded me of how the product of two sums can be nested. Wow. It is a very thorough answer, thank you a lot. – Eduardo Reis May 12 '20 at 20:36
  • Can you expand on this? if the exponent is not 0, we are adding all of the th roots of unity (view them in the complex plane), which will cancel one another out when added; I am still trying to visualize it. – Eduardo Reis May 13 '20 at 15:10
  • The complex numbers 1, exp(-2πi/N), exp(-2πi 2/N),..., exp(-2πi (N-1)/N) are the Nth roots of unity, and, when viewed as vectors in the complex plane, they are N equally-spaced (in terms of angles between them) unit vectors anchored at the origin. By the symmetry of their directions and sizes, they cancel out one another when they are all added together. For N = 2, for example, the roots of unity are 1 and -1, which clearly cancel each other out. – Joe Mack May 13 '20 at 20:45
  • I understand what you said by $$\sum_{k=0}^{N-2} e^{\frac{-j2\pi k n}{N}} = 0$$. But then, what you said above on the answer is a bit different, since you are multiplying the exponential by an integer, which could be multiple anything. For multiples of N, it is clear for me that the result will be one, but what is not clear is how the result would be zero otherwise. I could visualize yet how multiples of $2\pi / N$ could still be rotated and yield zero. – Eduardo Reis May 13 '20 at 20:56
  • When implementing, in order to get the DFT matching the circular convolution I have to apply ifftshift in order to have the convolution using FFT matching the one on the spatial domain. I am wondering what would be the reason of that given the math doesn't dependes on a ifftshift operation. – Eduardo Reis May 14 '20 at 13:43
  • The complex exponentials are not multiplied by an integer. The sum from k = 0 to k = N-1 has only two possible values: 0 and N. If n in the exponent is 0, then each term is 1, and we are adding N 1s, and we get N. If n in the exponent is not 0, then we are adding all the N-th roots of unity, which cancel out one another, and we get 0. See the diagram on Wikipedia's entry for root of unity (https://en.wikipedia.org/wiki/Root_of_unity). – Joe Mack May 14 '20 at 15:27
  • I experimented in Octave. x = rand(10,1); y = rand(10,1); pkg load signal; u = cconv(x,y,10); v = ifft(fft(x).*fft(y)); norm(u - v) I got 0 as the result of the final line, indicating that the circular convolution equals the IDFT of the entry-by-entry product of two DFTs.fftshift and ifftshift are really ordering commands related to whether you want your normalized frequencies to go from -π to π or from 0 to 2π, and you can ignore them in this question. – Joe Mack May 14 '20 at 16:10
  • I am using python, here is the code as a gist, and it does not match, unless I shift either the kernel, or the output. – Eduardo Reis May 14 '20 at 16:18
  • There is also this answer here on the forum, which code uses shift. – Eduardo Reis May 14 '20 at 16:26
  • Regarding the beginning of the conversation. I meant the term $m+n-l$ is by definition an integer, allow me to refer to it as $c$.

    From the most inner sum's perspective, $c$ is an integer constant. Now, $\frac{-1j 2 \pi k c}{N}$ will still be a multiple of the 1st root $\frac{-1j 2 \pi}{N}$.

    Since $c$ can be easily greater than $1$, then, instead of $k$ increment over every single root, it might in certain cases skip some roots. So, what was not clear for me is, How to demonstrate that the angles $\frac{-1j 2 \pi k c}{N}$ cancel each other.

    – Eduardo Reis May 14 '20 at 16:37
  • 1
    I finally your concern exactly, and it is valid. A better explanation than mine is to use the fact that if the number w is not 1, then 1 + w + w^2 + ... + w^(N-1) = (1 - w^N)/(1 - w). In your case, w = exp(-2πic/N), where c is as you defined. Then the numerator is 1 - w^N = 1 - exp(N×(-2πic/N)) = 1 - 1 = 0. – Joe Mack May 14 '20 at 17:23
  • Thanks a lot! Regarding the code on Octave. defined two signals on python, did the circular convolution. Then I did the same thing, but on matlab instead. If compared, on output is the circular shift of the other. So, numpy and Matlab/Octave do thing differently. – Eduardo Reis May 14 '20 at 18:34
  • Here is the gist with the comparison above. – Eduardo Reis May 14 '20 at 18:40
  • I am inexperienced in the tools used for DFTs on 2-dimensional arrays, but I suspect that some equivalent of fftshift is automatically applied, so that the normalized frequencies run from -π to π in all frequency dimensions, instead of allowing 0 to 2π in any frequency dimension. That way, the origin of the frequency plane is at or near the center of the array output by the transform. Using a 1-d transform from the same library might have the same issue. – Joe Mack May 14 '20 at 19:22