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