这时来着网络的一个采用stm32的DSP库FFT变换后求模的函数,X= nfill*((float)lX)/32768;为什是这样求的?还有lBUFMAG[i] = (uint32_t)(Mag*65536);为什么还要乘65536?
void PowerMag(u16 nfill)
{
s16 lX,lY;
for (i=0; i < nfill/2; i++)
{
lX= (lBUFOUT[i]<<16)>>16; /* sine_cosine --> cos */
lY= (lBUFOUT[i] >> 16); /* sine_cosine --> sin */
{
float X= nfill*((float)lX)/32768;
float Y = nfill*((float)lY)/32768;
float Mag = sqrt(X*X+ Y*Y)/nfill;
lBUFMAG[i] = (uint32_t)(Mag*65536);
}
}
} |