Ejemplo n.º 1
0
//----------------------------------------------------------------------
MAT EEMD::eemdf90( VEC input, float noise_amplitude, int num_imfs, int num_ensembles ) {

    // Obtain a pointer to the data in the input array for the Fortran function
    float* indata = input.memptr();
    int length = input.size();
    int seed = tools->getRand(); // C++ random seed for the F90 random number generator
    float* result = new float[length*(num_imfs+2)]; // Store the results

    // Call the Fortran subroutine
    eemd_( length, indata, noise_amplitude, 
            num_ensembles, num_imfs, seed, result );

    // Create the resulting armadillo structure to store the result
    MAT imfs(result,length,num_imfs+2); 

    // The last column of the result is the residue (from F90 documentation
    // in file eemdf90/eemd.f90)
    residual = imfs.col(num_imfs+1);
    imfs.shed_col(num_imfs+1);

    // The Very first column is the original signal (from F90 documentation
    // in file eemdf90/eemd.f90)
    VEC f90_input = imfs.col(0);
    imfs.shed_col(0);

    // A sanity check to help see if the F90 result makes any sense
    float diff = norm( f90_input-input, 2 );
    if( diff > .1 && false ) {
        printf( "\n\tFortran input signal differs from the C++ input signal by %f \n", diff);
        //for( int i=0; i<length; i++ ) {
        //    printf( "C++[%d] = %f \t F90[%d] = %f\n", i, input[i], i, f90_input[i] );
        //}
        exit(EXIT_FAILURE);
    }

    return imfs;

}