#include "block.h" #include "gray.h" #include using std::complex; class PAMMapper_gray : public Block { private: InPort < bool > * in; OutPort < complex < double > > * out; Parameter < long > * bitsPar; int bits; complex < double > * alphabet; int symbols; double sqrtp0; public: PAMMapper_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; sqrtp0 = sqrt( (pow(double(symbols), 2.) - 1.) / 12.); alphabet = new complex < double > [symbols]; for (long symbolre = 0; symbolre < symbols; symbolre++) { alphabet[symbolre] = 1 / sqrtp0 * complex < double > ((double(symbolre) - double(symbols) / 2. + 0.5), 0.); } } void go() { long symbol = 0; for (int b = 0; b < bits; b++) { symbol <<= 1; if (in->read()) symbol |= 0x01; } symbol = gray2bin(symbol); out->write(alphabet[symbol]); } void finalize() { delete [] alphabet; } }; PUBLISH(PAMMapper_gray);