From 5b2ed3097b8a05ed26eca2941e4965a4811b5fa8 Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Fri, 17 Jun 2022 10:34:10 +0000 Subject: [PATCH] - polyphase is a Processor::Block git-svn-id: http://moon:8086/svn/software/trunk/libsrc/cpp@1020 b431acfa-c32f-4a4a-93f1-934dc6c82436 --- radio/interpolation/PolyPhase.hpp | 78 +++++++++++++++++-------------- 1 file changed, 44 insertions(+), 34 deletions(-) diff --git a/radio/interpolation/PolyPhase.hpp b/radio/interpolation/PolyPhase.hpp index 685db91..59d017c 100644 --- a/radio/interpolation/PolyPhase.hpp +++ b/radio/interpolation/PolyPhase.hpp @@ -5,6 +5,9 @@ #include #include +#include +#include + #include #include #include @@ -16,10 +19,13 @@ namespace Interpolation // -------------------------------------------------------------- // Complex FIR-based discrete step polyphase interpolation filter // -------------------------------------------------------------- -class PolyPhase : public FirComplex +class PolyPhase : public Processor::Block { public: - PolyPhase() + PolyPhase(TimingGenerator &timingGenerator) + : Processor::Block(1, 1) + , m_timingGenerator(timingGenerator) + , m_buf_in(8*1024) { } @@ -35,12 +41,11 @@ public: fir_float_t *pCoeff; RealScalar k; - FirComplex::setNumTaps(N); + m_fir.setNumTaps(N); m_M = M; m_N = N; m_coeff.resize(N, M); - m_fifo.resize(N); - m_fifo = ComplexScalar(0,0); +// m_buf_in.resize(N); pCoeff = (fir_float_t*)malloc((N+1)*M*sizeof(fir_float_t)); memset(pCoeff, 0, (N+1)*M*sizeof(fir_float_t)); @@ -58,46 +63,51 @@ public: free(pCoeff); } - void feed(ComplexScalar const &x, uint32_t push) + void process() { - m_w = (m_w + push) % m_N; - m_fifo[m_w] = x; - } - - ComplexScalar process(RealScalar mu, uint32_t pop) - { - uint32_t i, r, index; - int32_t j; + // Get output buffer + auto buf_out = dynamic_cast*>(buffer_out()); - index = (uint32_t)dmod(dmax(0, mu*m_M), (RealScalar)m_M); - - m_r = (m_r + pop) % m_N; - - if (pop) + // Process input + while(buf_out->free()) { - r = m_r; - j = m_N-1; - while(r < m_N) - { - m_state[j--] = m_fifo[r++]; - } - r = 0; - while(j >= 0) - { - m_state[j--] = m_fifo[r++]; - } - } + size_t adv = m_timingGenerator.getAdv(); + radio_float_t mu = m_timingGenerator.getMu(); - return FirComplex::processReal(column(m_coeff, index)); + if (m_buf_in.len() < adv) + { + break; + } + + if (adv != 0) + { + m_fir.feed(m_buf_in, adv); + } + + // Polyphase filtering + uint32_t index = (uint32_t)dmod(dmax(0, mu*m_M), (RealScalar)m_M); + ComplexScalar yout = m_fir.processReal(column(m_coeff, index)); + buf_out->write(&yout, 1); + + // Process timing generator + m_timingGenerator.process(yout); + } } - + + Processor::IBuffer* buffer_in(size_t index=0) override + { + return &m_buf_in; + } + private: + TimingGenerator &m_timingGenerator; + Processor::Buffer m_buf_in; + FirComplex m_fir; uint32_t m_M; uint32_t m_N; uint32_t m_r; uint32_t m_w; RMat m_coeff; - CVec m_fifo; }; } // Radio::Interpolation