From e45fc5d020193ea59302717bbd0666dd0508aa72 Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Wed, 15 Jun 2022 15:37:06 +0000 Subject: [PATCH] - added alternate_impl for gardner git-svn-id: http://moon:8086/svn/software/trunk/libsrc/radio@991 b431acfa-c32f-4a4a-93f1-934dc6c82436 --- synchronization.c | 18 +++++++++++++++--- synchronization.h | 1 + 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/synchronization.c b/synchronization.c index 61ec962..ce37bc0 100755 --- a/synchronization.c +++ b/synchronization.c @@ -91,6 +91,7 @@ void LeadLagSetState(lead_lag_filter_t *pObj, radio_float_t state) void STRGardnerInit(str_t *pObj) { memset(pObj->d, 0, sizeof(pObj->d)); + pObj->alternate_impl = 0; } radio_float_t STRGardnerProcess(str_t *pObj, cpx_t x) @@ -100,9 +101,20 @@ radio_float_t STRGardnerProcess(str_t *pObj, cpx_t x) pD = pObj->d; - t.real = (pD[1].real - x.real) * pD[0].real; - t.imag = (pD[1].imag - x.imag) * pD[0].imag; - Vd = (t.real + t.imag); + if (pObj->alternate_impl) + { + t.real = (x.real - pD[1].real) * pD[0].real; + t.imag = (x.imag - pD[1].imag) * pD[0].imag; + + radio_float_t sign = (t.real*t.imag) < 0 ? -1.0 : 1.0; + Vd = sqrt(fabs(t.real) * fabs(t.imag)) * sign; + } + else + { + t.real = (pD[1].real - x.real) * pD[0].real; + t.imag = (pD[1].imag - x.imag) * pD[0].imag; + Vd = (t.real + t.imag); + } // Adjust delay line pD[1] = pD[0]; diff --git a/synchronization.h b/synchronization.h index 0cc1655..34d8b6d 100755 --- a/synchronization.h +++ b/synchronization.h @@ -32,6 +32,7 @@ typedef struct _lead_lag_coeff_t typedef struct _str_t { cpx_t d[2]; + int alternate_impl; } str_t;