summaryrefslogtreecommitdiff
path: root/gr-blocks/include/gnuradio/blocks/control_loop.h
diff options
context:
space:
mode:
authorghostop14 <ghostop14@gmail.com>2020-01-29 17:20:16 -0500
committerMichael Dickens <michael.dickens@ettus.com>2020-02-14 10:05:12 -0500
commitaa0bd44efbf8afdfd93d627e486c1427426b76f9 (patch)
treedd2acb4ebed83dc5a553678ba46b76424690b90a /gr-blocks/include/gnuradio/blocks/control_loop.h
parent36680f338e0b7ae7e5bcf7d2a860527ca7b14dfe (diff)
gr-digital: Improve Performance of Costas Loop
This update is focused on improving the throughput of the Costas loop, however some changes are more global performance enhancements as this PR has evolved. Updates include an ENABLE_NATIVE added to CMake, which is off by default but enables native compiling (including FMA support) if desired; sincos was inlined in sincos.h and sincos.cc was removed from the appropriate CMake to improve sincos speed, some constants were added to math.h, inlined functions in costas loop and nco.h, used switch instead of function pointer (much faster), and used fast complex multiply to get around all the range checking in the standard complex.h complex multiply function on all builds.
Diffstat (limited to 'gr-blocks/include/gnuradio/blocks/control_loop.h')
-rw-r--r--gr-blocks/include/gnuradio/blocks/control_loop.h24
1 files changed, 21 insertions, 3 deletions
diff --git a/gr-blocks/include/gnuradio/blocks/control_loop.h b/gr-blocks/include/gnuradio/blocks/control_loop.h
index 7aa43b531c..64d5ade620 100644
--- a/gr-blocks/include/gnuradio/blocks/control_loop.h
+++ b/gr-blocks/include/gnuradio/blocks/control_loop.h
@@ -12,6 +12,7 @@
#define GR_BLOCKS_CONTROL_LOOP
#include <gnuradio/blocks/api.h>
+#include <gnuradio/math.h>
namespace gr {
namespace blocks {
@@ -72,7 +73,11 @@ public:
/*! \brief Advance the control loop based on the current gain
* settings and the inputted error signal.
*/
- void advance_loop(float error);
+ void advance_loop(float error)
+ {
+ d_freq = d_freq + d_beta * error;
+ d_phase = d_phase + d_freq + d_alpha * error;
+ }
/*! \brief Keep the phase between -2pi and 2pi.
*
@@ -87,7 +92,13 @@ public:
* method in case another way is desired as this is fairly
* heavy-handed.
*/
- void phase_wrap();
+ void phase_wrap()
+ {
+ while (d_phase > GR_M_TWOPI)
+ d_phase -= GR_M_TWOPI;
+ while (d_phase < -GR_M_TWOPI)
+ d_phase += GR_M_TWOPI;
+ }
/*! \brief Keep the frequency between d_min_freq and d_max_freq.
*
@@ -102,7 +113,14 @@ public:
* method in case another way is desired as this is fairly
* heavy-handed.
*/
- void frequency_limit();
+ void frequency_limit()
+ {
+ if (d_freq > d_max_freq)
+ d_freq = d_max_freq;
+ else if (d_freq < d_min_freq)
+ d_freq = d_min_freq;
+ }
+
/*******************************************************************
* SET FUNCTIONS