Hi, I got this function of TI's site for the c6711 - void digitrev(int *x, unsigned int *index, int n, int radix) { int i,j,a,b; int xi, xj; int nbits, nbot, ntop, ndiff, n2, astep, radN; /* short leftzeros; */ int *xs = (int *) x; nbits = 0; i = n; while (i > 1) { i = i >> 1; nbits++; } radN = 0; i = radix; while (i > 1) { i = i >> 1; radN++; } nbot = nbits / (2*radN); nbot = nbot * radN; ndiff = nbits % (2*radN); ntop = nbot + ndiff; n2 = 1 << ntop; astep = 1 << ndiff; for (a = 0, i = 0; a < n2; a += astep) { for (b = 0; b < n2; b++, i++) { j = (index[b] << nbot) + index[a]; if (i < j) { xi = x[i]; xj = x[j]; x[i] = xj; x[j] = xi; } } } } I'm looking for optimized code for swapping complex values from the function DSPF_sp_cfftr4_dif, not plain old ints as above. What I'm having to do at the moment is - DSPF_sp_cfftr4_dif(FFTBuffer, PSD_W, FFT_SIZE); digitrev_index(PSD_Indeces, FFT_SIZE, 4); for (i = 0,j=0; i < FFT_SIZE; i++,j+=2) { FFTBuffer2[j] = FFTBuffer[PSD_Indeces[i]*2]; FFTBuffer2[j+1] = FFTBuffer[PSD_Indeces[i]*2+1]; } CalcFFTMag(FFTBuffer2,FFT_SIZE,FFT_mag); My code for digitrev_index is - void digitrev_index(unsigned int *index, int n2, int radix) { int i,j,k; index[0] = 0; for ( i = 1, j = n2/radix + 1; i < n2 - 1; i++) { index[i] = j - 1; for (k = n2/radix; k*(radix-1) < j; k /= radix) j -= k*(radix-1); j += k; } index[n2 - 1] = n2 - 1; } Maybe theres an optimized version of this also? Thanks for your help, Barry.
c6x: digitrev for complex values
Started by ●September 23, 2003
Reply by ●September 24, 20032003-09-24
Hi, I'm sure some of you guys have have used DSPF_sp_cfftr4_dif before. What code did you use to sort out the output array? Thanks, Barry. bg_ie@yahoo.com (Barry) wrote in message news:<731cea69.0309231158.1b40e19a@posting.google.com>...> Hi, > > I got this function of TI's site for the c6711 - > > void digitrev(int *x, unsigned int *index, int n, int radix) > { > int i,j,a,b; > int xi, xj; > int nbits, nbot, ntop, ndiff, n2, astep, radN; > > /* short leftzeros; */ > int *xs = (int *) x; > > nbits = 0; > i = n; > while (i > 1) > { > i = i >> 1; > nbits++; > } > > radN = 0; > i = radix; > while (i > 1) > { > i = i >> 1; > radN++; > } > nbot = nbits / (2*radN); > nbot = nbot * radN; > ndiff = nbits % (2*radN); > ntop = nbot + ndiff; > n2 = 1 << ntop; > astep = 1 << ndiff; > for (a = 0, i = 0; a < n2; a += astep) > { > for (b = 0; b < n2; b++, i++) > { > j = (index[b] << nbot) + index[a]; > if (i < j) > { > xi = x[i]; > xj = x[j]; > x[i] = xj; > x[j] = xi; > } > } > } > } > > I'm looking for optimized code for swapping complex values from the > function DSPF_sp_cfftr4_dif, not plain old ints as above. What I'm > having to do at the moment is - > > DSPF_sp_cfftr4_dif(FFTBuffer, PSD_W, FFT_SIZE); > > digitrev_index(PSD_Indeces, FFT_SIZE, 4); > > for (i = 0,j=0; i < FFT_SIZE; i++,j+=2) > { > FFTBuffer2[j] = FFTBuffer[PSD_Indeces[i]*2]; > FFTBuffer2[j+1] = FFTBuffer[PSD_Indeces[i]*2+1]; > } > > CalcFFTMag(FFTBuffer2,FFT_SIZE,FFT_mag); > > My code for digitrev_index is - > > void digitrev_index(unsigned int *index, int n2, int radix) > { > int i,j,k; > index[0] = 0; > for ( i = 1, j = n2/radix + 1; i < n2 - 1; i++) > { > index[i] = j - 1; > for (k = n2/radix; k*(radix-1) < j; k /= radix) > j -= k*(radix-1); > j += k; > } > index[n2 - 1] = n2 - 1; > } > > Maybe theres an optimized version of this also? > > Thanks for your help, > > Barry.