Fourier Transform vs Nump FFT

This is probably a very naive question, but here it is.

I want to calculate the Fourier transform of the function f (x). So I define a numpy X array and pass it through a vectorized function f. Now, if I calculate the FFT of this array f (X), it is not the Fourier transform of the function f (x), as if I were doing this on a piece of paper. For example, if I calculate the FFT of a Gaussian, I have to get a Gaussian or array, the real part of which will be very close to Gaussian.

here is the code. let me know what I need to change to get the usual Fourier transform.

import matplotlib.pyplot as plt import numpy as np N = 128 x = np.linspace(-5, 5, N) y = np.exp(-x**2) y_fft = np.fft.fftshift(np.fft.fft(y).real) plt.plot(x, y_fft) plt.show() 

let me repeat it. I want to calculate the Fourier transform of any function (e.g., Gaussian). FFT is a way to calculate the Fourier transform from an array of numbers, but it's not the same as simply sampling a continuous Fourier transform formula.

+6
source share
2 answers

No, FFT is not a way to calculate the Fourier transform (FT) of a function. FFT is a fast algorithm for computing DFT, discrete Fourier transform from an array of samples. This array of samples can be interpreted as a sample of a function at equal points to each other.

DFT and FT are two different things, and you cannot use DFT to calculate FT. See Link for differences.

If your function is periodic, then its spectrum is a function defined only at points, and you can use DFT on equidistant function samples to make FT successful if you select your domain and sampling frequency very carefully, and the area is a multiple of all periods of all harmonics your function.

+7
source

I think I answered your question here . (I didn’t see your question before asking and answering it myself in the link above)

+2
source

Source: https://habr.com/ru/post/969394/


All Articles