mborgerding / kissfft

a Fast Fourier Transform (FFT) library that tries to Keep it Simple, Stupid
Other
1.39k stars 278 forks source link

how to use the kiss_fft? #30

Closed ucasiggcas closed 4 years ago

ucasiggcas commented 4 years ago

Dear, thanks to the great project, but for a new one, It's a little difficult to test the kiss_fft,

so could you please give the main function ? I just want to use a forward transform, thx

ucasiggcas commented 4 years ago

emm, my input data is real, and want to use kiss_fftr.c any one could help me to write a test.c with main function ? and the output is the absolute of the fft , that is ,if my input size is 200, n_fft=256,the output size should be n_fft/2+1 ,and then get abs other n_fft is also needed. SOS Help me.

thanks a lot

ucasiggcas commented 4 years ago

and I modify the test_real.c, but the results are not right in VS2017

`#include "kiss_fftr.h"

include "_kiss_fft_guts.h"

include

//#include

include

include

include

define nfft 120

int main() {

int i;

kiss_fft_cpx cin[nfft];
kiss_fft_cpx cout[nfft];
kiss_fft_cpx sout[nfft];
kiss_fftr_cfg  kiss_fftr_state;

kiss_fft_scalar rin[nfft];
kiss_fft_scalar rout[nfft];

for (i=0;i<nfft;++i) {
    rin[i] = i;//rand_scalar();
    cin[i].r = rin[i];
    cin[i].i = 0;
}

kiss_fftr_state = kiss_fftr_alloc(nfft,0,0,0);
kiss_fftr(kiss_fftr_state,rin,sout);
for (i = 0; i < nfft; ++i) {
    printf("i=%d,sout real=%f,sout imag=%f\n", i,sout[i].r, sout[i].i);
}
free(kiss_fftr_state);

system("pause");
return 0;

}`

image image

that is the real input is 0~120 (120 not include) but in python3.6.8 x=np.arange(120) xft=np.fft.fft(x) xft array([7140.+0.00000000e+00j, -60.+2.29130756e+03j, -60.+1.14486820e+03j, -60.+7.62372284e+02j, -60.+5.70861867e+02j, -60.+4.55745247e+02j, -60.+3.78825091e+02j, -60.+3.23731030e+02j, -60.+2.82277807e+02j, -60.+2.49917986e+02j, -60.+2.23923048e+02j, -60.+2.02556605e+02j, -60.+1.84661012e+02j, -60.+1.69434773e+02j, -60.+1.56305344e+02j, -60.+1.44852814e+02j, -60.+1.34762206e+02j, -60.+1.25792616e+02j, -60.+1.17756630e+02j, -60.+1.10506253e+02j, -60.+1.03923048e+02j, -60.+9.79111012e+01j, -60.+9.23918978e+01j, -60.+8.73005417e+01j, -60.+8.25829152e+01j, -60.+7.81935224e+01j, -60.+7.40938294e+01j, -60.+7.02509740e+01j, -60.+6.66367509e+01j, -60.+6.32268075e+01j, -60.+6.00000000e+01j, -60.+5.69378740e+01j, -60.+5.40242427e+01j, -60.+5.12448411e+01j, -60.+4.85870420e+01j, -60.+4.60396193e+01j, -60.+4.35925517e+01j, -60.+4.12368575e+01j, -60.+3.89644556e+01j, -60.+3.67680473e+01j, -60.+3.46410162e+01j, -60.+3.25773420e+01j, -60.+3.05715270e+01j, -60.+2.86185320e+01j, -60.+2.67137211e+01j, -60.+2.48528137e+01j, -60.+2.30318421e+01j, -60.+2.12471144e+01j, -60.+1.94951818e+01j, -60.+1.77728097e+01j, -60.+1.60769515e+01j, -60.+1.44047255e+01j, -60.+1.27533937e+01j, -60.+1.11203427e+01j, -60.+9.50306642e+00j, -60.+7.89914986e+00j, -60.+6.30625412e+00j, -60.+4.72210241e+00j, -60.+3.14446676e+00j, -60.+1.57115529e+00j, -60.+7.10542736e-15j, -60.-1.57115529e+00j, -60.-3.14446676e+00j, -60.-4.72210241e+00j, -60.-6.30625412e+00j, -60.-7.89914986e+00j, -60.-9.50306642e+00j, -60.-1.11203427e+01j, -60.-1.27533937e+01j, -60.-1.44047255e+01j, -60.-1.60769515e+01j, -60.-1.77728097e+01j, -60.-1.94951818e+01j, -60.-2.12471144e+01j, -60.-2.30318421e+01j, -60.-2.48528137e+01j, -60.-2.67137211e+01j, -60.-2.86185320e+01j, -60.-3.05715270e+01j, -60.-3.25773420e+01j, -60.-3.46410162e+01j, -60.-3.67680473e+01j, -60.-3.89644556e+01j, -60.-4.12368575e+01j, -60.-4.35925517e+01j, -60.-4.60396193e+01j, -60.-4.85870420e+01j, -60.-5.12448411e+01j, -60.-5.40242427e+01j, -60.-5.69378740e+01j, -60.-6.00000000e+01j, -60.-6.32268075e+01j, -60.-6.66367509e+01j, -60.-7.02509740e+01j, -60.-7.40938294e+01j, -60.-7.81935224e+01j, -60.-8.25829152e+01j, -60.-8.73005417e+01j, -60.-9.23918978e+01j, -60.-9.79111012e+01j, -60.-1.03923048e+02j, -60.-1.10506253e+02j, -60.-1.17756630e+02j, -60.-1.25792616e+02j, -60.-1.34762206e+02j, -60.-1.44852814e+02j, -60.-1.56305344e+02j, -60.-1.69434773e+02j, -60.-1.84661012e+02j, -60.-2.02556605e+02j, -60.-2.23923048e+02j, -60.-2.49917986e+02j, -60.-2.82277807e+02j, -60.-3.23731030e+02j, -60.-3.78825091e+02j, -60.-4.55745247e+02j, -60.-5.70861867e+02j, -60.-7.62372284e+02j, -60.-1.14486820e+03j, -60.-2.29130756e+03j])

so how to deal with it ??

mborgerding commented 4 years ago

This is not the best forum for asking "my code doesn't work" questions. I'd suggest stackoverflow.com