Fast Fourier Transform decomposes signals into frequencies. scipy.fft (and numpy.fft) power spectral analysis; scipy.signal adds windows and filtering.
Concept
- Time-domain samples → frequency-domain amplitudes
fft.fft(x)— complex spectrumfft.fftfreq(n, d=dt)— frequency bins for sample spacing d- Magnitude
np.abs(spectrum)for power plots
Pure tone detection
import numpy as np
from scipy import fft
rate = 100
t = np.arange(0, 1, 1/rate)
x = np.sin(2 * np.pi * 5 * t)
spectrum = fft.fft(x)
freqs = fft.fftfreq(len(t), 1/rate)
idx = np.argmax(np.abs(spectrum[:len(t)//2]))
print('peak freq ~', abs(freqs[idx]), 'Hz')
Important interview questions and answers
- Q: Nyquist frequency?
A: Half the sample rate—frequencies above alias and corrupt analysis. - Q: Why windowing?
A: Reduces spectral leakage when signal does not fit an integer number of periods.
Self-check
- What does FFT convert between?
- What is the Nyquist limit for sample rate 1000 Hz?
Tip: Remember Nyquist: sample rate must exceed twice your highest frequency of interest.
Interview prep
- FFT purpose?
Time to frequency domain—find periodic components.
- Nyquist?
Max reliable frequency is half sample rate.