Kiss FFT on a dsPIC33

2019-09-07 05:20发布

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

0条回答
登录 后发表回答