I am working on an app. that its measuring the motion of a device. (xyz direction )
and now i must use fftw to filter the data.
i don't know how to call the data through fftw. hier below is a part of my code trying to execute the X-data ( i am working on each direction separate so X, Y, and then Z)
// FFTW for X-data
int SIZE = 97;
fftw_complex *dataX, *fft_resultX;
fftw_plan plan_X;
int i ;
dataX = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * SIZE);
fft_resultX = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * SIZE);
plan_X = fftw_plan_dft_1d(SIZE, dataX, fft_resultX,
FFTW_FORWARD, FFTW_ESTIMATE); // FFTW_MEASURE
for( i = 0 ; i < SIZE ; i++ ) {
dataX[i][0] = 1.0; // real
dataX[i][1] = 0.0; // complex
for( i = 0 ; i < SIZE ; i++ ) {
fprintf( stdout, "dataX[%d] = { %2.2f, %2.2f }\n",
i, dataX[i][0], dataX[i][1] );
}
fftw_execute( plan_X);
for( i = 0 ; i < SIZE ; i++ ) {
fprintf( stdout, "fft_resultX[%d] = { %2.2f, %2.2f }\n",
i, fft_resultX[i][0], fft_resultX[i][1] );
}
and hier is the userAcceleration:
[[weakSelf.graphViews objectAtIndex:kDeviceMotionGraphTypeUserAcceleration] addX:deviceMotion.userAcceleration.x y:deviceMotion.userAcceleration.y z:deviceMotion.userAcceleration.z];
for example, when i am writing :
dataX= deviceMotion.userAcceleration.x;
i am getting this error:
Assigning to 'fftw_complex *' (aka '_Complex double *') from incompatible type 'double'
any idea how to make fftw work on it ?
thanks for every try
You can't simply convert real data to a real imaginary pair. Each complex number is made up of 2 doubles.
You need to store all your acceleration data into a larger array (256 entries for example) where the x value is assigned to the real part of the complex number and 0 is assigned to the imaginary part.