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.

FFT code in F28335

Other Parts Discussed in Thread: CONTROLSUITE

Dear All,

I am trying to do the fft using F28335 where i am using current sensor to have signals to do the fft. The current sensors are working fine and giving sinosoidal current. I think that the FFT part in the code is ok. But,the fft in the graph window is not showing exactly i want. Some  one suggested me to check the ADC sampling frequency. I did so. I made to 250 Hz using the method described in controlsuite (put AdcRegs.ADCTRL3.bit.ADCCLKPS =  0x8F0D1;). As the system frequency is 15MHz i had to do so. I am still confused how to do that initialization of the ADC sampling and all this staffs. The code i am using is given below. The FFt plot i got in the graph window is also attached here.2480.FFT found.docx

Please anyone help me to get proper FFT using that one.

// Global variables used in this system

#ifndef M_PI
#define M_PI 3.14159265358979324
#endif
int nn;
int aa;
#define N 128
void compute_dft(double inreal[N], double inimag[N], double outreal[N], double outimag[N], int n);
double inputsignal[N] = {0};
double inputimag[N] = {0};
double inreal[N]={0};
double inimag[N]={0};
double outreal[N]={0};
double outimag[N]={0};
double result1[N/2]={0};
double THD;
float num=0;
float F=0;

void main(void){

DeviceInit();

// Initialize ADC 
ChSel[0]=0; 
ChSel[1]=2; 
ChSel[2]=4; 
ChSel[3]=6; 
ChSel[4]=8; 
// Initialize ADC module

ADC_MACRO_INIT(ChSel,TrigSel,ACQPS)

#ifdef DSP2833x_DEVICE_H
clarke1.As=((AdcMirror.ADCRESULT0)*0.00024414-offsetA)*2*0.909; // Phase A curr.
clarke1.Bs=((AdcMirror.ADCRESULT1)*0.00024414-offsetB)*2*0.909; // Phase B curr.
#endif

if (nn < N)
{ nn++;
inputsignal[nn]= (double)clarke1.As;
inputimag[nn] = 0;
}

else
{
compute_dft(inputsignal, inputimag, outreal, outimag, N);
nn=0;
}

}

void compute_dft(double inreal[N], double inimag[N], double outreal[N], double outimag[N], int n)
{
int k, m;
for (k = 0; k < n; k++) { /* For each output element */
double sumreal = 0;
double sumimag = 0;
int t;
//n=250;
for (t = 0; t < n; t++) { /* For each input element */
double angle = 2 * M_PI * t * k / n;
sumreal += inreal[t] * cos(angle) + inimag[t] * sin(angle);
sumimag += -inreal[t] * sin(angle) + inimag[t] * cos(angle);
}
outreal[k] = sumreal;
outimag[k] = sumimag;
}
for (m=0; m < N/2-1; m++)
{

result1[m]=sqrt(outreal[m]*outreal[m]+outimag[m]*outimag[m]);
}

BR

Arafat

  • Hi,

    From what you described, the graph settings are incorrect - 

    Acquisition buffer size = 128

    DSP data type = 64-bit double precision

    Sampling Rate Hz = 250

    Start Address = result1

    Display Data Size = 128

    I would also recommed you see the FFT examples in the fixed point DSP library in controlSUITE (controlSUITE/libs/dsp/FixedPointLib)

  • Hello Arafat,

    I am working on same module and would like to do fft for voltage and current signals which can come through sensors. will you please help me to generate fft and find THD for both the signals.

    regards

    Nikhil