CMSIS arm_cfft_radix4_q15 library

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

CMSIS arm_cfft_radix4_q15 library

2,291 Views
seungbackjung
Contributor II

Dear all.

I am now using the FFT Library on Kinetis K60 N512.

mycode .c

/////////////////////////////////////////////////////

uint32_t fftSize  = 256;

uint32_t ifftFlag = 0;

uint32_t doBitReverse = 1;

arm_cfft_radix4_instance_q15 S;

arm_rfft_instance_q15 SQ;

arm_status status;

.....................

status = arm_cfft_radix4_init_q15( &S, fftSize, ifftFlag, doBitReverse); // Complex FFT initialisation

arm_cfft_radix4_q15(&S, ((q15_t *)data)); // Make CFFT in place

//////////////////////////////////////////////////////////////

For comparison between the results obtained from Matlab FFT and CMSIS FFT library,

I want to know the exact FFT equation used inside CMSIS FFT library or the Matlab code on CMSIS FFT library.

The reason why I ask like this question is when I compared the results between both cases, I got the different result.

If there is anyone who know on my question, please let me know it.

Thank you in advance.

5 Replies

1,145 Views
martynhunt
NXP Employee
NXP Employee

Hi,

The source code for the Radix-4 algorithm (arm_cfft_radix4_q15.c) can be found in the TransformFunctions sub-directory of the CMSIS directory.

Could you please share the differences between the Matlab result and the CMSIS result? Would it be possible for you to share the data buffer you are performing the transform on?

I suspect that the Matlab FFT (running on an x86 processor & OS, floating point values?) is going to provide slightly different answers to the CMSIS FFT running on an ARM Cortex-M devices using Q15 fixed point integer values. Of course if there is a major difference between the two solutions, then we will need to investigate what is causing the difference.

Also, what IDE/Compiler are you using for K60 development?

Best regards,

Martyn

0 Kudos
Reply

1,145 Views
seungbackjung
Contributor II

Dear. Martyn.

Thank you Your quickly reply.

I am using IAR 6.4 and J-Link.


For example, I input rear value 1~256/   image 1~256 both matlab and IAR

The matlab's First results is 3.2896+e4+3.289624+e4i

but IAR 's Firstg results is 127(real) and 127(image)...

Why occupied this result??? I think I did coding with wrong method .

pls. help me.

thank you .

0 Kudos
Reply

1,145 Views
bosleymusic_com
Contributor IV

Here's an example of round-off differences :

This is a function to build a hamming window that is calculated using 32-bit floats, which then converts it to q15 :

void hamming_window_q15(q15_t *finalarray) {

  float32_t temp_vals[SPEC_FFT_SIZE];

  float32_t bigN = (float32_t)SPEC_FFT_SIZE;

  int i = 0;

  for(i = 0; i < SPEC_FFT_SIZE; i++){

  //temp_vals[i] = .54 - .46 * cos(2*PI (i / bigN));

  temp_vals[i] = 0.54 - 0.46 * cos(2.0*PI*(((float32_t)i) / bigN));

  }

  arm_float_to_q15(temp_vals, finalarray, SPEC_FFT_SIZE);

}

^SPEC_FFT_SIZE is 1024.

The first values I get is 2622.

Using rounding in Matlab, I get these values for my hamming window, the round to achieve what would be equivalent to the binary of the q15 : { 2621, 2622, 2623, 2624, 2626, 2629, 2632, 2635,...

So you see the small differences that will arise when you do Matlab (generally 64 bit precision depending on your machine) versus fractional integers. The point is, expect imprecision when you use fractional integers.

0 Kudos
Reply

1,145 Views
martynhunt
NXP Employee
NXP Employee

Hi,

The q15_t format will only work for values between -1 & 0.99. I would try using the float32_t method and see if your results are closer to the Matlab results.

Also, could you share your data arrays so that I may run the fft on them to compare results? Thank you.

Best regards,

Martyn

1,145 Views
bosleymusic_com
Contributor IV

Fractional integers (q) are going to yield very imprecise values because of round off and saturation to a limited number of decimal places. If your signal has a significant DC component, then 127 and 127 wouldn't be outrageous compared to the value you saw coming from Matlab. What other kinds of values are you getting?

0 Kudos
Reply