AnsweredAssumed Answered

CFFT_Q15 validation

Question asked by michel gaeta on Jan 19, 2017
Latest reply on Feb 24, 2018 by Pablo Cottens

Hi 

i am trying to use arm_cfft_q15.c from cmsis dsp. 

I could not match Matlab result. 

matalb resul : 

real_fft_result = 40 21 129 259 170 -17 30 136 100 136 30 -17 170 259 129 21
imag_fft_result = 0 53 136 17 -150 -92 76 23 0 -23 -76 92 150 -17 -136 -53

CMSIS result : 

TEST FFT Q15 using dsp_cmsis.
fft q15 result, real part : 1 0 7 15 11 -1 1 8 6 8 2 -1 11 16 7 1 
fft q15 result, Imag part : 0 3 7 0 -10 -6 5 2 0 -2 -5 5 9 -2 -8 -4

Can some one could have a look to the following code 

 

 

/*
* test_fft_q15.c
*
* Created on: 28 déc. 2016
* Author: gaeta
*/
/* ----------------------------------------------------------------------
* Test fft q15 function in comparison to matlab result
*
// reference matlab code
R=[100, 10,-40,-100, 20,50,-10,10, 0,0,0,0,0,0,0,0];
I=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
signal=R+1i*I;
fft_result=fft(signal);
real_fft_result=fix( real(fft_result) )
imag_fft_result=fix( imag(fft_result) )
//Matlab display :
real_fft_result = 40 21 129 259 170 -17 30 136 100 136 30 -17 170 259 129 21
imag_fft_result = 0 53 136 17 -150 -92 76 23 0 -23 -76 92 150 -17 -136 -53

* ------------------------------------------------------------------- */

#include <stdio.h>
#include <math.h>
#include <unistd.h>
#include <stdlib.h>
#include "fsl_debug_console.h"
#include "fsl_device_registers.h"
#include "Frdm.h"
#include "arm_math.h"
#include "arm_const_structs.h"


/* ----------------------------------------------------------------------
* Defines each of the tests performed
* ------------------------------------------------------------------- */
#define MAX_BLOCKSIZE 64
/* ----------------------------------------------------------------------
* Declare I/O buffers
* ------------------------------------------------------------------- */
q15_t Ak[MAX_BLOCKSIZE]; /* Input A */
q15_t testInputA [32] =
{100, 0,10,0,-40, 0,-100, 0,20,0,50,0,-10, 00,10, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};


int32_t test_fft_q15(void)
{
uint8_t fftSize = 16;
uint8_t ifftFlag = 0;
uint8_t bitReverseFlag =1;
uint8_t ii;

/* Initialise the fft input buffers with all zeros */
arm_fill_q15(0, Ak, MAX_BLOCKSIZE);

/* Copy the input values to the fft input buffers */
for ( ii=0;ii<16;ii++) Ak[ii]=(q15_t) testInputA[ii];

/* Transform input a[n] from time domain to frequency domain A[k] */
arm_cfft_q15(&arm_cfft_sR_q15_len16, Ak,ifftFlag,bitReverseFlag);

/* Display result */
PRINTF(" fft q15 result, real part :" );
for ( ii=0;ii<32;ii++) PRINTF(" %d",Ak[ii*2] );
PRINTF(" \r\n" );
PRINTF(" fft q15 result, Imag part :" );
for ( ii=0;ii<32;ii++) PRINTF(" %d",Ak[ii*2+1] );
PRINTF(" \r\n" );

return 1;
}

Outcomes