# How to Calculate Frequency "X values" from a FFT/DFT Transformation

First of all I am totally new to the DSP field and I have no background in it whatsoever, but my work in biology has led me to data that would greatly benefit from DSP. Any answers devoid of specific DSP math notation, verbage or symbols would be greatly appreciated.

My question is: how do I calculate the frequency values or "X axis" values that go with the DFT peaks' "Y values" that were output from a DSP program? I have used a program that output the following DFT and I can also access/print out the actual "Y values"/peak heights themselves, but not the "X values"/frequency values:

I have heard it mentioned that the sampling frequency/sampling rate and the number of data points that make up the above graph/plot are the only necessary ingredients needed to calculate the "X values" that go with the "Y values" (peak heights) but I don't know what this math equation/formula is. I have also heard mention of something called "frequency bins" but I am not sure if that has any relevance to my question on this post (since the word "bin" reminds me of the bins mentioned in statistics for histograms, but those bins are ranges of values, not the discrete "X values" I am asking about here). Any help/direction or hints would be greatly appreciated.

LM

What you have heard about the sampling frequency/rate and the number of samples/data points is correct. When you take $$n$$ samples in the time-domain representation of the signal and "Fourier Transform" them (I use the term loosely without getting into details about DFT, DTFT, FFT etc.) you end up with equal amount of samples ($$n$$ that is). Those samples now represent the "amplitude" (I also use this term quite loosely) of some frequencies.

Your data after the transformation to the frequency-domain will now contain all the frequency information from $$0 Hz$$ (DC that is) up to your sampling frequency/rate, which I will denote with $$f_{s}$$. The spacing of the frequencies on the $$x$$-axis is linear so the whole spectrum is divided into equal intervals. This interval, denoted here as $$\Delta f$$, is given by

$$\Delta f = \frac{f_{s}}{n}, ~~~~~~~~~~~~ n = 0, 1, 2, \ldots, N - 1 \tag{1}$$

where $$N$$ represents the number of samples used.

Bins is indeed the term (or at least one of the terms) used in this case. So, each interval is denoted as one bin. It has indeed direct connection to the term as used in statistics when creating histograms because in each bin is included the energy in the band

$$\left[n \Delta f - \frac{\Delta f}{2}, n \Delta f + \frac{\Delta f}{2}\right], ~~~~~~~~~~~~ n = 1, 1, 2, \ldots, N - 1 \tag{2}$$

where for $$n = 0$$ the bin corresponds to DC and is the mean of all the values.

One comment to make here is that, in case of a real-valued signal/function, the magnitude/spectrum will be an even function (the second half of the data is mirrored in respect to the y-axis) and the phase information an odd function (the second half of the data is mirrored in respect to the y-axis and negated in respect to the x-axis). Thus, for analysis, one could use only the first half of the data (or the second half if the first half represents negative frequencies, but this is implementation dependent).

• Thanks for your kind response. If I may then elaborate on my system: I have a total of 200 data points in the time domain but when I use the program's FFT feature, it returns a total of 129 points which constitute the transform's data points. This program does not require me to provide a sampling frequency in order to obtain the transform. Does the above sound normal as what software packages typically ask for in order to output transform data points? Please correct me if I'm wrong but it sounds as if I should also have 200 transform data points in the frequency domain. Thanks. Jul 4, 2022 at 22:50
• @LobsterMan123, I have skipped a lot of details in the answer and this may have hidden some things from you. The FFT works best when the number of the input data (the time-domain signal that is) is a power of 2. So, most probably the software you use, zero-pads (adds zeros) until the length of your signal vector is a power 2 and greater than the original signal (256 most probably in your case). Now, after zero-padding the length of the input to the FFT is 256 samples (some of them zeros as I said, which doesn't alter the included information somehow). As I mentioned in the answer (cont.) Jul 5, 2022 at 8:42
• (contd.) when the input to the transform is real-valued, half of the spectrum is the complex conjugate of the other half. This makes half the information redundant. So, the software "discards" (does not show) half the spectrum which is identical to the other half. This is why you get 129 bins (the last bin corresponds to the Nyquist frequency, which is equal to half your sampling frequency). Now, if your software does not know the sampling frequency then the values get on the x-axis correspond to bins without any information of frequency. You have to keep in mind that the transform (cont.) Jul 5, 2022 at 8:44
• (contd.) is an algorithm which can very well be performed without any knowledge of the frequency, it's just a mathematical formula implemented numerically on a computer. Nevertheless, this does not change the output of the transform, it just does not provide any information on the frequencies. For example, if your sampling frequency would be 10 Hz, then the whole [0 Hz, 5 Hz] frequency band would be divided into 129 bins. If it were 10 kHz then the band [0 Hz, 5 kHz] would be divided (linearly of course) to 129 bins. Hope that makes sense. Let us know if it doesn't. Jul 5, 2022 at 8:47
• Thank you for explaining all of this. My follow-up question then is the following: is my sampling frequency the frequency with which I collected my original time domain data? If so, I actually collected my data once per nanosecond for a total of 200 nanoseconds. How do you recommend I "Hertzify" this data collection frequency (assuming this is indeed what is meant by a sampling frequency). Thanks again for all your help. Jul 14, 2022 at 1:48