Skip to content

Commit

Permalink
gr_fxpt : Add sincos function to class.
Browse files Browse the repository at this point in the history
Signed-off-by: Philip Balister <philip@opensdr.com>
  • Loading branch information
balister committed Mar 13, 2012
1 parent 0cdbdc6 commit c8f59ba
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
16 changes: 16 additions & 0 deletions gnuradio-core/src/lib/general/gr_fxpt.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,22 @@ class GR_CORE_API gr_fxpt
return s_sine_table[index][0] * (ux >> 1) + s_sine_table[index][1];
}

/*
* \brief Given a fixedpoint angle x, return float cos(x) and sin (x)
*/
static void sincos(gr_int32 x, float *s, float *c)
{
gr_uint32 ux = x;
int sin_index = ux >> (WORDBITS - NBITS);
*s = s_sine_table[sin_index][0] * (ux >> 1) + s_sine_table[sin_index][1];

ux = x + 0x40000000;
int cos_index = ux >> (WORDBITS - NBITS);
*c = s_sine_table[cos_index][0] * (ux >> 1) + s_sine_table[cos_index][1];

return;
}

};

#endif /* INCLUDED_GR_FXPT_H */
10 changes: 10 additions & 0 deletions gnuradio-core/src/lib/general/qa_gr_fxpt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,14 @@ qa_gr_fxpt::t2 ()
void
qa_gr_fxpt::t3 ()
{
std::cout << "In fixed sincos test" << std::endl;
for (float p = -M_PI; p < M_PI; p += 2 * M_PI / 3600){
float expected_sin = sin (p);
float expected_cos = cos (p);
float actual_sin;
float actual_cos;
gr_fxpt::sincos (gr_fxpt::float_to_fixed (p), &actual_sin, &actual_cos);
CPPUNIT_ASSERT_DOUBLES_EQUAL (expected_sin, actual_sin, SIN_COS_TOLERANCE);
CPPUNIT_ASSERT_DOUBLES_EQUAL (expected_cos, actual_cos, SIN_COS_TOLERANCE);
}
}

0 comments on commit c8f59ba

Please sign in to comment.