3.4计算各次谐波幅值,先将lBufOutArray分解成实部(X)和虚部(Y),然后计算幅值(sqrt(X*X+Y*Y)。
void GetPowerMag()
{
signed short lX,lY;
float X,Y,Mag;
unsigned short i;
for(i=0; i<N/2; i++)
{
lX = (FFT_256PointOut[i] << 16) >> 16;
lY = (FFT_256PointOut[i] >> 16);
X = N * ((float)lX) / 32768;
Y = N * ((float)lY) / 32768;
Mag = sqrt(X * X + Y * Y) / N;
if(i == 0)
lBufMagArray[i] = (unsigned long)(Mag * 32768);
else
lBufMagArray[i] = (unsigned long)(Mag * 65536);
printf("%d ",i);
printf("%d ",F*i);
printf("%d ",lBufMagArray[i]);
printf("%d ",lX);
printf("%d \r\n",lY);
}
} |