# frequency analysis without numpy

sturlamolden sturlamolden at yahoo.no
Wed Jan 21 00:13:44 CET 2009

```On Jan 20, 11:09 pm, debug <domelect... at gmail.com> wrote:

> So far i've managed to put together a chunk of code but I'm not sure
> its returning the right values, any ideas?

Don't use the periodogram for frequency analysis; it is not a good
estimate of the power spectrum. According to the Wiener-Khintchin
theorem, the power spectrum is the Fourier transform of the
autocorrelation, not the Fourier transform of the signal. You don't
want to just FFT the signal. FFTs are used for spectral estimation,
but not to obtain the periodogram. The periodogrgam is full of noise
and spectral leakage. And even worse, the variance of the periodogram
is constant, not inversely proportional to the number of samples. This
is not how you want a spectrum estimator to behave.

Consider using Thompson's multitaper method, autoregression (maximum
entropy), or Welch method for your frequency estimates. Blackman-
Tuckey is also a possibility, but I see no reason to prefer that to
Welch. Multitaper and AR tends to be the better options though, but
they are not as fast as Welch' method.

You probably also want to use real FFTs instead of complex FFTs,
unless you are interested in estimating the negative frequencies as
well. For common spectral analysis, real FFTs are almost always what
you want (complex FFTs can be used, but the incur redundant work).

Apart from that, an FFT in pure python is going to be atrociously slow
for anything but the shortest signals. I cannot imagine why you want
to do this. There are many free FFT libraries around, including
FFTPACK (used by NumPy) and FFTW.

The easiest way to check your FFT is to compare with a verified
implementation. I'd use NumPy or Matlab for that.

S.M.

```