Wednesday, January 8, 2014

Inverse Fast Fourier Transformation in MATLAB

In this, i am going to show how the inverse fast fourier transformation can be used to find the $n^{th}$ derivative of a hyperbolic secant function sech(x)

Fourier transform has the an amazing property: $\hat{f^{(n)}(k)}=(ik)^n\hat{f(k)}$ where $k$ is the frequency of the Fourier Transform $\hat{f(k)}=\frac{1}{2L} \int_{-L/2}^{L/2} f(x)exp(-i k \pi x/L)dx$ and $f^{(n)}$ is the $n^{th}$ derivative of the function $f(x)$. Therefore $\hat{f^{(n)}(k)}$ is the Fourier transform of the $n^{th}$ derivative of $f(x)$.

Due to this property, we can find the $n^{th}$ derivative of $f(x)$ by first obtaining the $\hat{f^{(n)}(k)}$ then performing an inverse Fourier transform

The sample code below first computes the first and second derivative of sech(x) (i.e. ud and u2d) then compare it against the ones computed using the method described above using inverse Fourier Transform (ifft) (i.e. uds and u2ds) and finally plot ud versus uds

clear all; close all; clc;

L=20;
n=128;

x2=linspace(-L/2, L/2, n+1);

x=x2(1:n);

k=(2*pi/L)*[0:n/2-1 -n/2:-1];

u=sech(x);
ud=-sech(x).*tanh(x);
u2d=sech(x)-2*sech(x).^3;

ut=fft(u);

uds=ifft((i*k).*ut);
u2ds=ifft((i*k).^2.*ut);

ks=fftshift(k);

plot(x, ud, 'r', x, uds, 'mo');

No comments:

Post a Comment