Wednesday, January 05, 2011

Trials of EMD C code

I found a simple module of EMD in C on google code: realtime-emd. The source code, however, has no main function to invoke the modules. So I wrote one as the follows.

#include <stdio>
#include "EmpiricalModeDecomposition.h"

void imfs_output(emdData* emd){
        int i, j;

        for(j = 0; j < emd->size; j++){
                for(i = 0; i < emd->order; i++) {
                        printf("%f ", emd->imfs[i][j]);
                }   
                printf("\n");
        }   
}

int main(void){
        FILE *inputfile = fopen("sinusoid.txt","r");
        int i=0;
        float signal[1024]={0.0};
        emdData data;

        while (fscanf(inputfile, "%f", &signal[i]) != EOF){
                //printf("%d %f\n",i,signal[i]);
                i++;
        }

        emdCreate(&data,i,5,10,0); // problems here
        emdDecompose(&data,signal);
        imfs_output(&data);
        emdClear(&data);

        fclose(inputfile);
        return 0;
}


The main problem is the arguments of the function emdCreate. I am not sure how to set proper parameters to obtain correct results, so please take this clip of code as just a reference.

You can download the main.c and sinusoid.txt for testing. The input file sinusoid.txt was generate by adding several sinusoidal signals.

5 comments:

  1. Hello, I can't get the sinusoid.txt, can you send the txt to my email, think you very much!
    lizhonghai0729@gmail.com

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
    2. Hi, thank you for notifying me about this.

      I have just make the files public.
      Please check again.

      Delete
  2. Hey, were you able to get the correct inputs finally ?

    ReplyDelete