2

I am trying to use KissFFT on BeagleBone Black, running Debian 7.5 with 3.8 kernel. The program gets compiled yet when I try to run it, It shows error

Real FFT optimization must be even

.

The same program run properly on Ubuntu laptop. I also tried various fft window length but error remains the same. Can anyone point out where I am going wrong? Herewith attaching the code and on gist with highlighting .

#include<stdio.h>
#include<math.h>
#include<string.h>
#include"kiss_fft.h"
#include "tools/kiss_fftr.h"
#include<complex.h>

int main()

{

    float s[960], k;                  //s = sine, data array
    float t[960]= {0};                //t = time data array
    int i, size = 960, fft_len=16384;
    float buff[fft_len];


    bzero(&buff, sizeof(buff));       // write zeros in whole buffer

    for (i = 0;i< fft_len;i++){
      if(buff[i] != 0){
          printf("Not zero");
          break;
        }
    }

    k = 2*M_PI/128;

  // Creating a 128 point/cycle discreet input 
    for (i = 0; i< 128; i++){
        t[i]= i*k;
        s[i] = sin(t[i]*50);
    }

// taking 7 cycles of input as 960 point window
  for (i = 1; i <=7; i++){
        memcpy(s+(128*i),s,128*4);
  }

kiss_fftr_cfg fft_cfg = kiss_fftr_alloc(fft_len,0,0,0);

kiss_fft_cpx out_cpx[fft_len/2 +1];

// Padding the 960 length data with zeros
memcpy(buff,s, sizeof(s));

kiss_fftr(fft_cfg,buff,out_cpx);

  for (i = 0; i <fft_len/2+1; i++){
        printf("\n%d %f%+f ",i,out_cpx[i].r,out_cpx[i].i);
  }

    return 0;
}

I compile it using:

gcc -g sinwave.c kiss_fft.c tools/kiss_fftr.c -o fsin -I "kiss_fft130/" -lm

rathin2j
  • 99
  • 1
  • 9
  • 1
    Try pinging the author, @MarkBorgerding, as he is [a contributor here on StackOverflow](https://stackoverflow.com/users/3343/mark-borgerding). – Paul R Jun 15 '17 at 07:22

1 Answers1

1

One problem is that you are overwriting the s buffer. The loop with "i<=7" makes 7 extra copies of the first 128 elements in s. 8*128 = 1024 > 960

Mark Borgerding
  • 8,117
  • 4
  • 30
  • 51
  • Yes, I am making 7 (sorry for typo, it shouldn't only < 7) copies to emulate the data window that I am going to receive. I am doing that for zero padding, should that coz trouble to KissFFT? It is just getting an zero padded array ultimately. – rathin2j Jun 15 '17 at 20:06
  • Thanks a lot! THAT **< 7** typo was the error, program started working. I am really sorry for troubling for such a trivial mistake! – rathin2j Jun 16 '17 at 06:20
  • Hey Mark! Nice seeing you on Stackoverflow! I guess there is no better person to ask a question related to **kissfft** than yourself. Do you mind taking a look at [this problem](https://stackoverflow.com/q/61872422/176769)? Your help will be much appreciated. – karlphillip May 18 '20 at 15:02