|
|
|
|
@@ -25,14 +25,14 @@
|
|
|
|
|
* @param[out] resEnvelopeRef, result of envelope of reference aScan
|
|
|
|
|
*
|
|
|
|
|
**/
|
|
|
|
|
int calculateBankDetectAndHilbertTransformation(float* aScans_r, float* aScansRef_r,int numberScans, int numberSamples, int RESAMPLE_FACTOR, int nthreads, float* resDetect, float* resEnvelope, float* resEnvelopeRef) {
|
|
|
|
|
int calculateBankDetectAndHilbertTransformation(double* aScans_r, double* aScansRef_r,int numberScans, int numberSamples, int RESAMPLE_FACTOR, int nthreads, double* resDetect, double* resEnvelope, double* resEnvelopeRef) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// resampling infos
|
|
|
|
|
int nresample_c; // for complex hermetian symmetry for upsample 2 -> stays the same (!)
|
|
|
|
|
int nresample_r; // for real from hermetian symmetry for upsample 2 -> stays the same (!)
|
|
|
|
|
|
|
|
|
|
float scale;
|
|
|
|
|
double scale;
|
|
|
|
|
|
|
|
|
|
bool even;
|
|
|
|
|
|
|
|
|
|
@@ -43,18 +43,18 @@ int calculateBankDetectAndHilbertTransformation(float* aScans_r, float* aScansRe
|
|
|
|
|
int endIndex;
|
|
|
|
|
|
|
|
|
|
// interim results
|
|
|
|
|
static fftwf_complex* resultCrossCor_c = NULL;
|
|
|
|
|
static fftwf_complex* aScans_c_res = NULL;
|
|
|
|
|
static fftwf_complex* aScansRef_c_res = NULL;
|
|
|
|
|
static fftwf_complex* aScans_c = NULL;
|
|
|
|
|
static fftwf_complex* aScansRef_c = NULL;
|
|
|
|
|
float* resultCrossCor_r;
|
|
|
|
|
float* aScans;
|
|
|
|
|
static fftw_complex* resultCrossCor_c = NULL;
|
|
|
|
|
static fftw_complex* aScans_c_res = NULL;
|
|
|
|
|
static fftw_complex* aScansRef_c_res = NULL;
|
|
|
|
|
static fftw_complex* aScans_c = NULL;
|
|
|
|
|
static fftw_complex* aScansRef_c = NULL;
|
|
|
|
|
double* resultCrossCor_r;
|
|
|
|
|
double* aScans;
|
|
|
|
|
|
|
|
|
|
// fftw plans
|
|
|
|
|
static fftwf_plan plan_fftAScans_rc = NULL;
|
|
|
|
|
static fftwf_plan plan_ifftAScans_cr = NULL;
|
|
|
|
|
static fftwf_plan plan_ifftAScans_cc = NULL;
|
|
|
|
|
static fftw_plan plan_fftAScans_rc = NULL;
|
|
|
|
|
static fftw_plan plan_ifftAScans_cr = NULL;
|
|
|
|
|
static fftw_plan plan_ifftAScans_cc = NULL;
|
|
|
|
|
|
|
|
|
|
// fftw wisdom
|
|
|
|
|
char filenameFftwWisdom[200] = "";
|
|
|
|
|
@@ -63,14 +63,14 @@ int calculateBankDetectAndHilbertTransformation(float* aScans_r, float* aScansRe
|
|
|
|
|
nresample_r = numberSamples * RESAMPLE_FACTOR;
|
|
|
|
|
nresample_c = numberSamples * RESAMPLE_FACTOR / 2;
|
|
|
|
|
|
|
|
|
|
scale = float((1.0 / nresample_r)* RESAMPLE_FACTOR);
|
|
|
|
|
scale = double((1.0 / nresample_r)* RESAMPLE_FACTOR);
|
|
|
|
|
|
|
|
|
|
even = (nresample_r / 2.0);
|
|
|
|
|
|
|
|
|
|
// load wisdom
|
|
|
|
|
sprintf(filenameFftwWisdom, "fftwf_wisdom_detection_%d.wis", FFTW_WISDOM_TYPE);
|
|
|
|
|
sprintf(filenameFftwWisdom, "fftw_wisdom_detection_%d.wis", FFTW_WISDOM_TYPE);
|
|
|
|
|
int loadedWisdomUsed = 0;
|
|
|
|
|
if(fftwf_import_wisdom_from_filename(filenameFftwWisdom) == 0) {
|
|
|
|
|
if(fftw_import_wisdom_from_filename(filenameFftwWisdom) == 0) {
|
|
|
|
|
// printf("wisdom not loaded.\n");
|
|
|
|
|
} else {
|
|
|
|
|
loadedWisdomUsed = 1;
|
|
|
|
|
@@ -78,33 +78,33 @@ int calculateBankDetectAndHilbertTransformation(float* aScans_r, float* aScansRe
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// mem alloc
|
|
|
|
|
resultCrossCor_c = (fftwf_complex*)fftwf_malloc(sizeof(fftwf_complex) * numberScans * nresample_r);
|
|
|
|
|
aScans_c_res = (fftwf_complex*)fftwf_malloc(sizeof(fftwf_complex) * numberScans * nresample_r);
|
|
|
|
|
aScansRef_c_res = (fftwf_complex*)fftwf_malloc(sizeof(fftwf_complex) * numberScans * nresample_r);
|
|
|
|
|
resultCrossCor_r = (float*)malloc(numberScans * nresample_r * sizeof(float));
|
|
|
|
|
aScans_c = (fftwf_complex*)fftwf_malloc(sizeof(fftwf_complex) * numberScans * numberSamples);
|
|
|
|
|
aScansRef_c = (fftwf_complex*)fftwf_malloc(sizeof(fftwf_complex) * numberScans * numberSamples);
|
|
|
|
|
aScans = (float*)malloc(numberScans * numberSamples * sizeof(float));
|
|
|
|
|
resultCrossCor_c = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * numberScans * nresample_r);
|
|
|
|
|
aScans_c_res = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * numberScans * nresample_r);
|
|
|
|
|
aScansRef_c_res = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * numberScans * nresample_r);
|
|
|
|
|
resultCrossCor_r = (double*)malloc(numberScans * nresample_r * sizeof(double));
|
|
|
|
|
aScans_c = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * numberScans * numberSamples);
|
|
|
|
|
aScansRef_c = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * numberScans * numberSamples);
|
|
|
|
|
aScans = (double*)malloc(numberScans * numberSamples * sizeof(double));
|
|
|
|
|
|
|
|
|
|
/* fftw initializations */
|
|
|
|
|
// thread ini
|
|
|
|
|
if ((nthreads > 0)) {
|
|
|
|
|
if (fftwf_init_threads() == 0){
|
|
|
|
|
if (fftw_init_threads() == 0){
|
|
|
|
|
printf("Data input are not the same size. Exiting.");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
fftwf_plan_with_nthreads(nthreads);
|
|
|
|
|
fftw_plan_with_nthreads(nthreads);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// plan creations
|
|
|
|
|
plan_fftAScans_rc = fftwf_plan_many_dft_r2c(1, &numberSamples, numberScans, aScans, NULL, 1, numberSamples, aScans_c_res, &nresample_r, 1, nresample_r, FFTW_WISDOM_TYPE);
|
|
|
|
|
plan_ifftAScans_cr = fftwf_plan_many_dft_c2r(1, &nresample_r, numberScans, resultCrossCor_c, NULL, 1, nresample_r, resultCrossCor_r, &nresample_r, 1, nresample_r, FFTW_WISDOM_TYPE);
|
|
|
|
|
plan_ifftAScans_cc = fftwf_plan_many_dft(1, &numberSamples, numberScans, aScans_c_res, NULL, 1, nresample_r, aScans_c, &numberSamples, 1, numberSamples, 1, FFTW_WISDOM_TYPE);
|
|
|
|
|
plan_fftAScans_rc = fftw_plan_many_dft_r2c(1, &numberSamples, numberScans, aScans, NULL, 1, numberSamples, aScans_c_res, &nresample_r, 1, nresample_r, FFTW_WISDOM_TYPE);
|
|
|
|
|
plan_ifftAScans_cr = fftw_plan_many_dft_c2r(1, &nresample_r, numberScans, resultCrossCor_c, NULL, 1, nresample_r, resultCrossCor_r, &nresample_r, 1, nresample_r, FFTW_WISDOM_TYPE);
|
|
|
|
|
plan_ifftAScans_cc = fftw_plan_many_dft(1, &numberSamples, numberScans, aScans_c_res, NULL, 1, nresample_r, aScans_c, &numberSamples, 1, numberSamples, 1, FFTW_WISDOM_TYPE);
|
|
|
|
|
|
|
|
|
|
// DFT of input signals
|
|
|
|
|
fftwf_execute_dft_r2c(plan_fftAScans_rc, aScans_r, aScans_c_res);
|
|
|
|
|
fftwf_execute_dft_r2c(plan_fftAScans_rc, aScansRef_r, aScansRef_c_res);
|
|
|
|
|
fftw_execute_dft_r2c(plan_fftAScans_rc, aScans_r, aScans_c_res);
|
|
|
|
|
fftw_execute_dft_r2c(plan_fftAScans_rc, aScansRef_r, aScansRef_c_res);
|
|
|
|
|
|
|
|
|
|
/* Calculus of fft(tab1)* conj(fft(tab2)) (first part) */
|
|
|
|
|
/* and calculations for hilbert transform */
|
|
|
|
|
@@ -154,38 +154,39 @@ int calculateBankDetectAndHilbertTransformation(float* aScans_r, float* aScansRe
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Execute a IDFT plan
|
|
|
|
|
fftwf_execute(plan_ifftAScans_cr);
|
|
|
|
|
fftwf_execute_dft(plan_ifftAScans_cc,aScans_c_res,aScans_c);
|
|
|
|
|
fftwf_execute_dft(plan_ifftAScans_cc,aScansRef_c_res,aScansRef_c);
|
|
|
|
|
fftw_execute(plan_ifftAScans_cr);
|
|
|
|
|
fftw_execute_dft(plan_ifftAScans_cc,aScans_c_res,aScans_c);
|
|
|
|
|
fftw_execute_dft(plan_ifftAScans_cc,aScansRef_c_res,aScansRef_c);
|
|
|
|
|
|
|
|
|
|
// maximum detection
|
|
|
|
|
maximumDetection(resultCrossCor_r, numberScans, nresample_r, resDetect);
|
|
|
|
|
|
|
|
|
|
// abs calculation, adapt scaling
|
|
|
|
|
#pragma omp parallel for num_threads(nthreads)
|
|
|
|
|
for (int i = 0; i < numberSamples * numberScans; i++) {
|
|
|
|
|
resEnvelope[i] = sqrt(aScans_c[i][REAL] * aScans_c[i][REAL] + aScans_c[i][IMAG] * aScans_c[i][IMAG]) * scale;
|
|
|
|
|
resEnvelopeRef[i] = sqrt(aScansRef_c[i][REAL] * aScansRef_c[i][REAL] + aScansRef_c[i][IMAG] * aScansRef_c[i][IMAG]) * scale;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Store Wisdom
|
|
|
|
|
fftwf_export_wisdom_to_filename(filenameFftwWisdom);
|
|
|
|
|
fftw_export_wisdom_to_filename(filenameFftwWisdom);
|
|
|
|
|
|
|
|
|
|
// clean
|
|
|
|
|
fftwf_destroy_plan(plan_fftAScans_rc);
|
|
|
|
|
fftwf_destroy_plan(plan_ifftAScans_cr);
|
|
|
|
|
fftwf_destroy_plan(plan_ifftAScans_cc);
|
|
|
|
|
fftw_destroy_plan(plan_fftAScans_rc);
|
|
|
|
|
fftw_destroy_plan(plan_ifftAScans_cr);
|
|
|
|
|
fftw_destroy_plan(plan_ifftAScans_cc);
|
|
|
|
|
|
|
|
|
|
fftwf_free(resultCrossCor_c);
|
|
|
|
|
fftwf_free(aScans_c_res);
|
|
|
|
|
fftwf_free(aScansRef_c_res);
|
|
|
|
|
fftwf_free(aScans_c);
|
|
|
|
|
fftwf_free(aScansRef_c);
|
|
|
|
|
fftw_free(resultCrossCor_c);
|
|
|
|
|
fftw_free(aScans_c_res);
|
|
|
|
|
fftw_free(aScansRef_c_res);
|
|
|
|
|
fftw_free(aScans_c);
|
|
|
|
|
fftw_free(aScansRef_c);
|
|
|
|
|
free(resultCrossCor_r);
|
|
|
|
|
free(aScans);
|
|
|
|
|
|
|
|
|
|
// fftwf_cleanup_threads();
|
|
|
|
|
// fftwf_cleanup();
|
|
|
|
|
fftwf_forget_wisdom();
|
|
|
|
|
// fftw_cleanup_threads();
|
|
|
|
|
// fftw_cleanup();
|
|
|
|
|
fftw_forget_wisdom();
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|