I have a basic understanding of the Fourier Transform, though I’m trying to use it in a program and I’m confused on the specifics. Based on source code I can find online, the DFT takes a set of samples/numbers, performs a summation for each term, and returns a set of these summations which is the same size as the input set. Suppose I have a periodic function. As I understand it, the output array should contain the amplitudes/weights of each frequency which sum to that function. What I can’t figure out is how each frequency is encoded in the array as just an index. In each example I read, we just assign a summation at each iteration of the inner loop to the next consecutive index in the output array. How are these indices indicative of which frequency they correspond to?
I’m attaching the source code I’m referencing to the bottom of this in case the website I linked to ever goes down.
import cmath def compute_dft_complex(input): n = len(input) output =  for k in range(n): # For each output element s = complex(0) for t in range(n): # For each input element angle = 2j * cmath.pi * t * k / n s += input[t] * cmath.exp(-angle) output.append(s) return output