DSP库里面当前只有一个信噪比的函数做了简单处理,仅仅是简单处理,判断除数是否为NAN值0x7FC00000(NaN的一种情况)。
大家在使用有什么好的建议。
float arm_snr_f32(float *pRef, float *pTest, uint32_t buffSize)
{
float EnergySignal = 0.0, EnergyError = 0.0;
uint32_t i;
float SNR;
int temp;
int *test;
for (i = 0; i < buffSize; i++)
{
/* Checking for a NAN value in pRef array */
test = (int *)(&pRef);
temp = *test;
if (temp == 0x7FC00000)
{
return(0);
}
/* Checking for a NAN value in pTest array */
test = (int *)(&pTest);
temp = *test;
if (temp == 0x7FC00000)
{
return(0);
}
EnergySignal += pRef * pRef;
EnergyError += (pRef - pTest) * (pRef - pTest);
}
/* Checking for a NAN value in EnergyError */
test = (int *)(&EnergyError);
temp = *test;
if (temp == 0x7FC00000)
{
return(0);
}
SNR = 10 * log10 (EnergySignal / EnergyError);
return (SNR);
} |