00001
00005 #include <bpm/bpm_interface.h>
00006 #include <bpm/bpm_rf.h>
00007 #include <bpm/bpm_alloc.h>
00008 #include <bpm/bpm_nr.h>
00009
00019 int rf_complexFFT( double **in, double **out, int dir ) {
00020
00021
00022 int i = 0;
00023 double f;
00024
00025 if ( ( ! in ) || ( ! out ) ) {
00026 bpm_error( "Invalid pointers in rf_complexFFT(...)",
00027 __FILE__, __LINE__ );
00028 return BPM_FAILURE;
00029 }
00030
00031
00032 int ns = 1;
00033 while ( ns < rf_nsamples ) {
00034 ns *= 2;
00035 }
00036
00037
00038
00039 double *cp = (double*) calloc( 2*ns+1, sizeof(double) );
00040
00041 if( ! cp ) {
00042 bpm_error( "Could not allocate memory in rf_complexFFT(...)",
00043 __FILE__, __LINE__ );
00044 return BPM_FAILURE;
00045 }
00046
00047
00048 for( i = 0; i < rf_nsamples; i++ ) {
00049
00050
00051 cp[2*i+1] = in[i][Re];
00052 cp[2*i+2] = in[i][Im];
00053
00054 }
00055
00056 if ( nr_four1( cp, ns, dir ) == BPM_FAILURE ) {
00057 free(cp);
00058 bpm_error( "Unable to execute nr_four routine in rf_complexFFT(...)",
00059 __FILE__, __LINE__ );
00060 return BPM_FAILURE;
00061 }
00062
00063
00064 for( i = 0; i < rf_nsamples; i++ ) {
00065 out[i][Re] = cp[2*i+1];
00066 out[i][Im] = cp[2*i+2];
00067 }
00068
00069 free (cp);
00070
00071 return BPM_SUCCESS;
00072 }
00073