I am trying to verify this relation with the fftw library:
Therefore, I chose f to be a Gaussian, computed the Fourier Transform of its derivative and compared it with the one of the Fourier Transform of the Gaussian multiplied by ik. Here is what I get:
It is very strange, especially because the plot of the Fourier Transform of the derivative of the Gaussian (i.e the red one) is not 0 at the origin, while it should be (I checked with the analytic one).
The code seems ok to me, anyhow here it is (I am using C):
int main() {
int i, N = 100;
double v[N], x[N], k[N/2+1], vd[N];
double dx = 2*pi/N, dk=2*pi/(N*dx), tmp;
fftw_complex *out;
fftw_plan forward,inverse;
out = ( fftw_complex* )fftw_malloc( sizeof( fftw_complex )*( N/2 + 1 ));
forward = fftw_plan_dft_r2c_1d(N, v, out, FFTW_ESTIMATE);
inverse = fftw_plan_dft_c2r_1d(N, out, vd, FFTW_ESTIMATE);
//Initialise arrays
for( i = 0; i < N; i++ ) {
x[i] = dx*i;
v[i] = -2*x[i]*exp( -pow( x[i], 2) );
printf( " %le %le \n ", x[i], v[i] );
}
for( i = 0; i < N; i++ ) {
k[i]=i*dk;
}
k[N/2]=0.;
//Compute fft
fftw_execute( forward );
//Print the results
for( i = 0; i < N/2 + 1 ; i++ ) {
printf( "%le %le %le \n", i*dk, out[i][0], out[i][1] );
}
//Multiply by ik
for( i = 0; i < ( N/2 + 1 ); i++ ) {
tmp=out[i][0];
out[i][0]=-k[i]*out[i][1];
out[i][1]=k[i]*tmp;
printf( "%le %le %le \n", i*dk, out[i][0], out[i][1] );
}
fftw_destroy_plan(forward);
fftw_destroy_plan(inverse);
fftw_free(out);
return 0;
}
Could anyone please tell me what I am doing wrong?