fourier analysis – Is there a built-in equivalent to numpy’s fftfreq?
It’s not obvious, but a concise implementation for the functionality can actually be found in
What’s wrong with this FFT-based Von Kármán vortex street simulation?
Taking the relevant part out, we have:
fftfreq[n_, d_ : 1] := Mod[Range@n - 1, n, -n/2]/(d n)
Usage (Mimicking the example in document of numpy.fft.fftfreq
):
signal = {-2, 8, 6, 4, 1, 0, 3, 5};
fourier = Fourier[signal];
n = signal // Length;
d = 0.1;
freq = fftfreq[n, d];
freq
(* {0., 1.25, 2.5, 3.75, -5., -3.75, -2.5, -1.25} *)
Check:
npfftfreq = ExternalFunction["Python", "import numpy; numpy.fft.fftfreq"];
fftfreq[##] == npfftfreq[##] & @@@ {{7}, {8}, {9, 0.13}, {10, 2.1}}
(* {True, True, True, True} *)
Read more here: Source link