Is it possible to input a manual frequency axis as a function argument in np.fft and get the FFT evaluated at those frequency points?

35 Views Asked by At

I have an equation that can be expressed in a somewhat Fourier transform-like expression. (I can't find a way to write in latex format so I am trying to write in c code format). For a function f in a grid of M points, I evaluate a function on a kind of different grid. So my expression looks like

F[n] = np.sum( np.exp(-2j * np.pi * k * n / N) * f[k])

with k = np.linspace(0, M-1, M), i.e. k ranges from 0 to M with M < N. Because of this, if I want to evaluate the above expression in a Fourier-transformed way, I rewrite the above expression as

F[n] = np.sum( np.exp(-2j * np.pi * (k*M/N) * n / M) * f[k])

So now as you can see, my effective index is now (kM/N) which is no longer an integer. I can do a manual Fourier transform by writing my own code for each n index.

For now, I am creating an NxM matrix containing the exponential term and multiplying this with my vector (M elements) to get another vector of N elements. The current implementation looks more like,

F = np.exp(-2j * np.pi * np.outer(n, k) / N) @ f[k]

with k = np.linspace(0, M-1, M) and n = np.linspace(0, N-1, N). This gets very expensive (both computation time and from memory perspective) for very large matrices and so I want to use the existing FFT functionality in Numpy or Scipy and do not see a way to input my manual frequency axis as an argument inside the np.fft.fft function. Also, I am unclear about how to convert this into an FFT kind of problem. Another question I have is how do I perform FFT for a single frequency input point using np.fft.fft (or from Scipy)?

0

There are 0 best solutions below