This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/TMS320F28379D: How to take absolute value for array data

Part Number: TMS320F28379D

Tool/software: Code Composer Studio

Hello, I'm using '2837x_RFFT_ADC'  example code in CCS.

For FFT output, I want to take absolute value for these data.

===================================================================================================================================================

#include "fpu_rfft.h"

#include "math.h"

#include "examples_setup.h"

#define RFFT_STAGES 11

#define RFFT_SIZE (1 << RFFT_STAGES)

#define F_PER_SAMPLE (ADC_SAMPLING_FREQ/(float)RFFT_SIZE)

#pragma DATA_SECTION(RFFTin1Buff,"RFFTdata1")

uint16_t RFFTin1Buff[2*RFFT_SIZE];

#pragma DATA_SECTION(RFFTmagBuff,"RFFTdata2")

float RFFTmagBuff[RFFT_SIZE/2+1];

#pragma DATA_SECTION(RFFToutBuff,"RFFTdata3")

float RFFToutBuff[RFFT_SIZE];

//float RFFToutBuff1[RFFT_SIZE]=fabsf(RFFToutBuff[RFFT_SIZE]);

#pragma DATA_SECTION(RFFTF32Coef,"RFFTdata4")

float RFFTF32Coef[RFFT_SIZE];

RFFT_ADC_F32_STRUCT rfft_adc;

RFFT_ADC_F32_STRUCT_Handle hnd_rfft_adc = &rfft_adc;

RFFT_F32_STRUCT rfft;

RFFT_F32_STRUCT_Handle hnd_rfft = &rfft;

volatile uint16_t flagInputReady = 0;

volatile uint16_t sampleIndex = 0;

uint16_t pass = 0;

uint16_t fail = 0;

__interrupt void adcaIsr();

int16_t main(void)

{

uint16_t i, j;

float freq = 0.0;

#ifdef FLASH

EALLOW;

Flash0EccRegs.ECC_ENABLE.bit.ENABLE = 0;

memcpy((uint32_t *)&RamfuncsRunStart, (uint32_t *)&RamfuncsLoadStart,

(uint32_t)&RamfuncsLoadSize );

FPU_initFlash();

#endif //FLASH

FPU_initSystemClocks();

FPU_initEpie();

FPU_initADCA();

 FPU_initEPWM();

EALLOW;

PieVectTable.ADCA1_INT = &adcaIsr;

EDIS;

PieCtrlRegs.PIEIER1.bit.INTx1 = 1;

IER |= M_INT1;

EINT;

ERTM;

FPU_startEPWM();

hnd_rfft_adc->Tail = &(hnd_rfft->OutBuf);

hnd_rfft->FFTSize = RFFT_SIZE; //FFT size

hnd_rfft->FFTStages = RFFT_STAGES; //FFT stages

hnd_rfft_adc->InBuf = &RFFTin1Buff[0]; //Input buffer (12-bit ADC) input

hnd_rfft->OutBuf = &RFFToutBuff[0]; //Output buffer

hnd_rfft->CosSinBuf = &RFFTF32Coef[0]; //Twiddle factor

hnd_rfft->MagBuf = &RFFTmagBuff[0]; //Magnitude output buffer

RFFT_f32_sincostable(hnd_rfft); //Calculate twiddle factor

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

RFFToutBuff[i] = 0; //Clean up output buffer

}

for (i=0; i < RFFT_SIZE/2; i++){

RFFTmagBuff[i] = 0; //Clean up magnitude buffer

}

while(1){

while(flagInputReady == 0){};

RFFT_adc_f32(hnd_rfft_adc);

flagInputReady = 0; // Reset the flag

RFFT_f32_mag(hnd_rfft); //Calculate magnitude

j = 1;

freq = RFFTmagBuff[1];

for(i=2;i<RFFT_SIZE/2+1;i++){

if(RFFTmagBuff[i] > freq){

j = i;

freq = RFFTmagBuff[i];

}

}

freq = F_PER_SAMPLE * (float)j;

}

done();

return 1;

}

__interrupt void adcaIsr()

{

RFFTin1Buff[sampleIndex++] = AdcaResultRegs.ADCRESULT0;

if(sampleIndex == (RFFT_SIZE - 1) ){

sampleIndex = 0;

flagInputReady = 1;

}

AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //clear INT1 flag

PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;

}

=========================================================================================================================

From this code, FFT output data is stored in 'RFFToutBuff'.

Please help me

Thank you.