2014-10-07 06:24 PM
Hi,
Iam trying to use DSP lib on STM32F4 chip. I run the example project of FFT on CMSIS lib and it's ok:an float array ==> FFT ==> result it's ok.But I try on my board:Signal generator => external ADC => FFT on STM32F4 => result it's wrong and when I change input signal (sine 1Khz, 2Khz, 3Khz...), the result didnot change. The difference between 2 program is the input of example project is an float array, but other is signed short int array. Am I wrong in this step? Please show me the solution.Any help will be appreciated, Thanks in advance.Regards,Nhan2014-10-07 09:32 PM
#include ''stm32f4xx.h''
#include ''SSD19h''
#include ''delay.h''
#include ''arm_math.h''
#include ''stdlib.h''
#include ''ts.h''
#include ''main.h''
void dac(float phasevolt);
void EXTI15_10_IRQHandler(void);
float32_t FFT[256]={0};
uint16_t FFTold[128]={0};
float fazenauja=0;
float diodo_spektras[512]={0};
int diodo_spektrasold[130]={0};
float32_t maxValue;
uint8_t maxIndex = 0;
float32_t maxValue2;
uint32_t maxIndex2 = 0;
float PID=0.2;
char stringas[8];
signed int taskas = 7;
float invertacija = 1;
int fftenable=0,diodeV=0;
float vidurkis=0;
int main()
{
Delay2(0xFFFFF);
touch_init();
Delay2(0xFFFFF);
LCD_Init();
Delay2(0xFFFFF);
t();
Delay2(0xFFFFF);
DMA_Config();
Delay2(0xFFFFF);
arm_status status;
arm_cfft_radix4_instance_f32 S;
EXTI_GenerateSWInterrupt(EXTI_Line12);
uint16_t i=0,k=0;
status = arm_cfft_radix4_init_f32(&S, 256, 0, 1);
while(i<
512
)
{
diodo_spektras[i]=0;
i++;
}
i
=
0
;
while(i<130)
{
diodo_spektrasold[i]=0;
i++;
}
while(1)
{
Delay(0xFF);
GPIOB->ODR=0x02;
Delay(20);
GPIOB->ODR=0x03;
Delay(20);
i=0;
k=0;
vidurkis=0;
while(i<
128
)
{
GPIOB->ODR=0x01;
Delay(300);
GPIOB->ODR=0x00;
Delay(200);
diodo_spektras[k]=(float)ADCDualConvertedValue[0];
vidurkis+=(diodo_spektras[k]/128);
k++;
diodo_spektras[k]=0;
k++;
i++;
}
while(k<
512
)
{
diodo_spektras[k]=0;
k++;
}
diodo_spektras[0]=diodo_spektras[4];
diodo_spektras[2]=diodo_spektras[6];
i
=
0
;
if(diodeV==0)
{
while(i<126)
{
LCD_Line(i,228-(diodo_spektrasold[i]/22),i+1,228-(diodo_spektrasold[i+1]/22),BLACK);
LCD_Line(i,228-(int)(diodo_spektras[2*i]/22),i+1,228-(int)(diodo_spektras[2*i+2]/22),YELLOW);
i++;
}
i
=
0
;
while(i<130)
{
diodo_spektrasold[i]=(int)diodo_spektras[2*i];
i++;
}
}
i
=
0
;
/*
while(i<128)
{
diodo_spektras[2*i]=(diodo_spektras[2*i]-vidurkis);
i++;
}
*/
arm_cfft_radix4_f32(&S,diodo_spektras);
fazenauja
= fazenauja-(PID*invertacija*angle(diodo_spektras[taskas*2],diodo_spektras[taskas*2+1]));
dac(fazenauja);
arm_cmplx_mag_f32(diodo_spektras, FFT, 256);
i
=
0
;
/*
maxValue
=
0
;
maxIndex
=
0
;
while(i<127)
{
if(FFT[i]>maxValue)
{
maxValue=FFT[i];
maxIndex=i;
}
i++;
}
maxValue/=186;
sprintf(stringas, ''%d'', maxIndex);
LCD_StringLine(304,10,(u8*) '' '');
LCD_StringLine(304,10,(u8*) stringas);
i=0;
if(fftenable==0)
{
while(i<
126
)
{
LCD_Line(200+2*i,228-FFTold[i],2*i+202,228-FFTold[i+1],BLACK);
LCD_Line(200+2*i,228-(int)(FFT[i]/maxValue),2*i+202,228-(int)(FFT[i+1]/maxValue),BLUE);
i++;
}
i
=
0
;
while(i<130)
{
FFTold[i]=(int)(FFT[i]/maxValue);
i++;
}
LCD_Line(200+taskas*2,30,200+taskas*2,240,RED);
}
LCD_Line(130,30,130,240,BLACK);
LCD_Line(130,136,130,136-(int)(30*angle(diodo_spektras[taskas*2],diodo_spektras[taskas*2+1])),GREEN);
*/
}
}
This code can by your start point, id does work just fine
And this is how you fill array, note that odd numbers are empty, since you don't have imaginary part, only real part, and array is 2x longer than you have samples
diodo_spektras[k]=(float)ADCDualConvertedValue[0];
k++;
diodo_spektras[k]=0;
k++;
2014-10-08 06:08 PM
Hi Karpavicius,
Thank you so much about your help, I will try it nowRegards,Nhan2014-10-09 02:13 AM