*** empty log message ***

This commit is contained in:
Mark Borgerding 2005-05-11 03:02:57 +00:00
parent ed1a5f0cfc
commit 89e3fe2466

View File

@ -1,4 +1,3 @@
#include <complex.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
@ -9,97 +8,74 @@
#define pcpx(c)\ #define pcpx(c)\
fprintf(stderr,"%g + %gi\n",(double)((c)->r),(double)((c)->i) ) fprintf(stderr,"%g + %gi\n",(double)((c)->r),(double)((c)->i) )
void fe_fft_test( int N, int bin1,int bin2) static
double two_tone_test( int nfft, int bin1,int bin2)
{ {
// static kiss_fft_cfg cfg = NULL; kiss_fftr_cfg cfg = NULL;
static kiss_fftr_cfg cfg = NULL; kiss_fft_cpx *kout = NULL;
static int lastN = 0; kiss_fft_scalar *tbuf = NULL;
// kiss_fft_cpx *kin = NULL;
static kiss_fft_cpx *kout = NULL;
static kiss_fft_scalar *kin_r = NULL;
static int halfN = 0;
int flipN;
int i; int i;
double f1 = (bin1*2.0/N)*M_PI; double f1 = bin1*2*M_PI/nfft;
double f2 = (bin2*2.0/N)*M_PI; double f2 = bin2*2*M_PI/nfft;
double sigpow=0; double sigpow=0;
double noisepow=0; double noisepow=0;
if (lastN != N) { cfg = kiss_fftr_alloc(nfft , 0, NULL, NULL);
// Free previous structures, if allocated. tbuf = malloc(nfft * sizeof(kiss_fft_scalar));
if (cfg) kout = malloc(nfft * sizeof(kiss_fft_cpx));
free(cfg); //assert(bin1<=nfft/2);
if (kin_r) //assert(bin2<=nfft/2);
free(kin_r);
if (kout)
free(kout);
halfN = N / 2;
// Allocate the KISS FFT configuration structure.
// Although the memory for these structures will be freed
// when the DLL unloads, to be squeaky clean it should be
// freed explicitly.
// cfg = kiss_fft_alloc( N , 0, NULL, NULL);
cfg = kiss_fftr_alloc(N , 0, NULL, NULL);
// kin = malloc(N * sizeof(kiss_fft_cpx));
// kin_r = malloc(N * sizeof(kiss_fft_cpx));
kin_r = malloc(N * sizeof(kiss_fft_scalar));
kout = malloc(N * sizeof(kiss_fft_cpx));
lastN = N;
}
#if FIXED_POINT==32 #if FIXED_POINT==32
long maxrange = LONG_MAX; long maxrange = LONG_MAX;
#else #else
long maxrange = SHRT_MAX; long maxrange = SHRT_MAX;// works fine for float too
#endif #endif
// Convert the floating point "in" array to fixed point. // generate a signal with two tones
for (i = 0; i < N; i++) for (i = 0; i < nfft; i++) {
{ tbuf[i] = (maxrange>>1)*cos(f1*i)
kin_r[i] = (maxrange>>1)*cos(f1*i)
+ (maxrange>>1)*cos(f2*i); + (maxrange>>1)*cos(f2*i);
} }
// Make the kiss FFT call. kiss_fftr(cfg, tbuf, kout);
kiss_fftr(cfg, kin_r, kout);
sigpow = 0; for (i=0;i < (nfft/2+1);++i) {
//printf("[");
for (i=0;i < (N/2+1);++i) {
double tmpr = (double)kout[i].r / (double)maxrange; double tmpr = (double)kout[i].r / (double)maxrange;
double tmpi = (double)kout[i].i / (double)maxrange; double tmpi = (double)kout[i].i / (double)maxrange;
double mag2 = tmpr*tmpr + tmpi*tmpi; double mag2 = tmpr*tmpr + tmpi*tmpi;
if (i!=0 && i!= N/2) if (i!=0 && i!= nfft/2)
mag2 *= 2; // all bins except DC and Nyquist have symmetric counterparts implied mag2 *= 2; // all bins except DC and Nyquist have symmetric counterparts implied
sigpow += mag2;
// subtract out the expected result, anything left is noise // if there is power in one of the expected bins, it is signal, otherwise noise
if ( i!=bin1 && i != bin2 ) if ( i!=bin1 && i != bin2 )
noisepow += mag2; noisepow += mag2;
//printf("%d%+di,",(int)kout[i].r,(int)kout[i].i); else
sigpow += mag2;
} }
//printf("]\n"); //printf("TEST %d,%d,%d noise @ %fdB\n",nfft,bin1,bin2,10*log10(noisepow/sigpow +1e-30) );
printf("TEST %d,%d,%d noise @ %fdB\n",N,bin1,bin2,10*log10(noisepow/sigpow +1e-20) ); return 10*log10(sigpow/(noisepow+1e-50) );
return(0);
} }
int main(int argc,char ** argv) int main(int argc,char ** argv)
{ {
int nfft = 16; int nfft = 4*2*2*3*5;
int i,j; int i,j;
double minsnr = 500;
double maxsnr = -500;
double snr;
for (i=0;i<nfft/2;++i) { for (i=0;i<nfft/2;++i) {
for (j=i;j<nfft/2;++j) { for (j=i;j<nfft/2;j+=7) {
fe_fft_test(nfft,i,j); snr = two_tone_test(nfft,i,j);
if (snr<minsnr) minsnr=snr;
if (snr>maxsnr) maxsnr=snr;
} }
} }
printf("sizeof(kiss_fft_scalar) = %d\n",sizeof(kiss_fft_scalar) ); snr = two_tone_test(nfft,nfft/2,nfft/2);
if (snr<minsnr) minsnr=snr;
if (snr>maxsnr) maxsnr=snr;
printf("TwoToneTest: snr ranges from %ddB to %ddB\n",(int)minsnr,(int)maxsnr);
printf("sizeof(kiss_fft_scalar) = %d\n",sizeof(kiss_fft_scalar) );
return 0; return 0;
} }