File Exchange

image thumbnail

Fourier derivative

version 1.0 (1.32 KB) by

A numerical differentiator for periodic functions using Fourier transformations



View License

Spectral methods of solving partial differential equations may involve the use of a Fourier transform to compute derivatives. If f is a uniformly sampled periodic function containing an even number of elements, then fourierderivative(f) computes the derivative of f with respect to the element spacing. For best results, f should be periodic such that f(x + a) = f(x + b). As an example,

x = linspace(0,pi);
f = exp(cos(x).*sin(2*x));
dfdx = fourierderivative(f,0,pi);

Results for nonperiodic f are dubious.

Comments and Ratings (1)

The constants being multiplied by the Fourier coefficients don't seem to be quite right, since 0 should not appear twice. See link below. Try [0:N/2-1, -N/2:-1] or fftshift(-N/2:N/2-1). These yield somewhat better accuracy.

MATLAB Release
MATLAB 7.10 (R2010a)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Win prizes and improve your MATLAB skills

Play today