c@174: #include c@174: #include c@174: #include c@174: #include "kiss_fft.h" c@174: #include "kiss_fftr.h" c@174: #include c@174: c@174: c@174: static c@174: double two_tone_test( int nfft, int bin1,int bin2) c@174: { c@174: kiss_fftr_cfg cfg = NULL; c@174: kiss_fft_cpx *kout = NULL; c@174: kiss_fft_scalar *tbuf = NULL; c@174: c@174: int i; c@174: double f1 = bin1*2*M_PI/nfft; c@174: double f2 = bin2*2*M_PI/nfft; c@174: double sigpow=0; c@174: double noisepow=0; c@174: #if FIXED_POINT==32 c@174: long maxrange = LONG_MAX; c@174: #else c@174: long maxrange = SHRT_MAX;/* works fine for float too*/ c@174: #endif c@174: c@174: cfg = kiss_fftr_alloc(nfft , 0, NULL, NULL); c@174: tbuf = KISS_FFT_MALLOC(nfft * sizeof(kiss_fft_scalar)); c@174: kout = KISS_FFT_MALLOC(nfft * sizeof(kiss_fft_cpx)); c@174: c@174: /* generate a signal with two tones*/ c@174: for (i = 0; i < nfft; i++) { c@174: #ifdef USE_SIMD c@174: tbuf[i] = _mm_set1_ps( (maxrange>>1)*cos(f1*i) c@174: + (maxrange>>1)*cos(f2*i) ); c@174: #else c@174: tbuf[i] = (maxrange>>1)*cos(f1*i) c@174: + (maxrange>>1)*cos(f2*i); c@174: #endif c@174: } c@174: c@174: kiss_fftr(cfg, tbuf, kout); c@174: c@174: for (i=0;i < (nfft/2+1);++i) { c@174: #ifdef USE_SIMD c@174: double tmpr = (double)*(float*)&kout[i].r / (double)maxrange; c@174: double tmpi = (double)*(float*)&kout[i].i / (double)maxrange; c@174: #else c@174: double tmpr = (double)kout[i].r / (double)maxrange; c@174: double tmpi = (double)kout[i].i / (double)maxrange; c@174: #endif c@174: double mag2 = tmpr*tmpr + tmpi*tmpi; c@174: if (i!=0 && i!= nfft/2) c@174: mag2 *= 2; /* all bins except DC and Nyquist have symmetric counterparts implied*/ c@174: c@174: /* if there is power in one of the expected bins, it is signal, otherwise noise*/ c@174: if ( i!=bin1 && i != bin2 ) c@174: noisepow += mag2; c@174: else c@174: sigpow += mag2; c@174: } c@174: kiss_fft_cleanup(); c@174: /*printf("TEST %d,%d,%d noise @ %fdB\n",nfft,bin1,bin2,10*log10(noisepow/sigpow +1e-30) );*/ c@174: return 10*log10(sigpow/(noisepow+1e-50) ); c@174: } c@174: c@174: int main(int argc,char ** argv) c@174: { c@174: int nfft = 4*2*2*3*5; c@174: if (argc>1) nfft = atoi(argv[1]); c@174: c@174: int i,j; c@174: double minsnr = 500; c@174: double maxsnr = -500; c@174: double snr; c@174: for (i=0;i>4)+1) { c@174: for (j=i;j>4)+7) { c@174: snr = two_tone_test(nfft,i,j); c@174: if (snrmaxsnr) { c@174: maxsnr=snr; c@174: } c@174: } c@174: } c@174: snr = two_tone_test(nfft,nfft/2,nfft/2); c@174: if (snrmaxsnr) maxsnr=snr; c@174: c@174: printf("TwoToneTest: snr ranges from %ddB to %ddB\n",(int)minsnr,(int)maxsnr); c@174: printf("sizeof(kiss_fft_scalar) = %d\n",(int)sizeof(kiss_fft_scalar) ); c@174: return 0; c@174: }