I hope this is the right place to ask this question since it is partially a note which might help others. Until recently, I always used the fft-algorithm implemented in the language of my choice if I wanted to calculate a spectrum. The main reason being it is easily available and is mentioned in every course on the subject (The real upside is of course the fact that it is a fast implementation of the discrete Fourier transform.), Lately though, I started to use my own custom version of the actual Fourier transform (python example, avoiding loops)

import numpy as np
from scipy.signal import get_window

def calc_fft(f, t, w, window_function='boxcar'):
    N = len(t)
    dw = w[1] - w[0]

    window = get_window(window_function, N)

    W, T = np.meshgrid(w, t)
    kernel = np.exp(-1j * W * T)

    # I normalize with dw here, because I want to integrate over the spectrum
    fft_func = np.sum(kernel * (f * window)[:, np.newaxis], axis=0) * dw

    # If your function is not centered around t=0, you might want to add those lines
    # t_mid = (t[-1] - t[0]) / 2
    # fft_func = fft_func * np.exp(+1j * w * t_mid)

    return w, fft_func

and don't see any reason to switch back. The upsides are:

  1. No padding is required (It can be quite large to get good resolution)
  2. We can specify the range and amount of calculated frequencies

with the only downside that it is of course slower, which is no problem for post processing.

So was I just having tunnel vision and it is actually common to calculate the actual Fourier transform or is something which should be added to the normal signal processing packages? Or is there another point, I'm just missing?

  • 1
    $\begingroup$ I do something very similar myself, but the function arguments I use are start frequency, end frequency, and number of frequencies to sample at. BTW, by sampling at arbitary frequencies, this is no longer the DFT, but rather samples of the DTFT. $\endgroup$
    – MBaz
    Commented Nov 14, 2023 at 18:47
  • $\begingroup$ @MBaz I do the same, but I wanted to post the most simple version :) I'd argue that it is sampling of the actual Fourier Transform since we don't assume periodicity. But of course my main point here is usability for signal processing. $\endgroup$
    – TheIdealis
    Commented Nov 14, 2023 at 19:01
  • $\begingroup$ The main point of the FFT is execution speed. If you only need a few frequencies, it's actually quite common to do it using the original DFT sum. I don't think you'll find it in most packages since its trivial to write your own. $\endgroup$
    – Hilmar
    Commented Nov 14, 2023 at 19:59
  • $\begingroup$ @TheIdealis It's not the FT because the input is discrete. And, the DTFT does not assume periodicity :) $\endgroup$
    – MBaz
    Commented Nov 14, 2023 at 22:24


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.