This is just a note to self, for remembering the little details about NumPy's FFT implementation.
- To get the FFT bins to line up perfectly with a single frequency bin, without any "skirts" or spectral leakage, you need to make a perfect cycle, where the next sample after this chunk lines up with the first. (In other words, the first and last samples should not be the same.)
- To get a sinusoid of amplitude 1 (= 0 dBFS = -3 dBov) to produce 2 complex exponentials of amplitude 0.5, you need to divide the
fft()
results by the number of samples. - The
fft()
output is from 0 Hz to Nyquist frequency to sampling rate. To plot the spectrum from negative Nyquist frequency to positive Nyquist frequency, with 0 in the center, usefftshift()
on both thefreqs
andampl
variables. You can also just usefftfreq()
to generate a horizontal axis for plotting, but the plot will have extraneous lines on it.fftshift()
shifts the DC component from the bottom to the center of the spectrum.ifftshift()
shifts the DC component from the center to the bottom of the spectrum.- (They do the same thing for even-length, but not for odd-length.)
- If the result of an IFFT has some complex residue, use
real()
to get rid of it, notabs()
.
@joegle Thanks, I added it.