# How can you get the mean wavelength/frequency of a Discrete Fourier Transform (DFT)?

I am very new to the concept of Fourier transforms and DFTs so please explain in as simple terms as possible.

I am messing around with Fourier transforms in processing. I wanted to determine the average wavelength of an input - trigonometric or otherwise.

void generateHeightsCos()
{
heights = new float[xResolution][yResolution];
for (int y = 0; y < yResolution; y++) {
for (int x = 0; x < xResolution; x++) {
heights[x][y] = cos(2 * 3 * PI * x / xResolution);
}
}
}


I use the above code to generate a cosine curve (I'm also using a 2d input and 2d Fourier transforms which is unshifted but I can shift it). The transform looks like this - I don't think there's any problem here.

So now to get the average frequency (not wavelength I know but its in frequency domain) I used the following code:

float GetMeanFrequency(Complex[][] input)
{
float total = 0;
float totalCounts = 0;

float count;
for (int y = 0; y < yResolution; y++) {
for (int x = 0; x < xResolution; x++) {
count = input[x][y].magnitude();
total += x * count;
totalCounts += count;
}
}
}


So the problem with this is the symmetry of Fourier transforms. Because of the symmetry it will return xResolution / 2 no matter the frequency of the input. I could add a condition so it only checks the left half but then it won't work for higher frequency inputs.

The DFT includes both negative and positive frequencies.

For example, if there are $$N=8$$ samples in the signal, then the DFT bin frequencies will be as shown. I've used a 1-D example to keep it simple.

where $$f_s$$ is the sampling frequency.

In reality, the left half is the only half that really matters in the case where you want to find the average frequency.