From 53067d36d0621e22e1aa91065a6e39897384c402 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Sat, 21 Jan 2017 18:57:39 +0000 Subject: [PATCH] More averaging of the centre and threshold. --- YSFRX.cpp | 14 ++++++++++---- YSFRX.h | 4 ++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/YSFRX.cpp b/YSFRX.cpp index bf6ed1d..0857fb6 100644 --- a/YSFRX.cpp +++ b/YSFRX.cpp @@ -119,7 +119,7 @@ void CYSFRX::processNone(q15_t sample) } if (m_dataPtr == m_endPtr) { - for (uint8_t i = 0U; i < 8U; i++) { + for (uint8_t i = 0U; i < 16U; i++) { m_centre[i] = m_centreBest; m_threshold[i] = m_thresholdBest; } @@ -176,12 +176,18 @@ void CYSFRX::processData(q15_t sample) m_centre[m_averagePtr] = m_centreBest; m_averagePtr++; - if (m_averagePtr >= 8U) + if (m_averagePtr >= 16U) m_averagePtr = 0U; // Find the average centre and threshold values - m_centreVal = (m_centre[0U] + m_centre[1U] + m_centre[2U] + m_centre[3U]) >> 3; - m_thresholdVal = (m_threshold[0U] + m_threshold[1U] + m_threshold[2U] + m_threshold[3U]) >> 3; + m_centreVal = 0; + m_thresholdVal = 0; + for (uint8_t i = 0U; i < 16U; i++) { + m_centreVal += m_centre[i]; + m_thresholdVal += m_threshold[i]; + } + m_centreVal >>= 4; + m_thresholdVal >>= 4; DEBUG4("YSFRX: sync found in Data (best) pos/centre/threshold", m_syncPtr, m_centreBest, m_thresholdBest); DEBUG4("YSFRX: sync found in Data (val) pos/centre/threshold", m_syncPtr, m_centreVal, m_thresholdVal); diff --git a/YSFRX.h b/YSFRX.h index d79bf61..15fdbbe 100644 --- a/YSFRX.h +++ b/YSFRX.h @@ -47,10 +47,10 @@ private: uint16_t m_syncPtr; q31_t m_maxCorr; uint16_t m_lostCount; - q15_t m_centre[8U]; + q15_t m_centre[16U]; q15_t m_centreVal; q15_t m_centreBest; - q15_t m_threshold[8U]; + q15_t m_threshold[16U]; q15_t m_thresholdVal; q15_t m_thresholdBest; uint8_t m_averagePtr;