- polyphase is a Processor::Block
git-svn-id: http://moon:8086/svn/software/trunk/libsrc/cpp@1020 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
@@ -5,6 +5,9 @@
|
|||||||
|
|
||||||
#include <cpp/radio/Vector.hpp>
|
#include <cpp/radio/Vector.hpp>
|
||||||
#include <cpp/radio/FirComplex.hpp>
|
#include <cpp/radio/FirComplex.hpp>
|
||||||
|
#include <cpp/radio/processor/src/Block.hpp>
|
||||||
|
#include <cpp/radio/interpolation/TimingGenerator.hpp>
|
||||||
|
|
||||||
#include <fir/fir2.h>
|
#include <fir/fir2.h>
|
||||||
#include <memory.h>
|
#include <memory.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -16,10 +19,13 @@ namespace Interpolation
|
|||||||
// --------------------------------------------------------------
|
// --------------------------------------------------------------
|
||||||
// Complex FIR-based discrete step polyphase interpolation filter
|
// Complex FIR-based discrete step polyphase interpolation filter
|
||||||
// --------------------------------------------------------------
|
// --------------------------------------------------------------
|
||||||
class PolyPhase : public FirComplex
|
class PolyPhase : public Processor::Block
|
||||||
{
|
{
|
||||||
public:
|
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;
|
fir_float_t *pCoeff;
|
||||||
RealScalar k;
|
RealScalar k;
|
||||||
|
|
||||||
FirComplex::setNumTaps(N);
|
m_fir.setNumTaps(N);
|
||||||
m_M = M;
|
m_M = M;
|
||||||
m_N = N;
|
m_N = N;
|
||||||
m_coeff.resize(N, M);
|
m_coeff.resize(N, M);
|
||||||
m_fifo.resize(N);
|
// m_buf_in.resize(N);
|
||||||
m_fifo = ComplexScalar(0,0);
|
|
||||||
|
|
||||||
pCoeff = (fir_float_t*)malloc((N+1)*M*sizeof(fir_float_t));
|
pCoeff = (fir_float_t*)malloc((N+1)*M*sizeof(fir_float_t));
|
||||||
memset(pCoeff, 0, (N+1)*M*sizeof(fir_float_t));
|
memset(pCoeff, 0, (N+1)*M*sizeof(fir_float_t));
|
||||||
@@ -58,46 +63,51 @@ public:
|
|||||||
free(pCoeff);
|
free(pCoeff);
|
||||||
}
|
}
|
||||||
|
|
||||||
void feed(ComplexScalar const &x, uint32_t push)
|
void process()
|
||||||
{
|
{
|
||||||
m_w = (m_w + push) % m_N;
|
// Get output buffer
|
||||||
m_fifo[m_w] = x;
|
auto buf_out = dynamic_cast<Processor::Buffer<ComplexScalar>*>(buffer_out());
|
||||||
}
|
|
||||||
|
|
||||||
ComplexScalar process(RealScalar mu, uint32_t pop)
|
|
||||||
{
|
|
||||||
uint32_t i, r, index;
|
|
||||||
int32_t j;
|
|
||||||
|
|
||||||
index = (uint32_t)dmod(dmax(0, mu*m_M), (RealScalar)m_M);
|
// Process input
|
||||||
|
while(buf_out->free())
|
||||||
m_r = (m_r + pop) % m_N;
|
|
||||||
|
|
||||||
if (pop)
|
|
||||||
{
|
{
|
||||||
r = m_r;
|
size_t adv = m_timingGenerator.getAdv();
|
||||||
j = m_N-1;
|
radio_float_t mu = m_timingGenerator.getMu();
|
||||||
while(r < m_N)
|
|
||||||
{
|
|
||||||
m_state[j--] = m_fifo[r++];
|
|
||||||
}
|
|
||||||
r = 0;
|
|
||||||
while(j >= 0)
|
|
||||||
{
|
|
||||||
m_state[j--] = m_fifo[r++];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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:
|
private:
|
||||||
|
TimingGenerator &m_timingGenerator;
|
||||||
|
Processor::Buffer<ComplexScalar> m_buf_in;
|
||||||
|
FirComplex m_fir;
|
||||||
uint32_t m_M;
|
uint32_t m_M;
|
||||||
uint32_t m_N;
|
uint32_t m_N;
|
||||||
uint32_t m_r;
|
uint32_t m_r;
|
||||||
uint32_t m_w;
|
uint32_t m_w;
|
||||||
RMat m_coeff;
|
RMat m_coeff;
|
||||||
CVec m_fifo;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // Radio::Interpolation
|
} // Radio::Interpolation
|
||||||
|
|||||||
Reference in New Issue
Block a user