Fourier Transformation vs Numpy FFT
Asked Answered
A

2

6

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

I want to calculate Fourier transform of a function f(x). So I define a numpy array X and pass through vectorized function f. Now if I calculate the FFT of this array f(X) it does not come out to be Fourier Transform of f(x) as it would if I do it on a piece of paper. For example If I calculate FFT of Gaussian I should get a Gaussian or an array whose real part would resemble a Gaussian very closely.

here is the code. please let me know what I have 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 reiterate. I want to calculate Fourier transform of any function (e.g. gaussian). FFT is way to calculate Fourier transform of an array of numbers but this is not same as simple discretization of continuous Fourier transform formula.

Athenaathenaeum answered 16/5, 2014 at 17:7 Comment(0)
M
7

No, the FFT is not a way to calculate the Fourier transform (FT) of a function. The FFT is a fast algorithm to calculate the DFT, discrete Fourier transform of an array of samples. This array of samples can be interpretated as the sampling of a function at equi-spaced points.

The DFT and the FT are 2 different things, and you can't use the DFT to calculate the FT. See this link on their differences.

If your function is periodic, then its spectrum is a function defined only at points, and you can use the DFT on equi-spaced samples of the function to infer the FT with good success, if you choose very carefully your domain and sampling rate, and the domain is a multiple of all the periods of all the harmonics of your function.

Merrilee answered 16/5, 2014 at 18:0 Comment(2)
Are you actually claiming that a Discrete Fourier Transform is not a Fourier transform?Sanbenito
I am stating that the DFT is not the FT. The FT usually refers to the continuous Fourier transform of a function. I will slightly edit the post to avoid confusion.Merrilee
A
4

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

Ane answered 6/6, 2014 at 9:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.