Why I'm getting very bad results with FFT?

8 views (last 30 days)
My goal is to be able to compute the derivative of a function using its Fourier transform. I have a simple example below. The function will be smooth but won't be periodic.
tf=1; %total time
dt=0.001;
tvec=0:dt:tf;
n0=length(tvec);
f=tvec.^2;
n=2^(nextpow2(n0));
fvec=2*pi/totaltime*linspace(-n0/2,n0/2-1,n);
fftf=fftshift(fft(f,n));
fftdf=1i*fvec.*fftu; %the fourier transform of the 1st derivative of f
idft=real(ifft(ifftshift(fftdf)));
plot(idft(1:n0))
As you can see the result is very bad. What's wrong here? How can I get better resutls?

Answers (1)

Walter Roberson
Walter Roberson on 18 Apr 2020
fft has as a mathematical basis the idea that the signal is periodic. As your function is not periodic, and it is numeric, then to represent it for use with fft, you will need to use an infinite number of samples (and I do not mean "large number", I mean literal countable infinity)

Categories

Find more on Fourier Analysis and Filtering in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!