Discrete Fourier Transform
The latest commit to the project includes my first implementation of the Discrete Fourier transform. This function transforms amplitude-time data to amplitude-frequency data. Essentially, it can be used in spectral analysis to extract all the sinusoids that make up a signal.
It is defined as:
</img>
This formula can be derived further into a form more commonly used in Computer Science:
</img>
The variables are:
- N = number of time samples we have
- n = current sample we’re considering (0…N-1)
- xn = value of the signal at time n
- k = current frequency we’re considering (0 Hertz up to N-1 Hertz)
- Xk = amount of frequency k in the signal (Amplitude and Phase, a complex number)
Using this formula, I wrote an implementation in Python. Note that X is called amplitudes and k_amp is the sum of the sequence x in my implementation.
The main ambiguity in the definition of the Fourier Transform is the scaling factor of the amplitudes. The many different implementations of the Fourier Transform that can be found on the internet all use different scaling factors. The main three scaling factors that are used are as follows:
- 1 forward, 1/N inverse
- 1/N forward, 1 inverse
- 1/sqrt(N) forward, 1/sqrt(N) inverse
I noticed that Wolfram Alpha was using the 1/sqrt(N) factor. However, I chose to use the factor of 1 for the time being. This is the definition used on Wikipedia.
While this is a good initial implementation, I will be using the Fast Fourier Transform (FFT) in the final project, as it is theoretically around 100 times faster.
I may edit this post a little to explain the Fourier Transform and its implementation better.