summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Balister2012-03-13 10:13:06 -0400
committerPhilip Balister2012-03-13 10:13:06 -0400
commitc8f59bae854cccb6897c27424cce1a428c337286 (patch)
tree56e12ee9d9db8ac730d47ab10e823ebbd9e4339e
parent0cdbdc6e9f9c56e2820fc9474e108213be05325c (diff)
downloadgnuradio-c8f59bae854cccb6897c27424cce1a428c337286.tar.gz
gnuradio-c8f59bae854cccb6897c27424cce1a428c337286.tar.bz2
gnuradio-c8f59bae854cccb6897c27424cce1a428c337286.zip
gr_fxpt : Add sincos function to class.
Signed-off-by: Philip Balister <philip@opensdr.com>
-rw-r--r--gnuradio-core/src/lib/general/gr_fxpt.h16
-rw-r--r--gnuradio-core/src/lib/general/qa_gr_fxpt.cc10
2 files changed, 26 insertions, 0 deletions
diff --git a/gnuradio-core/src/lib/general/gr_fxpt.h b/gnuradio-core/src/lib/general/gr_fxpt.h
index 5cf736dfb..6f088769a 100644
--- a/gnuradio-core/src/lib/general/gr_fxpt.h
+++ b/gnuradio-core/src/lib/general/gr_fxpt.h
@@ -79,6 +79,22 @@ public:
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 */
diff --git a/gnuradio-core/src/lib/general/qa_gr_fxpt.cc b/gnuradio-core/src/lib/general/qa_gr_fxpt.cc
index 83bb05b2d..45bd3ed2c 100644
--- a/gnuradio-core/src/lib/general/qa_gr_fxpt.cc
+++ b/gnuradio-core/src/lib/general/qa_gr_fxpt.cc
@@ -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);
+ }
}