Question asked by lujing6662008 on Apr 8, 2013
Latest reply on Apr 9, 2013 by CraigG

Hi,I have some questions about the cabs_fr16 function.

I know it can calculate the magnitude of complex number,but when I specify the real and imaginary parts of a complex number and attempt to obtain its magnitude, I failed. It doesn't give me a correct result.

for example:

#include<fract.h>
#include<complex.h>

#define TestSize  32
#define Cycle     1
complex_fract16 Testout1[TestSize];
void testcabs1()
{
static int cnt = 0;
WORD TemFun_RL;
WORD TemFun_IM;
WORD TemFun_RL1;
WORD TemFun_IM1;
WORD FunMag;
WORD FunMag1;
WORD FunMag2,FunMag3,FunMag4,FunMag5;

Testout1[Cycle].re = 0xBB8;//3000;//BB8
Testout1[Cycle].im = 0xFA0;//4000;//FA0
FunMag2 = (WORD)cabs_fr16(Testout1[Cycle]);
Testout1[Cycle].re = 0xF448;//(-3000);
Testout1[Cycle].im = 0xFA0;//4000;
FunMag3 = (WORD)cabs_fr16(Testout1[Cycle]);
Testout1[Cycle].re = 0xF448;//(-3000);//F448
Testout1[Cycle].im = 0xF060;//(-4000)>>15;//F060
FunMag4 = (WORD)cabs_fr16(Testout1[Cycle]);
Testout1[Cycle].re = 0xBB8;//3000;
Testout1[Cycle].im = 0xF060;//(-4000);
FunMag5 = (WORD)cabs_fr16(Testout1[Cycle]);
TemFun_RL = Testout1[Cycle].re;
TemFun_IM = Testout1[Cycle].im;
FunMag1 = sqrt(TemFun_RL*TemFun_RL + TemFun_IM*TemFun_IM);
cnt++;
if(cnt>=50)
{
printf("==%d,%d,%d,%d,%d\n",FunMag2,FunMag3,FunMag4,FunMag5,FunMag1);
cnt = 0;
}
}

the correct result should be 5000,5000,5000,5000,5000.

but what I get is 5033,5033,5033,5033,5000.

who can tell me why? Thanks very much.