DSPRelated.com
Forums

cos function problem

Started by steh...@hotmail.com July 23, 2009
I am using the cos function provided in ADSP218x c library. I am using it in the following function
void GenerateFilter(short Key, short * H, short * G)
{
short i;
short coeff;
float fN=(float)N;
float angle=0;
float cAngle;
float fangle=(2*3.1415*(Key+0.5))/fN;
for(i=0;i {
//angle=(fangle*i*180/PI);
cAngle=cos(angle);
coeffgle*32767;
H[i]=G[i]*coeff;
angle=angle+fangle;
if(angle>4*PI)
angle=angle-4*PI;
}
}

Let Key be 49. The fangle becomes 0.868739 and the angle increments by 0.868739 in each loop. cos function assumes values in radians. When cos is called with 0.868739 as input the output is -8.90891e-006, againt the output in matlab which is 0.6458. I cant understand why is cos function not working properly.
If this is the code you used, then it's correct. angle is set to zero
and never changed (you commented it out here).

On Thu, 23 Jul 2009, s...@hotmail.com wrote:

> I am using the cos function provided in ADSP218x c library. I am using it in the following function
> void GenerateFilter(short Key, short * H, short * G)
> {
> short i;
> short coeff;
> float fN=(float)N;
> float angle=0;
> float cAngle;
> float fangle=(2*3.1415*(Key+0.5))/fN;
> for(i=0;i > {
> //angle=(fangle*i*180/PI);
> cAngle=cos(angle);
> coeffgle*32767;
> H[i]=G[i]*coeff;
> angle=angle+fangle;
> if(angle>4*PI)
> angle=angle-4*PI;
> }
> }
>
> Let Key be 49. The fangle becomes 0.868739 and the angle increments by
>0.868739 in each loop. cos function assumes values in radians. When cos
>is called with 0.868739 as input the output is -8.90891e-006, againt the
>output in matlab which is 0.6458. I cant understand why is cos function
>not working properly.
>