00001
00005 #include <stdio.h>
00006 #include <stdlib.h>
00007
00008 #include <bpm/bpm_messages.h>
00009 #include <bpm/bpm_process.h>
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 int fft_waveform_double( double *wf, int ns, double **fft) {
00022
00023 double *cp, ped, rms;
00024 int i;
00025
00026 if ( ! wf || ! fft ) {
00027 bpm_error( "Invalid waveform pointers in fft_waveform(...)",
00028 __FILE__, __LINE__ );
00029 return BPM_FAILURE;
00030 }
00031
00032
00033
00034 cp = (double*) calloc( 2*ns+1, sizeof(double) );
00035 if( ! cp ) {
00036 bpm_error( "Could not allocate memory in fft_waveform(...)",
00037 __FILE__, __LINE__ );
00038 return BPM_FAILURE;
00039 }
00040
00041 for( i=0; i<ns; i++ ) {
00042
00043
00044 cp[2*i+1] = wf[i];
00045 cp[2*i+2] = 0.;
00046 }
00047
00048 if ( nr_four1( cp, ns, 1 ) == BPM_FAILURE ) {
00049 free(cp);
00050 bpm_error( "Unable to execute nr_four routine in fft_waveform(...)",
00051 __FILE__, __LINE__ );
00052 return BPM_FAILURE;
00053 }
00054
00055
00056 for( i=0; i<ns; i++ ) {
00057
00058
00059 fft[i][Re] = cp[2*i+1];
00060 fft[i][Im] = cp[2*i+2];
00061 }
00062
00063 free( cp );
00064
00065 return BPM_SUCCESS;
00066 }
00067
00068
00069 int fft_waveform( int *intwf, int ns, double **fft ) {
00070 int i = 0;
00071
00072 double *wf = (double*)calloc(ns,sizeof(double));
00073
00074
00075 for(i=0;i<ns;i++) {
00076 wf[i] = (double)intwf[i];
00077 }
00078
00079
00080 fft_waveform(wf,ns,fft);
00081
00082
00083 free(wf);
00084 }