To analyze the frequency content of a data stream, we use the Fast Fourier Transform (FFT), which efficiently computes the Discrete Fourier Transform (DFT). One of the most widely used FFT algorithms is the Cooley–Tukey algorithm, which is a radix-2 divide-and-conquer method. It breaks down a DFT of size N (where N is a power of 2) into smaller DFTs of size , recursively, which reduces computational complexity from
to .
Python Code for FFT
def compute_fft(self, signal):
fft_result = np.fft.fft(signal)
freq = np.fft.fftfreq(len(signal), d=1/self.samplingFrequency)
return np.abs(fft_result), freq
In our case, we will perform the Fast Fourier Transform (FFT) on sine, cosine, rectangular, and triangular signals.
Example code to compute the Fourier Transform of sine, cosine, rectangular, and triangular waveforms: