DSPRelated.com
Forums

Problem Using Kiss FFT

Started by Javier Pajuelo July 20, 2014
On Sunday, July 20, 2014 6:06:34 PM UTC+12, Javier Pajuelo wrote:
> I get different results using Kiss FFT and Octave/Matlab fft. > > > > Here's the input/output of my code: > > ========================================================= > > xtmp[2][4] > > 0 1 2 3 > > 0 (0.2348,-0.5121) (-0.2745,0.0647)(-0.06092,-0.4704) (-0.04771,0.1112) > > 1 (-0.14,-0.04515)(-0.5469,0.4785) (-0.3687,-0.2009)(-0.04413,0.1298) > > > > Input: Output: > > 0.234797 -0.512116 -0.1706950.026731 > > -0.274483 0.064698 0.128480-0.021765 > > -0.060917 -0.470399 0.0131070.008202 > > -0.047714 0.111247 0.012300-0.097780 > > -0.140031 -0.045153 0.0576210.186990 > > -0.546944 0.478488 0.0032580.104076 > > -0.368746 -0.200878 0.088650-0.140648 > > -0.044125 0.129769 -0.0153230.051592 > > > > > > x_tmp from ifft: > > > > ========================================================= > > x_tmp[2][4] > > 0 1 2 3 > > 0 (-0.1707,0.02673)(0.1285,-0.02177) (0.01311,0.008202)(0.0123,-0.09778) > > 1 (0.05762,0.187) (0.003258,0.1041)(0.08865,-0.1406)(-0.01532,0.05159) > > > > > > > > ----------------------------------------------------------------------------- > > And, this is the correct output from Matlab/Octave: > > > > x_tmp = > > > > 0.2348 - 0.5121i -0.2745 + 0.0647i -0.0609 - 0.4704i -0.0477 + 0.1112i > > -0.1400 - 0.0452i -0.5469 + 0.4785i -0.3687 - 0.2009i -0.0441 + 0.1298i > > > > > > x_tmp_after_ifft = > > > > 0.0474 - 0.2786i -0.4107 + 0.2716i -0.2148 - 0.3356i -0.0459 + 0.1205i > > 0.1874 - 0.2335i 0.1362 - 0.2069i 0.1539 - 0.1348i -0.0018 - 0.0093i > > > > ---------------------------------------------------------------------------- > > Here's my code calling fft from Kiss: > > > > <code> > > int i; > > int isinverse = 1; > > > > // TODO try row wise storage > > int rows = x_tmp.size(); int cols=x_tmp[0].size(); > > double array_r[rows*cols];int idx=0; > > double array_i[rows*cols]; > > double buf[rows*cols]; int size=rows*cols; > > double buf_i[rows*cols]; > > > > > > for(int i=0; i<rows;i++) > > for(int j=0;j<cols;j++) > > { > > array_r[idx]=x_tmp[i][j].real(); > > array_i[idx]=x_tmp[i][j].imag(); > > idx++; > > } > > > > kiss_fft_cpx out_cpx[size],out[size],*cpx_buf; > > > > kiss_fftr_cfg fft = kiss_fftr_alloc(size*2 ,0 ,0,0); > > kiss_fftr_cfg ifft = kiss_fftr_alloc(size*2,isinverse,0,0); > > > > cpx_buf = copycpx(array_r, array_i, size); > > > > // kiss_fftr(fft,(kiss_fft_scalar*)cpx_buf, out_cpx); > > > > // out_cpx has our input > > //kiss_fftri(ifft,out_cpx,(kiss_fft_scalar*)out ); > > kiss_fftri(ifft,cpx_buf,(kiss_fft_scalar*)out ); > > > > printf("Input:\t\tOutput:\n"); > > for(i=0;i<size;i++) > > { > > buf[i] = (out[i].r)/(size*2); > > buf_i[i]=(out[i].i)/(size*2); > > > > printf("%f%f\t\t%f%f\n",array_r[i] > > , array_i[i],buf[i], buf_i[i]); > > } > > > > kiss_fft_cleanup(); > > free(fft); > > free(ifft); > > > > </code> > > ------------------------------------------------------ > > > > Sorry about the formatting. > > If Mark Borgerding is around, that would be great. > > > > Thank you very much. I don't know where is my mistake.
How fascinating, primitive text-based sequential code still being used in this era. Humans appear not to have developed data-flow language yet.