From edbe93987d14e3acc7331207f66ac6233bbbb4e1 Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Mon, 22 Dec 2014 13:02:02 +0000 Subject: [PATCH] - initial version git-svn-id: http://moon:8086/svn/software/trunk/libsrc/cpp@104 b431acfa-c32f-4a4a-93f1-934dc6c82436 --- radio/Nco.hpp | 144 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 radio/Nco.hpp diff --git a/radio/Nco.hpp b/radio/Nco.hpp new file mode 100644 index 0000000..03eeb79 --- /dev/null +++ b/radio/Nco.hpp @@ -0,0 +1,144 @@ +/* + * File: Nco.hpp + * Author: jens + * + * Created on 22. Dezember 2014, 12:51 + */ + +#ifndef NCO_HPP +#define NCO_HPP + +#include "radio/Vector.hpp" + +namespace Radio +{ + +class Nco +{ +public: + Nco(RealScalar omega=0, RealScalar phi=0) + : m_omega(omega) + , m_phi(phi) + { + + } + ~Nco() + { + + } + void init(RealScalar omega=0, RealScalar phi=0) + { + m_omega = omega; + m_phi = phi; + } + + void setOmega(RealScalar omega) + { + m_omega = omega; + } + + void setPhi(RealScalar phi) + { + m_phi = phi; + } + + RealScalar getOmega() + { + return m_omega; + } + + RealScalar getPhi() + { + return m_phi; + } + + void process(RealScalar dOmega, RealScalar dPhi) + { + m_phi += (m_omega + dOmega); + + if (m_phi < -(radio_float_t)0.5) + m_phi += (radio_float_t)1.0; + + if (m_phi >= +(radio_float_t)0.5) + m_phi -= (radio_float_t)1.0; + + m_state = ComplexScalar((RealScalar)cos(2.0*PI*m_phi + dPhi), -(RealScalar)sin(2.0*PI*m_phi + dPhi)); + } + + ComplexScalar mixRealComplexS(RealScalar const &src, RealScalar const &gain) + { + ComplexScalar dst(gain*src, 0); + + return m_state * dst; + } + + RealScalar mixComplexRealS(ComplexScalar const &src, ComplexScalar const &gain) + { + return gain.real()*m_state.real()*src.real() + gain.imag()*m_state.imag()*src.imag(); + } + + ComplexScalar mixComplexS(ComplexScalar const &src, ComplexScalar const &gain) + { + ComplexScalar y(src.real()*gain.real(), src.imag()*gain.imag()); + + return y * m_state; + } + + void mixRealComplexV(CVec &dst, RVec const &src, RealScalar gain, uint32_t len) + { + uint32_t i; + + i = 0; + while (len--) + { + + dst(i) = mixRealComplexS(src(i), gain); + + // NCO update + process(0, 0); + i++; + } + } + + void mixComplexRealV(RVec &dst, CVec const &src, ComplexScalar const &gain, uint32_t len) + { + uint32_t i; + + i = 0; + while (len--) + { + + dst(i) = mixComplexRealS(src(i), gain); + + // NCO update + process(0, 0); + i++; + } + } + + void mixComplexV(CVec &srcDst, ComplexScalar const &gain, uint32_t len) + { + uint32_t i; + + i = 0; + while (len--) + { + srcDst(i) = mixComplexS(srcDst(i), gain); + + // NCO update + process(0, 0); + i++; + } + } + +private: + RealScalar m_omega; + RealScalar m_phi; + ComplexScalar m_state; +}; + +} // ::Radio + + +#endif /* NCO_HPP */ +