From 934936d3f68d60eea114fa0cce91c44aa31fbcf2 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Wed, 2 Sep 2015 19:19:43 -0700 Subject: [PATCH] Enhancements to clock recovery Linearly interpolate input and delayed samples, based on phase of internal symbol clock. --- firmware/baseband/clock_recovery.hpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/firmware/baseband/clock_recovery.hpp b/firmware/baseband/clock_recovery.hpp index 8b7059af..4224032d 100644 --- a/firmware/baseband/clock_recovery.hpp +++ b/firmware/baseband/clock_recovery.hpp @@ -38,13 +38,15 @@ public: ) { const bool phase_0 = (phase_last >> 31) & (!(phase >> 31)); const bool phase_180 = (!(phase_last >> 31)) & (phase >> 31); - phase_last = phase; - phase += phase_increment + phase_adjustment; if( phase_0 || phase_180 ) { t2 = t1; t1 = t0; - t0 = in; + + const uint32_t phase_boundary = phase_180 ? (1U << 31) : 0; + const float alpha = (phase_boundary - phase_last) / float(phase_increment + phase_adjustment); + const float t = last_sample + alpha * (in - last_sample); + t0 = t; } if( phase_0 ) { @@ -59,6 +61,10 @@ public: // Correct phase (don't change frequency!) phase_adjustment = -phase_increment * error_filtered / 200.0f; } + + phase_last = phase; + phase += phase_increment + phase_adjustment; + last_sample = in; } private: @@ -66,6 +72,7 @@ private: uint32_t phase_last { 0 }; uint32_t phase_adjustment { 0 }; uint32_t phase_increment { 0 }; + float last_sample { 0 }; float t0 { 0 }; float t1 { 0 }; float t2 { 0 };