#include "block.h" #include "gray.h" #include using std::complex; class DPSKMapper_gray : public Block { private: InPort < bool > * in; OutPort < complex < double > > * out; Parameter < long > * bitsPar; long bits; long lastsymbol; complex < double > * alphabet; int symbols; public: DPSKMapper_gray(const Blockopt & blockopt) : Block(blockopt) {} void makeParameters() { bitsPar = new Parameter < long > (this, "bits", 2); } void makeIOPorts() { in = new InPort < bool > (this, "in", bitsPar->value()); out = new OutPort < complex < double > > (this, "out", 1); } void initialize() { bits = bitsPar->value(); symbols = 1 << bits; alphabet = new complex < double > [symbols]; for (long s = 0; s < symbols; s++) alphabet[s] = complex < double > (cos(2. * M_PI * double(s + 0.5) / symbols), sin(2. * M_PI * double(s + 0.5) / symbols)); lastsymbol = 0; } void go() { long symbol = 0; for (int b = 0; b < bits; b++) { symbol <<= 1; if (in->read()) symbol |= 0x01; } symbol = gray2bin(symbol); lastsymbol = (lastsymbol + symbol) % symbols; out->write(alphabet[lastsymbol]); } void finalize() { delete [] alphabet; } }; PUBLISH(DPSKMapper_gray);