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.

  • 1
    $\begingroup$ The last sentence in your question is the answer. $\endgroup$
    – Matt L.
    Jan 10 '21 at 9:00
  • $\begingroup$ MATLAB doesn't do $+f_{Nyq}$. $\endgroup$ Jan 10 '21 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:

enter image description here

You can tell a library's preference by fftshift docs:

enter image description here

  • $\begingroup$ Thanks, but I am still wondering about the basis that the Nyquist value is doubled? $\endgroup$
    – M. Farooq
    Jan 10 '21 at 16:26
  • $\begingroup$ @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. $\endgroup$ Jan 10 '21 at 16:32
  • $\begingroup$ Do you know of a book which specifically mentions this doubling issue? $\endgroup$
    – M. Farooq
    Jan 10 '21 at 16:47
  • $\begingroup$ @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. $\endgroup$ Jan 10 '21 at 17:17
  • $\begingroup$ Okay that is better because I have not seen this discussed, at least in the standard book like Bracewell. $\endgroup$
    – M. Farooq
    Jan 10 '21 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.

  • $\begingroup$ 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. $\endgroup$
    – M. Farooq
    Jan 10 '21 at 5:15
  • $\begingroup$ 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. $\endgroup$ Jan 10 '21 at 6:02
  • $\begingroup$ 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? $\endgroup$
    – M. Farooq
    Jan 10 '21 at 6:13
  • 2
    $\begingroup$ Only one Nyquist bin for even $N$; unequal number of positive and negative bins. $\endgroup$ Jan 10 '21 at 9:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.