added stride to fft input -- should simplify multi-dimensional FFTs

This commit is contained in:
Mark Borgerding 2003-12-29 18:50:13 +00:00
parent 604e238834
commit 4552a14801
8 changed files with 61 additions and 13 deletions

View File

@ -88,6 +88,7 @@ void kf_work(
kiss_fft_cpx * Fout,
const kiss_fft_cpx * f,
int fstride,
int in_skip,
int * factors,
const kiss_fft_state * st
);

View File

@ -244,6 +244,7 @@ void kf_work(
kiss_fft_cpx * Fout,
const kiss_fft_cpx * f,
int fstride,
int in_stride,
int * factors,
const kiss_fft_state * st
)
@ -256,8 +257,8 @@ void kf_work(
if (m==1)
Fout[q] = *f;
else
kf_work( Fout + m*q, f, fstride*p,factors,st);
f += fstride;
kf_work( Fout + m*q, f, fstride*p, in_stride, factors,st);
f += fstride*in_stride;
}
switch (p) {
@ -341,7 +342,7 @@ void * kiss_fft_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem )
return st;
}
void kiss_fft(const void * cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout)
void kiss_fft_stride(const void * cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout,int in_stride)
{
const kiss_fft_state * st = cfg;
if (st->nfft < 0) {
@ -350,9 +351,43 @@ void kiss_fft(const void * cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout)
}
if (fin == fout) {
memcpy(st->tmpbuf,fin,sizeof(kiss_fft_cpx)*st->nfft);
fin = st->tmpbuf;
kf_work(st->tmpbuf,fin,1,in_stride, st->factors,st);
memcpy(fout,st->tmpbuf,sizeof(kiss_fft_cpx)*st->nfft);
}else{
kf_work( fout, fin, 1,in_stride, st->factors,st );
}
}
void kiss_fft(const void * cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout)
{
kiss_fft_stride(cfg,fin,fout,1);
}
void test_stride()
{
#define SKIP_FACTOR 7
#define FFT_SIZE 1800
void *cfg;
kiss_fft_cpx buf1in[FFT_SIZE],buf1out[FFT_SIZE];
kiss_fft_cpx buf2in[SKIP_FACTOR*FFT_SIZE],buf2out[FFT_SIZE];
int i;
memset(buf2in,0,sizeof(buf2in));
for (i=0;i<FFT_SIZE;++i) {
buf1in[i].r = rand();
buf1in[i].i = rand();
buf2in[SKIP_FACTOR*i] = buf1in[i];
}
cfg= kiss_fft_alloc(FFT_SIZE,0,0,0);
kiss_fft(cfg,buf1in,buf1out);
kiss_fft_stride(cfg,buf2in,buf2out,SKIP_FACTOR);
if ( 0==memcmp(buf1out,buf2out,sizeof(buf1out) ) )
printf("kiss_fft_stride is working for stride = %d\n",SKIP_FACTOR);
else{
printf("kiss_fft_stride not working for stride =%d\n",SKIP_FACTOR);
for (i=0;i<FFT_SIZE;++i) {
fprintf(stderr,"good[%d]=",i);pcpx(buf1out+i);
fprintf(stderr,"bad [%d]=",i);pcpx(buf2out+i);
}
}
kf_work( fout, fin, 1, st->factors,st );
}

View File

@ -62,6 +62,7 @@ void* kiss_fft_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem);
* */
void kiss_fft(const void * cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout);
void kiss_fft_stride(const void * cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout,int fin_stride);
/* If kiss_fft_alloc allocated a buffer, it is one contiguous
buffer and can be simply free()d when no longer needed*/

View File

@ -34,9 +34,10 @@ endif
all: $(BENCHKISS) $(SELFTEST) $(BENCHFFTW) $(TESTREAL) $(FFTUTIL) $(TESTKFC)
#CFLAGS=-Wall -O3 -ansi -pedantic -march=pentiumpro -ffast-math -fomit-frame-pointer
CFLAGS=-Wall -O3 -pedantic -march=pentiumpro -ffast-math -fomit-frame-pointer
#-DUSE_SKIP
# If the above flags do not work, try the following
CFLAGS=-Wall -O3
#CFLAGS=-Wall -O3
$(FFTUTIL): ../kiss_fft.c fftutil.c kiss_fft2d.c kiss_fftr.c
$(CC) -o $@ $(CFLAGS) -I.. $(TYPEFLAGS) -lm $+

View File

@ -1,6 +1,5 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/times.h>
#include <unistd.h>
#include "kiss_fft.h"

View File

@ -26,6 +26,8 @@ double snr_compare( kiss_fft_cpx * test_vec_out,kiss_fft_cpx * testbuf, int n)
return snr;
}
void test_stride();
int main() { int exit_code=0;
#define NFFT 10
@ -130,7 +132,7 @@ int main() { int exit_code=0;
}
#undef NFFT
test_stride();
return exit_code;
}

View File

@ -34,9 +34,10 @@ endif
all: $(BENCHKISS) $(SELFTEST) $(BENCHFFTW) $(TESTREAL) $(FFTUTIL) $(TESTKFC)
#CFLAGS=-Wall -O3 -ansi -pedantic -march=pentiumpro -ffast-math -fomit-frame-pointer
CFLAGS=-Wall -O3 -pedantic -march=pentiumpro -ffast-math -fomit-frame-pointer
#-DUSE_SKIP
# If the above flags do not work, try the following
CFLAGS=-Wall -O3
#CFLAGS=-Wall -O3
$(FFTUTIL): ../kiss_fft.c fftutil.c kiss_fft2d.c kiss_fftr.c
$(CC) -o $@ $(CFLAGS) -I.. $(TYPEFLAGS) -lm $+

View File

@ -103,6 +103,14 @@ int main(int argc,char ** argv)
case 'r':nrows = atoi(optarg);break;
case 'i':isinverse=1;break;
case 'R':isreal=1;break;
case '?':
fprintf(stderr,"usage options:\n"
"\t-n NFFT: fft size\n"
"\t-r nrows: # rows (implies 2d FFT)\n"
"\t-i : inverse\n"
"\t-R : real input samples, not complex\n");
exit (1);
default:fprintf(stderr,"bad %c\n",c);break;
}
}