signal processing - Fast Fourier Transform in Objective-C doesn't work fine -


i have method in objective-c receives array of doubles , uses fast fourier transform, exit of fft doesn't match want.

can me, don't know i'm doing wrong?

this method fftlength 4096:

-(double(*)) dofft:(double(*))data{     double (*fft) = malloc((fftlength * 2) * sizeof(double));      fftsetupd fft_weights = vdsp_create_fftsetupd((log2((double)(fftlength))), kfftradix2);      dspdoublesplitcomplex fftdata;     //fftdata.imagp = fftmagnitudes;      fftdata.imagp = (double*)malloc(fftlength * sizeof(double));     fftdata.realp = (double*)malloc(fftlength * sizeof(double));      (int i=0; i< fftlength; i++) {         fftdata.realp[i] = (double)data[i];         fftdata.imagp[i] = (double)0.0;      }      vdsp_fft_zipd(fft_weights, &fftdata, 1, log2((double)(fftlength)), fft_forward);      for(int = 0;i<fftlength * 2;i++){         fft[i] = fftdata.realp[i];         fft[i+1] = fftdata.imagp[i];     }      return fft; } 

and part of input data:

[0.0,2.092731423889438e-4, 8.858534436404497e-4,0.0013714427743574675,0.0012678166431137061,-9.650789019044481e-4,-0.002852548808273958,-0.005176802258252122,-0.007281581949909022,-0.00575977878132905,…] 

and result should be:

[21478.183372382526,0.0,-10190.412374839314,…] 

but i'm not getting this.

this loop wrong:

for(int = 0;i<fftlength * 2;i++){     fft[i] = fftdata.realp[i];     fft[i+1] = fftdata.imagp[i]; } 

assuming want interleaved real/complex output data should be:

for(int = 0; < fftlength; i++) {     fft[i * 2] = fftdata.realp[i];     fft[i * 2 + 1] = fftdata.imagp[i]; } 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -