- refactored
- use blaze matrix library instead of Eigen git-svn-id: http://moon:8086/svn/software/trunk/libsrc/cpp@943 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
+18
-16
@@ -19,7 +19,7 @@ namespace Equalizer
|
|||||||
class AEqualizer : public FirComplex
|
class AEqualizer : public FirComplex
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AEqualizer(uint32_t numTaps)
|
AEqualizer(size_t numTaps)
|
||||||
: FirComplex(numTaps)
|
: FirComplex(numTaps)
|
||||||
, m_w(numTaps)
|
, m_w(numTaps)
|
||||||
{
|
{
|
||||||
@@ -28,16 +28,16 @@ public:
|
|||||||
|
|
||||||
virtual ~AEqualizer() {}
|
virtual ~AEqualizer() {}
|
||||||
|
|
||||||
void setNumTaps(uint32_t numTaps)
|
void setNumTaps(size_t numTaps)
|
||||||
{
|
{
|
||||||
FirComplex::setNumTaps(numTaps);
|
FirComplex::setNumTaps(numTaps);
|
||||||
m_w.resize(numTaps);
|
m_w.resize(numTaps);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setUnit(uint32_t delay)
|
void setUnit(size_t delay)
|
||||||
{
|
{
|
||||||
m_w.setZero();
|
m_w = ComplexScalar(0, 0);
|
||||||
m_w(delay) = ComplexScalar(1, 0);
|
m_w[delay] = ComplexScalar(1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
const CVec& getWeights()
|
const CVec& getWeights()
|
||||||
@@ -59,7 +59,7 @@ protected:
|
|||||||
class Lms : public AEqualizer
|
class Lms : public AEqualizer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Lms(uint32_t numTaps)
|
Lms(size_t numTaps)
|
||||||
: AEqualizer(numTaps)
|
: AEqualizer(numTaps)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -80,14 +80,14 @@ private:
|
|||||||
class Cma : public Lms
|
class Cma : public Lms
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Cma(uint32_t numTaps=0)
|
Cma(size_t numTaps=0)
|
||||||
: Lms(numTaps)
|
: Lms(numTaps)
|
||||||
, m_xLast(0)
|
, m_xLast(0)
|
||||||
, m_power(0)
|
, m_power(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void init(uint32_t numTaps)
|
void init(size_t numTaps)
|
||||||
{
|
{
|
||||||
setNumTaps(numTaps);
|
setNumTaps(numTaps);
|
||||||
}
|
}
|
||||||
@@ -153,7 +153,7 @@ private:
|
|||||||
class Dfe : public Lms
|
class Dfe : public Lms
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Dfe(uint32_t k=0)
|
Dfe(size_t k=0)
|
||||||
: Lms(2*k+1)
|
: Lms(2*k+1)
|
||||||
, m_numFeedforward(k+1)
|
, m_numFeedforward(k+1)
|
||||||
, m_numFeedBack(k)
|
, m_numFeedBack(k)
|
||||||
@@ -165,7 +165,7 @@ public:
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
void init(uint32_t k)
|
void init(size_t k)
|
||||||
{
|
{
|
||||||
setNumTaps(2*k+1);
|
setNumTaps(2*k+1);
|
||||||
m_numFeedforward = k+1;
|
m_numFeedforward = k+1;
|
||||||
@@ -174,11 +174,13 @@ public:
|
|||||||
|
|
||||||
ComplexScalar process(ComplexScalar const &xs, ComplexScalar const &xh)
|
ComplexScalar process(ComplexScalar const &xs, ComplexScalar const &xh)
|
||||||
{
|
{
|
||||||
int32_t i;
|
// P-Code
|
||||||
CVec &x = m_state;
|
|
||||||
|
|
||||||
// x(0:size-1) = [xs, x(0:m_numFeedforward-2), xh, x(m_numFeedforward:size-2)]
|
// x(0:size-1) = [xs, x(0:m_numFeedforward-2), xh, x(m_numFeedforward:size-2)]
|
||||||
m_state.reverse() << m_state.segment(m_numFeedforward-1, m_numFeedBack).reverse(),xh,m_state.segment(0, m_numFeedforward-2).reverse(),xs;
|
auto sv_xs = subvector(m_state, 0, m_numFeedforward);
|
||||||
|
insert_left(sv_xs, xs);
|
||||||
|
|
||||||
|
auto sv_xh = subvector(m_state, m_numFeedforward, m_numFeedBack);
|
||||||
|
insert_left(sv_xh, xh);
|
||||||
|
|
||||||
return FirComplex::process(m_w);
|
return FirComplex::process(m_w);
|
||||||
}
|
}
|
||||||
@@ -189,8 +191,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint32_t m_numFeedforward;
|
size_t m_numFeedforward;
|
||||||
uint32_t m_numFeedBack;
|
size_t m_numFeedBack;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ namespace Radio
|
|||||||
class FirComplex
|
class FirComplex
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FirComplex(uint32_t numTaps = 0)
|
FirComplex(size_t numTaps = 0)
|
||||||
: m_numTaps(numTaps)
|
: m_numTaps(numTaps)
|
||||||
, m_state(numTaps)
|
, m_state(numTaps)
|
||||||
{
|
{
|
||||||
@@ -26,32 +26,31 @@ public:
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setNumTaps(uint32_t numTaps)
|
void setNumTaps(size_t numTaps)
|
||||||
{
|
{
|
||||||
m_numTaps = numTaps;
|
m_numTaps = numTaps;
|
||||||
m_state.resize(numTaps);
|
m_state.resize(numTaps);
|
||||||
m_state.fill(ComplexScalar(0,0));
|
m_state = ComplexScalar(0,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void feed(ComplexScalar const &x)
|
void feed(ComplexScalar const &x)
|
||||||
{
|
{
|
||||||
m_state.reverse() << m_state.head(m_numTaps-1).reverse(), x;
|
insert_left(m_state, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
ComplexScalar process(CVec const &coeff)
|
ComplexScalar process(CVec const &coeff)
|
||||||
{
|
{
|
||||||
return m_state.transpose() * coeff.conjugate();
|
return ctrans(m_state) * coeff;
|
||||||
}
|
}
|
||||||
|
|
||||||
ComplexScalar processReal(RVec const &coeff)
|
ComplexScalar processReal(RVec const &coeff)
|
||||||
{
|
{
|
||||||
return m_state.transpose() * coeff;
|
return trans(m_state) * coeff;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint32_t m_numTaps;
|
size_t m_numTaps;
|
||||||
CVec m_state;
|
CVec m_state;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // ::Radio
|
} // ::Radio
|
||||||
|
|||||||
+9
-9
@@ -84,15 +84,15 @@ public:
|
|||||||
return y * m_state;
|
return y * m_state;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mixRealComplexV(CVec &dst, RVec const &src, RealScalar gain, uint32_t len)
|
void mixRealComplexV(CVec &dst, RVec const &src, RealScalar gain, size_t len)
|
||||||
{
|
{
|
||||||
uint32_t i;
|
size_t i;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (len--)
|
while (len--)
|
||||||
{
|
{
|
||||||
|
|
||||||
dst(i) = mixRealComplexS(src(i), gain);
|
dst[i] = mixRealComplexS(src[i], gain);
|
||||||
|
|
||||||
// NCO update
|
// NCO update
|
||||||
process(0, 0);
|
process(0, 0);
|
||||||
@@ -100,15 +100,15 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void mixComplexRealV(RVec &dst, CVec const &src, ComplexScalar const &gain, uint32_t len)
|
void mixComplexRealV(RVec &dst, CVec const &src, ComplexScalar const &gain, size_t len)
|
||||||
{
|
{
|
||||||
uint32_t i;
|
size_t i;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (len--)
|
while (len--)
|
||||||
{
|
{
|
||||||
|
|
||||||
dst(i) = mixComplexRealS(src(i), gain);
|
dst[i] = mixComplexRealS(src[i], gain);
|
||||||
|
|
||||||
// NCO update
|
// NCO update
|
||||||
process(0, 0);
|
process(0, 0);
|
||||||
@@ -116,14 +116,14 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void mixComplexV(CVec &srcDst, ComplexScalar const &gain, uint32_t len)
|
void mixComplexV(CVec &srcDst, ComplexScalar const &gain, size_t len)
|
||||||
{
|
{
|
||||||
uint32_t i;
|
size_t i;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (len--)
|
while (len--)
|
||||||
{
|
{
|
||||||
srcDst(i) = mixComplexS(srcDst(i), gain);
|
srcDst[i] = mixComplexS(srcDst[i], gain);
|
||||||
|
|
||||||
// NCO update
|
// NCO update
|
||||||
process(0, 0);
|
process(0, 0);
|
||||||
|
|||||||
+36
-1
@@ -8,7 +8,7 @@
|
|||||||
#ifndef _RADIO_VECTOR_HPP_
|
#ifndef _RADIO_VECTOR_HPP_
|
||||||
#define _RADIO_VECTOR_HPP_
|
#define _RADIO_VECTOR_HPP_
|
||||||
|
|
||||||
#define VECTOR_USE_EIGEN
|
#define VECTOR_USE_BLAZE
|
||||||
|
|
||||||
#include <complex>
|
#include <complex>
|
||||||
#include <radio/cpx.h>
|
#include <radio/cpx.h>
|
||||||
@@ -22,6 +22,10 @@
|
|||||||
#include <Eigen/Dense>
|
#include <Eigen/Dense>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef VECTOR_USE_BLAZE
|
||||||
|
#include <blaze/Blaze.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef VECTOR_USE_ARMADILLO
|
#ifdef VECTOR_USE_ARMADILLO
|
||||||
#include <armadillo>
|
#include <armadillo>
|
||||||
#endif
|
#endif
|
||||||
@@ -42,6 +46,37 @@ typedef Eigen::Matrix<ComplexScalar, Eigen::Dynamic, Eigen::Dynamic> CMat;
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef VECTOR_USE_BLAZE
|
||||||
|
typedef blaze::DynamicVector<RealScalar> RVec;
|
||||||
|
typedef blaze::DynamicVector<ComplexScalar> CVec;
|
||||||
|
|
||||||
|
typedef blaze::DynamicMatrix<RealScalar> RMat;
|
||||||
|
typedef blaze::DynamicMatrix<ComplexScalar> CMat;
|
||||||
|
|
||||||
|
inline void ror(auto &vec)
|
||||||
|
{
|
||||||
|
vec = elements(vec, [size=vec.size()](size_t i){ return (i-1) % size; }, vec.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void rol(auto &vec)
|
||||||
|
{
|
||||||
|
vec = elements(vec, [size=vec.size()](size_t i){ return (i+1) % size; }, vec.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void insert_left(auto &vec, auto const &x)
|
||||||
|
{
|
||||||
|
ror(vec);
|
||||||
|
vec[0] = x;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void insert_right(auto &vec, auto const &x)
|
||||||
|
{
|
||||||
|
rol(vec);
|
||||||
|
vec[vec.size()-1] = x;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef VECTOR_USE_ARMADILLO
|
#ifdef VECTOR_USE_ARMADILLO
|
||||||
#error "Vector: Implement armadillo support!"
|
#error "Vector: Implement armadillo support!"
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ public:
|
|||||||
{
|
{
|
||||||
if (coeff)
|
if (coeff)
|
||||||
{
|
{
|
||||||
m_pCoeff[stage](j++) = coeff[i];
|
m_pCoeff[stage][j++] = coeff[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -82,14 +82,14 @@ public:
|
|||||||
j = 0;
|
j = 0;
|
||||||
for (i=0; i < len; i++)
|
for (i=0; i < len; i++)
|
||||||
{
|
{
|
||||||
m_pFir[m_currStage].feed(src(i));
|
m_pFir[m_currStage].feed(src[i]);
|
||||||
if (m_currStage == (m_M-1))
|
if (m_currStage == (m_M-1))
|
||||||
{
|
{
|
||||||
dst(j) = m_pFir[m_currStage].processReal(m_pCoeff[m_currStage]);
|
dst[j] = m_pFir[m_currStage].processReal(m_pCoeff[m_currStage]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dst(j) += m_pFir[m_currStage].processReal(m_pCoeff[m_currStage]);
|
dst[j] += m_pFir[m_currStage].processReal(m_pCoeff[m_currStage]);
|
||||||
}
|
}
|
||||||
if (--m_currStage >= m_M)
|
if (--m_currStage >= m_M)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ public:
|
|||||||
m_b.resize(M);
|
m_b.resize(M);
|
||||||
m_h.resize(M);
|
m_h.resize(M);
|
||||||
m_fifo.resize(N);
|
m_fifo.resize(N);
|
||||||
m_fifo.setZero();
|
m_fifo = ComplexScalar(0,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void feed(ComplexScalar const &x, uint32_t push)
|
void feed(ComplexScalar const &x, uint32_t push)
|
||||||
@@ -86,13 +86,11 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Eigen::internal::set_is_malloc_allowed(true);
|
|
||||||
// Partial filter responses
|
// Partial filter responses
|
||||||
for (i=0; i < m_M; i++)
|
for (i=0; i < m_M; i++)
|
||||||
{
|
{
|
||||||
m_h[i] = FirComplex::processReal(m_coeff.col(i));
|
m_h[i] = FirComplex::processReal(column(m_coeff, i));
|
||||||
}
|
}
|
||||||
// Eigen::internal::set_is_malloc_allowed(false);
|
|
||||||
|
|
||||||
// Combine
|
// Combine
|
||||||
return horner(mu);
|
return horner(mu);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include <cpp/radio/Vector.hpp>
|
#include <cpp/radio/Vector.hpp>
|
||||||
#include <cpp/radio/FirComplex.hpp>
|
#include <cpp/radio/FirComplex.hpp>
|
||||||
#include <fir/fir2.h>
|
#include <fir/fir2.h>
|
||||||
|
#include <memory.h>
|
||||||
|
|
||||||
namespace Radio
|
namespace Radio
|
||||||
{
|
{
|
||||||
@@ -38,7 +39,7 @@ public:
|
|||||||
m_N = N;
|
m_N = N;
|
||||||
m_coeff.resize(N, M);
|
m_coeff.resize(N, M);
|
||||||
m_fifo.resize(N);
|
m_fifo.resize(N);
|
||||||
m_fifo.setZero();
|
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));
|
||||||
@@ -86,7 +87,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return FirComplex::processReal(m_coeff.col(index));
|
return FirComplex::processReal(column(m_coeff, index));
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ public:
|
|||||||
{
|
{
|
||||||
if (coeff)
|
if (coeff)
|
||||||
{
|
{
|
||||||
m_pCoeff[stage](j++) = coeff[i];
|
m_pCoeff[stage][j++] = coeff[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -82,8 +82,8 @@ public:
|
|||||||
{
|
{
|
||||||
for (currStage=0; currStage < m_L; currStage++)
|
for (currStage=0; currStage < m_L; currStage++)
|
||||||
{
|
{
|
||||||
m_pFir[currStage].feed(src(i));
|
m_pFir[currStage].feed(src[i]);
|
||||||
dst(m_L-1-currStage+j) = m_pFir[currStage].processReal(m_pCoeff[currStage]);
|
dst[m_L-1-currStage+j] = m_pFir[currStage].processReal(m_pCoeff[currStage]);
|
||||||
}
|
}
|
||||||
j += m_L;
|
j += m_L;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user