# One sided frequency spectrum (Matlab vs. Origin)

There are a lot of queries on fft frequency all over the web. I guess the following point not discussed anywhere explicitly. Hope someone can provide an insight here.

If we have and even number of data points, N=10, the fft complex output arranges the data as

fft = [c0, c1, c2, c3, c4, c-5, c-4, c-3, c-2, c-1],

where the complex numbers corresponding to positive and negative frequencies. I read somewhere that MATLAB calculates the negative coefficient first, hence we have c-5 but not c5. The author did not explain the reason.

Point no. 1, that the values are not symmetric, there is an extra c-5.

When we wish to make two-sided frequency spectrum, the frequency axis ranges from [-(N/2): (N/2)-1]*Fs/ N. Fs is the sampling rate, N is the number of even data points.

If we wish to make a one-sided positive frequency spectrum, should we choose

A) [0:(N/2)]*Fs/N and ignore the fact the we are using the values corresponding to the negative frequency axis, given that the data is a real number and it is just a mirror image.

B) [0: (N/2)-1]*Fs/N represents the true positive frequency axis?

If Fs= 250 Hz, the true positive frequency axis will end at 124.9980 Hz

If we happen to choose the negative frequency axis values and ignore the frequency sign, the frequency axis ends at 125 Hz exactly.

The same data when plotted in OriginPro ends the frequency axis at 125 Hz when plotted single sidedly.

Which approach (A) or (B) is rigorously correct, and why would OriginPro plot the frequency upto 125 Hz?

• You might find this answer really helpful as well: dsp.stackexchange.com/questions/59305/… Commented Jul 7, 2019 at 17:35
• I would say you are better off learning what the DFT actually means and how it works, then deal with MATLAB idiosyncrasies. Your referenced paper attempts to do both at once. Read the beginning of 3. The links I have already given should give you a good start. Of course, I also recommend my blog articles where you will find cutting edge formulas derived from scratch: dsprelated.com/blogs-1/nf/Cedron_Dawg.php They are listed in reverse chronological order, so go to page two at the bottom to start. Good luck, I'm gone for a while. Commented Jul 7, 2019 at 18:02
• MATLAB actually calculates [c0, c1, c2, c3, c4, c5, c6, c7, c8, c9]. The negative frequencies are the result of an interpretation based on the modulo N nature of the DFT. You can use fftshift to slide the values around in the vector. so the c0 is at the "center". Commented Jul 7, 2019 at 18:10
• @CedronDawg, Your blogs are useful. I was reading your first one. Just a short historical note (since I like sci history). You wrote "The variable i stands for the square root of negative one. This is the American convention. The European convention uses the letter j". I have written an answer on the history of i and j in another forum. It is the other way round. hsm.stackexchange.com/questions/9654/… .
– ACR
Commented Jul 8, 2019 at 4:38
• Thank you. You are the first to call me out on that. I correct it in my last blog (which you should probably read second). "i" is generally used by mathematicians, and "j" by engineers, particularly electrical engineer, since "I" (and sometimes "i") is used for current (amperage). Your paper misses the split issue I raised. If you are going to zero pad your DFT results and then apply the inverse DFT, you should split the they Nyquist value in half. There is no need to rotate the values in the vector either, you can just slide the upper half up and insert the zeroes in the center. Commented Jul 8, 2019 at 11:41

The indexing is a matter of convention. "Natural" is zero centered, "Computer implementation" is zero based.

We are having a big discussion right now over several questions on why your $$c_{-5}$$ should actually be considered as $$(c_{-5} +$$c_{5})/2\$. You'll find part of the discussion here Convergence of periodic sinc interpolation and the links to the rest are embedded within.

The "fluffy cloud" drawings show what happens when you consider the upper half (from a zero based perspective) as positive frequencies. How to get Fourier coefficients to draw any shape using DFT?

If I have a circle, and I check your location every minute and it seems you have moved a quarter circle counter-clockwise each time, how do I know you haven't actually moved three quarters of the circle clockwise?

Answer: You don't. The convention decides which interpretation to use.

• Thanks, is there a good resource, which talks about how MATLAB indexes the FFT coefficients? I cannot find any documentation from MATLAB itself that fft output is arranged as follows: [c0, c1, c2, c3, c4, c-5, c-4, c-3, c-2, c-1]? I saw this explanation in an online DFT primer. The author himself just that this is the way MATLAB does it i.e., c-5 is calculated first and he has not thought about the "why" of it. Where does MATLAB document it? Maybe it is too obvious, but I am coming from the chemistry side.
– ACR
Commented Jul 7, 2019 at 17:12
• Did you see this: mathworks.com/help/signal/ug/discrete-fourier-transform.html I simply searched on "matlab dft definition" See those "+1"s in the definition? Ugly, aren't they? MATLAB indexes all its arrays starting a 1. Which is incredible (incredibly shortsighted) as it is supposedly designed by mathematicians. You can do a lot of the same kind of stuff in Python with available libraries. Better, IMO. Yours truly likes Gambas, but the support for DSP there is weak. Commented Jul 7, 2019 at 17:21
• The most important "piece" to understanding a DFT is the bin index corresponds to a frequency in units of cycles per frame. The connection to Hz is a conversion factor away based on your sampling rate. Could be years in a different application, or inches even. You also need to realize that it repeats every N, so it is circular in nature, e.g. X[N-k] = X[-k]. It is easiest to think of the bins arranged in a circle, then the Nyquist bin is at the halfway point around the circle. MATLAB's off by one index obscures all that. Commented Jul 7, 2019 at 17:28
• @M.Farooq, I forgot to put this little (at) tag on the above two comments so you would get notified. Commented Jul 7, 2019 at 17:36
• I guess we can digest the bin number issue if we accept matrix indices. They don't start from zero either. Did Matlab justify like that? I like your analogy, but specifically, I wanted to know why the arrangement of the fft output is like [c0, c1, c2, c3, c4, c-5, c-4, c-3, c-2, c-1]. Is this specifically documented somewhere officially by Matlab? P.S. I always to get a notification whether @ tag is used or not if I am the original poster. Not sure how stackexchange works.
– ACR
Commented Jul 7, 2019 at 17:41