# Correct magnitude spectra of a cosine DFT?

I've just started my course on DSP and haven't laid my hands on MATLAB yet. I was wondering if the plot of the magnitude spectra was correct for the below shown $x(n)$: you're missing the frequency component at $k=N-k_0$.

• Could you explain how you arrived at that without the mathematics – asr Mar 4 '18 at 7:25
• A cosine always has symmetric spectrum. – Marcus Müller Mar 4 '18 at 9:45
• Hopefully someone will correct if I'm wrong but to explain why they are two components, here's my understanding. (I'm new at this also ). When you use 0 to N-1 in a DFT, you are impliciitly making the frequency spacing from 0 to $2 \pi$. So the $k = k_{0}$ component represents one frequency and the other represents the same frequency but at $2\pi - k_{0}$. So, they are really the same frequency which is why the magnitude of each is $\frac{1}{2}$. If N instead went from -N./2+1 to N/2, a similar thing happens but, in that case you'd be going from $-\pi$ to $\pi$. – mark leeds Mar 5 '18 at 6:38

HINT:

As mentioned in the comments you're missing one component. See it this way, Using Euler's formula you have: $$\cos\left(\frac{2\pi k_0 n}{N}\right) = \frac{\exp\left(j\frac{2\pi k_0 n}{N}\right) + \exp\left(-j\frac{2\pi k_0 n}{N}\right)}{2}\tag{1}$$ And using the DFT definition, you have:

$$X[k] = \sum_{n=0}^{N-1}x[n]\exp\left(-j\frac{2\pi k n}{N}\right)\tag{2}$$

Plugging equation $(1)$ in $(2)$ you get:

$$X[k] = \underbrace{\frac 12\sum_{n=0}^{N-1} \exp\left(-j\frac{2\pi (k - k_0) n}{N}\right)}_{\rm yours} + \frac 12\sum_{n=0}^{N-1} \exp\left(-j\frac{2\pi (k + k_0) n}{N}\right)\tag{3}$$

Your plot got only the one with the under-brace.

EDIT:

Using geometric series, equation $(3)$ can be written in the form: \begin{align} X[k]=\frac 12\sum_{n=0}^{N-1}a^n + \frac 12\sum_{n=0}^{N-1}b^n \end{align} Where

$$\text{with}\quad a = \exp\left(j\frac{2\pi (k_0 - k)}{N}\right)\quad\text{and}\quad b = \exp\left(j2\pi\frac{-(k_0 + k)}{N}\right)$$ In the first summation you get $0$ everywhere except for $k = k_0 + pN \ \forall \ p\in \mathbb Z$ where you get $N$ (summation of $1$s). In the same manner in the second summation you get $0$ everywhere except for $k = pN - k_0\ \forall \ p\in \mathbb Z$.

• Yes agreed . I'd like an explanation without the math.Here is how I see it : In the dft definition the summation yields a non zero value only for k=ko (the basis function e^(-j2 πkn/N) will have frequency equal to that of function being analysed for k=ko) . I don't understand how the summation will yield non zero value at k=N-ko – asr Mar 4 '18 at 16:23
• @asr please see my edit. – Gilles Mar 4 '18 at 20:58

The broader principle is that the DFT of any real signal is conjugate symmetric between the bottom half and the top half. This can be understood in more of a conceptual manner by observing that a DFT bin value is the calculation of a weighted set of N Roots of Unity, where the signal value is the weighting factor and the bin index is the skip size traversing the roots. The signal is wrapped around the circle $k$ number of times for the $kth$ bin. Skipping ahead $N-k$ roots is the same as skipping backward by $k$ roots, which is then simply a wrapping in the opposite direction. Therefore, the center of mass will also be in the opposite direction which happens to be the complex conjugate.

This means for every real valued signal, the bin value at index $k$ is the complex conjugate of the bin value at $N-k$. This is how robert bristow-johnson could tell you that you were missing a value without doing any math.

I have written a blog article "DFT Graphical Interpretation: Centroids of Weighted Roots of Unity" to explain what I mean by the "wrapping" above. I don't think you will find it anywhere else. The reason the magnitude value is 1/2 can be clearly seen in Figures 2 through 6.

I hope this helps.

Ced