# In the context of DFT, Where Does the Nyquist Frequency Sample Belong In a Double Sided Frequency Spectrum (Positive / Negative Side)?

If we have an even number of data points $$N$$, after DFT in MATLAB, the output has the order:

$$(\text{DC}, f_1, f_2, \ldots, f_{N/2-1}, f_\text{Nyq}, -f_{N/2-1}, -f_{N/2-2}, \ldots, -f_1)$$

For real signals, the first output corresponding to $$k$$=0, is real and so is the Nyquist frequency. After that numbers are complex conjugates.

If we are interested in a single sided spectrum, the Nyquist frequency is shown on the positive side.

However, when a double-sided frequency spectrum is plotted, many authors put the Nyquist frequency on the negative side.

Some software like OriginPro, follow the opposite. Is there a fundamentally correct way or is it just a convention i.e.,

$$\text { If } N \text { is even, } \quad k\quad\text { takes: }-\frac{N}{2}, \ldots,-1,0,1, \ldots, \frac{N}{2}-1$$

Alternatively, $$\text { If } N \text { is even, } \quad k \text { takes: } -\frac{N}{2}-1, \ldots,-1,0,1, \ldots, \frac{N}{2}$$

where $$k$$ is the DFT index vector, which is used to construct the frequency axis as

$$\text {Frequency axis}=k/ N\Delta t$$

where $$\Delta t$$ is the sampling interval.

Many people say it is just a convention and both are correct. Thanks.

• The last sentence in your question is the answer. Jan 10 at 9:00
• MATLAB doesn't do $+f_{Nyq}$. Jan 10 at 9:32

It's convention, they're equivalent:

$$\exp{\left(j2 \pi \frac{N}{2}n/N \right)} = \exp{\left(j2\pi \frac{-N}{2}n/N\right)} \\ \Rightarrow e^{j\pi n} = e^{-j \pi n} \Rightarrow \cos(\pi n) = \cos(-\pi n)=(-1)^n,\ j\sin(\pi n) = j\sin(-\pi n) = 0$$

MATLAB and Numpy go $$[-N/2, ..., N/2-1]$$, which is unfortunate for analytic representations (+ freqs only). Note also its value is doubled relative to other bins (but not manually; they correlate this way), so in a sense it's both a negative and positive frequency, so energy's preserved: You can tell a library's preference by fftshift docs: • Thanks, but I am still wondering about the basis that the Nyquist value is doubled? Jan 10 at 16:26
• @M.Farooq $\text{sum}([1, -1, ...]^2) = 2N$. Recall, $X$ at $k$ is multiply-summed by $\cos{(2\pi k n / N)}$ for the real part, which at $k=N/2$ is $[1, -1, ...]$. Intuitively, unlike for any other $k$, every point at $k=N/2$ is a peak, so squared-sum is higher. Jan 10 at 16:32
• Do you know of a book which specifically mentions this doubling issue? Jan 10 at 16:47
• @M.Farooq It's more a benefit, as you sort of keep both + and - in one. Energy calculations are to be adjusted as here, idea similar to fft vs rfft. I'm not aware of texts discussing various implications of this; should be its own question depending what you seek. Jan 10 at 17:17
• Okay that is better because I have not seen this discussed, at least in the standard book like Bracewell. Jan 10 at 17:19

Assuming $$x[n]$$ is real, resulting in $$X[k]$$ being "Hermitian symmetric";

$$X[N-k] = (X[k])^*$$

and if $$N$$ is even, then the value in the DFT bin $$X[\tfrac{N}{2}]$$ (which is a real quantity with zero imaginary part) should be split into two equal halves. One half should be placed at $$k=-\tfrac{N}{2}$$ and the other half placed at $$k=+\tfrac{N}{2}$$.

This previous answer deals with this.

• I think we had discussed this before here. How can we have both -N/2 and +N/2 for an even output. I would really appreciate if you know of a reference which does this and explains the fundamental basis of splitting it. Most people take the Nyquist value to the negative side (in Matlab's fftshift). I have browsed plenty of books, but could not find this particular point addressed. Jan 10 at 5:15
• if $x[n]$ is real, it must have both $X[-\frac{N}2]$ and $X[+\frac{N}2]$ because if $x[n]$ is real, then the spectrum must be Hermitian symmetric. Jan 10 at 6:02
• If N=6, the output is like $\left[c_{0}, c_{+1}, c_{+2}, c_{-3}, c_{-2}, c_{-1}\right]$ and after fftshift it is $\left[c_{-3}, c_{-2}, c_{-1}, c_{0}, c_{+1}, c_{+2}\right]$, where is X[+N/2] here? Jan 10 at 6:13
• Only one Nyquist bin for even $N$; unequal number of positive and negative bins. Jan 10 at 9:28