mirror of
https://github.com/mborgerding/kissfft.git
synced 2025-07-18 21:14:24 -04:00
took utility/test code out of main source file and moved down to sample_code
This commit is contained in:
59
test/Makefile
Normal file
59
test/Makefile
Normal file
@ -0,0 +1,59 @@
|
||||
NFFT=1024
|
||||
ALLUTILS=kfft kifft kffts kiffts kfftd kifftd s2f s2d sigdiff sigdiffs sigdiffd scale scales scaled
|
||||
NUMFFTS=1000
|
||||
UTILSRC=../kiss_fft.c fftutil.c
|
||||
|
||||
all: $(ALLUTILS)
|
||||
|
||||
kfft: $(UTILSRC)
|
||||
gcc -Wall -O3 -o $@ -lm -I.. -DNFFT=$(NFFT) $(UTILSRC)
|
||||
kifft: ../kiss_fft.h ../kiss_fft.c fftutil.c
|
||||
gcc -Wall -O3 -o $@ -lm -I.. -DNFFT=$(NFFT) -DINVERSE_FFT $(UTILSRC)
|
||||
kffts: $(UTILSRC)
|
||||
gcc -Wall -O3 -o $@ -lm -I.. -DNFFT=$(NFFT) -DFIXED_POINT $(UTILSRC)
|
||||
kiffts: $(UTILSRC)
|
||||
gcc -Wall -O3 -o $@ -lm -I.. -DNFFT=$(NFFT) -DFIXED_POINT -DINVERSE_FFT $(UTILSRC)
|
||||
kfftd: $(UTILSRC)
|
||||
gcc -Wall -O3 -o $@ -lm -I.. -DNFFT=$(NFFT) -Dkiss_fft_scalar=double $(UTILSRC)
|
||||
kifftd: ../kiss_fft.h ../kiss_fft.c fftutil.c
|
||||
gcc -Wall -O3 -o $@ -lm -I.. -DNFFT=$(NFFT) -Dkiss_fft_scalar=double -DINVERSE_FFT $(UTILSRC)
|
||||
|
||||
s2f: typeconvert.c
|
||||
gcc -Wall -O3 -o $@ $^ -DTYPE1=short -DTYPE2=float
|
||||
s2d: typeconvert.c
|
||||
gcc -Wall -O3 -o $@ $^ -DTYPE1=short -DTYPE2=double
|
||||
|
||||
scale: typeconvert.c
|
||||
gcc -Wall -O3 -o $@ $^ -DTYPE1=float -DTYPE2=float
|
||||
scales: typeconvert.c
|
||||
gcc -Wall -O3 -o $@ $^ -DTYPE1=short -DTYPE2=short
|
||||
scaled: typeconvert.c
|
||||
gcc -Wall -O3 -o $@ $^ -DTYPE1=double -DTYPE2=double
|
||||
|
||||
sigdiff: sigdiff.c
|
||||
gcc -Wall -O3 -o $@ $^ -DTYPE=float -lm
|
||||
sigdiffs: sigdiff.c
|
||||
gcc -Wall -O3 -o $@ $^ -DTYPE=short -lm
|
||||
sigdiffd: sigdiff.c
|
||||
gcc -Wall -O3 -o $@ $^ -DTYPE=double -lm
|
||||
|
||||
randshort.dat:
|
||||
dd if=/dev/urandom bs=$$((4 * $(NFFT) )) count=$(NUMFFTS) of=randshort.dat
|
||||
randfloat.dat: randshort.dat s2f
|
||||
./s2f < $< > $
|
||||
randdouble.dat: randshort.dat s2d
|
||||
./s2d < $< > $@
|
||||
|
||||
data: randshort.dat randfloat.dat randdouble.dat
|
||||
|
||||
test: all data
|
||||
@echo "####################Testing double fft|ifft"
|
||||
@./kfftd < randdouble.dat | ./kifftd | ./scaled -d 1024 | ./sigdiffd randdouble.dat -
|
||||
@echo "####################Testing float fft|ifft"
|
||||
@./kfft < randfloat.dat | ./kifft | ./scale -d 1024 | ./sigdiff randfloat.dat -
|
||||
@echo "####################Testing short fft|ifft"
|
||||
@./kffts < randshort.dat | ./kiffts | ./scales -m 1024 | ./sigdiffs randshort.dat -
|
||||
|
||||
clean:
|
||||
rm -f $(ALLUTILS) *.dat *~
|
||||
|
80
test/sigdiff.c
Normal file
80
test/sigdiff.c
Normal file
@ -0,0 +1,80 @@
|
||||
/*
|
||||
Copyright (c) 2003, Mark Borgerding
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
* Neither the author nor the names of any contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#ifndef BUFSIZE
|
||||
# define BUFSIZE 1024
|
||||
#endif
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
FILE * f1=stdin;
|
||||
FILE * f2=stdin;
|
||||
|
||||
int i,n;
|
||||
TYPE buf1[BUFSIZE];
|
||||
TYPE buf2[BUFSIZE];
|
||||
|
||||
double sigpower=0;
|
||||
double noisepower=0;
|
||||
double snrdb=0;
|
||||
double scale=0;
|
||||
long ntotal=0;
|
||||
|
||||
if (argc>1 && strcmp( argv[1] ,"-") != 0 ) {
|
||||
f1 = fopen(argv[1],"rb");
|
||||
}
|
||||
if (argc>2 && strcmp( argv[2] ,"-") != 0 ) {
|
||||
f2 = fopen(argv[2],"rb");
|
||||
}
|
||||
|
||||
// TODO LEFT OFF HERE
|
||||
while ( ( n = fread( buf1 , sizeof(TYPE) , BUFSIZE , f1 ) ) > 0 ) {
|
||||
if ( fread( buf2 , sizeof(TYPE) , BUFSIZE , f2 ) != n ) {
|
||||
fprintf(stderr,"premature end of file 2\n");
|
||||
exit(1);
|
||||
}
|
||||
for (i=0;i<n;++i) {
|
||||
double s=buf1[i];
|
||||
double n = s - buf2[i];
|
||||
sigpower += s*s;
|
||||
noisepower += n*n;
|
||||
if (s!=0) {
|
||||
++ntotal;
|
||||
scale += buf2[i] / s;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( fread( buf2 , sizeof(TYPE) , BUFSIZE , f2 ) > 0 ) {
|
||||
fprintf(stderr,"premature end of file 1\n");
|
||||
exit(1);
|
||||
}
|
||||
scale /= ntotal;
|
||||
|
||||
if (noisepower>0)
|
||||
snrdb = 10*log10( sigpower / noisepower );
|
||||
else
|
||||
snrdb = 200;
|
||||
|
||||
printf("snr = %.2f dB\n",snrdb);
|
||||
printf("average output/input = %.5e\n",scale);
|
||||
|
||||
return 0;
|
||||
}
|
46
test/typeconvert.c
Normal file
46
test/typeconvert.c
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
Copyright (c) 2003, Mark Borgerding
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
* Neither the author nor the names of any contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#define BUFSIZE 1024
|
||||
int main(int argc, char ** argv )
|
||||
{
|
||||
int i,n;
|
||||
TYPE1 buf1[BUFSIZE];
|
||||
TYPE2 buf2[BUFSIZE];
|
||||
double mult=1.0;
|
||||
|
||||
for (i=1;i<argc;++i){
|
||||
if (strcmp("-m",argv[i])==0){
|
||||
mult *= atof(argv[i+1] );
|
||||
++i;
|
||||
}else if (strcmp("-d",argv[i])==0){
|
||||
mult /= atof(argv[i+1] );
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
while ( ( n = fread( buf1 , sizeof(TYPE1) , BUFSIZE , stdin ) ) > 0 ) {
|
||||
for (i=0;i<n;++i)
|
||||
buf2[i] = (TYPE1)(mult * buf1[i]);
|
||||
fwrite( buf2 , sizeof(TYPE2) , n , stdout );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user