0

I have been trying to get KissFFT to work on a dsPIC, however after trying various different ways, the output is not what it should be. I was hoping to get some help to see if there are any configurations that I may be overlooking or if its just somthing i haven't thought of?

I am using a dsPIC33EP256MC202 with the XC16 compiler within MPLABX.

Declarations and memory assignment.

int readings[3] = {0, 0, 0};
kiss_fft_scalar zero;
memset(&zero,0,sizeof(zero));
int size = 128 * 2;

float fin[256];
kiss_fft_cpx in[size];
kiss_fft_cpx out[size];
for (i = 0; i < size; i++) {
in[i].r = zero;
in[i].i = zero;
out[i].r = zero;
out[i].i = zero;
}

kiss_fft_cfg mycfg = kiss_fft_alloc(size*2 ,0 ,NULL,NULL);

Get readings from an accellerometer on the breadboard and populate the float array (using pythagoras to consolidate the 3 axis' into one signal). The input XYZ value are scaled down as they come in anywhere between -2400 and 2400 on average.

while(1)
{
    if(iii <= 1){
        UART_Write_Text("Collecting...");
    }
    getOutput(readings);
    X = (double)readings[0];
    Y = (double)readings[1];
    Z = (double)readings[2];

    X = X / 50;
    Y = Y / 50;
    Z = Z / 50;

    if(ii <= 256){
        fin[ii] = sqrt(X*X + Y*Y + Z*Z);
        ii++;
    }
    else{
        i=0;
        while(i<255){
            fin[i] = fin[i+1];
            i++;
        }
        fin[255] = sqrt(X*X + Y*Y + Z*Z);

    }

Once the float array is full of values, populate the real component of the input complex array with the values in the float array. Then perform the Kiss FFT and populate a float array (arrayDFTOUT) with the absolute value of each real and imaginary value of the out array of Kiss FFT, the final loop makes any negative value positive.

if(iii == 255){
        iii = 0;
        UART_Write_Text("Processing...");

        for (i = 0; i < size; i++) {
            // samples are type of short
            in[i].r = fin[i];
            in[i].i = zero;
            out[i].r = zero;
            out[i].i = zero;
        }

        kiss_fft(mycfg, in, out);

        for(i=0;i<128;i++){
            arrayDFTOUT[i] = sqrt((out[i].r*out[i].r) + (out[i].i*out[i].i));
        }
        arrayDFTOUT[0] = 1;

        for(i = 0; i<128; i++){
            if(arrayDFTOUT[i] < 0){
            arrayDFTOUT[i] = arrayDFTOUT[i] - (arrayDFTOUT[i]*2);
            }
        }

Finally display the output values through serial using the UART on the breadboard.

for(i = 0; i < 128; i++){
            sprintf(temp, "%f,", arrayDFTOUT[i]);
            UART_Write_Text(temp);

        }

And are the results. All zero's aparet from the first value that was set to 1 after KissFFT had been performed. Any ideas?

Console Output

Sam
  • 350
  • 2
  • 9
  • you missed the `{` at the last for loop and increase `i` twice – mch Aug 20 '14 at 11:48
  • You should check your input data, the fft transform of a DC signal would be only the DC component on frequency=0, thus I suspect your input data is not correct (eg all values are 0) – Emilien Aug 20 '14 at 11:51
  • The input data is fine, i have been usilizing other fft algorithms and all have been well. However the KissFFT seems to have the fastest compute time (it works fine on mbed in C++). And as for the for loop i edited to have the right syntax (i made a couple of edits to it as i was uploading the question and over looked it) :). – Sam Aug 20 '14 at 12:05
  • I have been struggling just to get a project to compile with kiss fft and the dspic. Any chance you could provide any insight on what is needed to add the libraries to mplab?? – user2848810 Mar 12 '15 at 18:20

0 Answers0