/* * fftSub.c * * Functions for initializing and performing FFT on waveforms from * the beam profiler. * * Created on: Oct 26, 2015 * Author: Hovanes Egiyan */ #include #include #include #include #include #include #include #include #include #include #include #include "ddcmath.h" #include "fourier.h" int fftDebug = 10; /* * Initialize records to save PXI data */ static long fftInit( aSubRecord *record ) { /* if ( fftDebug > 2 ) printf( "Record %s called fftInit(%p)\n", record->name, (void*) record );*/ return 0; } /* * Process records to save PXI data */ static long fftProcess( aSubRecord *record ) { /* if ( fftDebug > 2 ) printf( "Record %s called fftProcess(%p)\n", record->name, (void*) record );*/ /* INPA will be the record whose transform will need to be computed */ unsigned nFIFO = record->noa; /* the OUTB field is going to be the real part */ unsigned halfFIFO = record->novb; float realPart[nFIFO], imgPart[nFIFO]; /* float power[halfFIFO], phase[halfFIFO]; */ // first copy the input data to vala since vala will be set to float memcpy( record->vala, record->a, nFIFO * (sizeof(float)) ); /* Do fast-fourier transform using the float numbers in vala. The real part will be in valb, the imaginary part will be in valc. */ fft_float( nFIFO, 0, record->vala, NULL, realPart, imgPart ); /* Copy real part and imaginary part to B and C output * Only first half is copied since the second half is not determined. */ memcpy( record->valb, realPart, halfFIFO * (sizeof(float)) ); memcpy( record->valc, imgPart, halfFIFO * (sizeof(float)) ); // Calculate the power and the // for( unsigned iFIFO = 0; iFIFO < halfFIFO; iFIFO++ ) { // power[iFIFO] = sqrt(realPart[iFIFO]*realPart[iFIFO] + imgPart[iFIFO]*imgPart[iFIFO] ); // if( realPart[iFIFO] > 0 ) { // phase[iFIFO] = (float) atan2(imgPart[iFIFO],realPart[iFIFO] ) ; // } else { // phase[iFIFO] = acos(0.0); // } // } return 0; } epicsRegisterFunction( fftInit ); epicsRegisterFunction( fftProcess );