0

I don't know if it's possible. In my app I am saving a list of arrays in a file.txt. (e.g.:

2012-09-02 16:27:15.010 SMAccelerometerDataLogger[1950:707] -0.818863 0.286575 0.206177

2012-09-02 16:27:15.017 SMAccelerometerDataLogger[1950:707] -1.024597 0.380875 0.456131

2012-09-02 16:27:15.023 SMAccelerometerDataLogger[1950:707] -0.754196 0.417053 1.165237

...

and I need (the first numbers array):

     -0.818863

     -1.024597

     0.754196

e.g in Gnuplot it is possible

plot "file.txt"using 2:7

I need this array to filter it by FFT, here is my code:

int SIZE = 97;

fftw_complex    *data, *fft_result, *ifft_result;
fftw_plan       plan_forward, plan_backward;
int             i;

data        = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * SIZE);
fft_result  = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * SIZE);
ifft_result = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * SIZE);

plan_forward  = fftw_plan_dft_1d(SIZE, data, fft_result,
                                 FFTW_FORWARD, FFTW_ESTIMATE);
plan_backward = fftw_plan_dft_1d(SIZE, fft_result, ifft_result,
                                 FFTW_BACKWARD, FFTW_ESTIMATE);


for( i = 0 ; i < SIZE ; i++ ) {
    data[i][0] = array[i][0];//>>>> here i should use the array that i need

    data[i][1] = 0.0; 
}


for( i = 0 ; i < SIZE ; i++ ) {
    fprintf( stdout, "data[%d] = { %2.2f, %2.2f }\n",
            i, data[i][0], data[i][1] );
}

fftw_execute( plan_forward );


for( i = 0 ; i < SIZE ; i++ ) {
    fprintf( stdout, "fft_result[%d] = { %2.2f, %2.2f }\n",
            i, fft_result[i][0], fft_result[i][1] );
}

fftw_execute( plan_backward );


for( i = 0 ; i < SIZE ; i++ ) {
    fprintf( stdout, "ifft_result[%d] = { %2.2f, %2.2f }\n",
            i, ifft_result[i][0] / SIZE, ifft_result[i][1] / SIZE );
}


fftw_destroy_plan( plan_forward );
fftw_destroy_plan( plan_backward );

fftw_free( data );
fftw_free( fft_result );
fftw_free( ifft_result );

is it possible? how?

Cœur
  • 37,241
  • 25
  • 195
  • 267
josef
  • 1,632
  • 1
  • 11
  • 16

1 Answers1

0

If the format is always the same then you could split the string by the known delimiter in this case you could get that column of data using something like:

NSArray *components = [line componentsSeparatedByString:@" "];
if (components.count > 3) {
  NSLog(@"%@", components[3]);
}
Paul.s
  • 38,494
  • 5
  • 70
  • 88
  • thank you for helping. where should i write the path of the file that i have (file.txt)? and its showing me an error for `[line componentsSeparatedByString:@" "];` > use of undeclared identifier "line"; did you mean "link"? – josef May 19 '14 at 23:22
  • For efficiently reading a file line by line check out this great answer http://stackoverflow.com/questions/3707427/how-to-read-data-from-nsfilehandle-line-by-line – Paul.s May 20 '14 at 19:38
  • thank you, i read it, even that it is for reading lines , i could complete my code from there. :) but i am getting now null please take a look on my new Question : [link](http://stackoverflow.com/questions/23766925/how-to-chose-an-array-from-a-given-file-txt-stringbyappendingpathcomponent-x) – josef May 20 '14 at 21:37