Efficient circular buffer for use with CMSIS-DSP lib K64

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

Efficient circular buffer for use with CMSIS-DSP lib K64

1,481 Views
jparrish88
Contributor IV

Hello all,

I'm trying to figure out an efficient method to pass my (our any version of circular buffer) to the CMSIS-DSPs functions. Specifically, I'm targeting the arm_cfft_f32 function. The issue here is that it requires a source pointer to a contiguous memory space. Yet, the design of a ring or circular buffer makes that difficult.

I'm using a K64, using 32 bit floats, with 32 point input buffer.

My current buffer code is:

#define BUFF_SIZE 32

#define BUFF_SIZE_MASK (BUFF_SIZE-1)

typedef struct filbuffer{

    float buff[BUFF_SIZE];

    int writeIndex;

}filbuffer;

void initBuffer(filbuffer* buffer){

  int i;

  buffer->writeIndex = 0;

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

  buffer->buff[i]=0;

  }

}

/* Write to the buffer */

void write(filbuffer* buffer, float value){

    buffer->buff[(buffer->writeIndex++) & BUFF_SIZE_MASK] = value;

}

/* Read from the buffer -- probably not needed */

float readn(filbuffer* buffer, int Xn){

    return buffer->buff[(buffer->writeIndex + (~Xn)) & BUFF_SIZE_MASK];

}

Labels (1)
Tags (2)
0 Kudos
1 Reply

829 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Friends,

I see  that you would like to use the following api function to compute the complex FFT which is defined in arm_cfft_f32.c.

If it is the case, you use the function:

void arm_cfft_f32(

    const arm_cfft_instance_f32 * S,

    float32_t * p1,

    uint8_t ifftFlag,

    uint8_t bitReverseFlag)

* The FFT functions operate in-place.  That is, the array holding the input data

* will also be used to hold the corresponding result.  The input data is complex

* and contains <code>2*fftLen</code> interleaved values as shown below.

* <pre> {real[0], imag[0], real[1], imag[1],..} </pre>

* The FFT result will be contained in the same array and the frequency domain

* values will have the same interleaving.

as the above direction, you can define a structure:

typedef struct {

float32_t real;

float32_t image;

} complex;

complex array[64];

after you initialize the array[] and call the arm_cfft_f32(), it is okay.

BR

Xiangjun Rong