From 8f01fd659ecb0b0bf4dab304cdd6e4906c55a4f2 Mon Sep 17 00:00:00 2001 From: Alexander Chemeris Date: Mon, 29 Jun 2015 20:46:46 -0400 Subject: Transceiver: Better abstraction for the quality calculations. --- Transceiver52M/Transceiver.cpp | 49 +++++++++++++++++++++--------------------- Transceiver52M/Transceiver.h | 21 +++++++++++++++--- 2 files changed, 42 insertions(+), 28 deletions(-) diff --git a/Transceiver52M/Transceiver.cpp b/Transceiver52M/Transceiver.cpp index d7b2da3..b9902c2 100644 --- a/Transceiver52M/Transceiver.cpp +++ b/Transceiver52M/Transceiver.cpp @@ -637,11 +637,11 @@ void writeToFile(signalVector *burst, const GSM::Time &time, size_t chan, const SoftVector *Transceiver::demodulate(TransceiverState *state, signalVector &burst, complex amp, float toa, size_t tn, bool equalize, - GSM::Time &wTime, size_t chan) + GSM::Time &wTime, size_t chan, + Transceiver::BurstQuality *qual) { signalVector *aligned, *bit_aligned=NULL; SoftVector *bits; - bool estimateQuality = true; if (equalize) { scaleVector(burst, complex(1.0, 0.0) / amp); @@ -654,7 +654,7 @@ SoftVector *Transceiver::demodulate(TransceiverState *state, aligned = alignBurst(burst, amp, toa); - if (estimateQuality) { + if (qual) { /* "aligned" burst has samples exactly between bits. * Delay it by 1/2 bit more to get samples aligned to bit positions. */ bit_aligned = delayVector(aligned, NULL, 0.5); @@ -666,9 +666,9 @@ SoftVector *Transceiver::demodulate(TransceiverState *state, bits = demodulateBurst(*aligned, mSPSRx); - if (estimateQuality) { + if (qual) { /* Estimate signal quality */ - estimateBurstQuality(bits->segment(0, gSlotLen).sliced(), bit_aligned, wTime, chan); + estimateBurstQuality(bits->segment(0, gSlotLen).sliced(), bit_aligned, wTime, chan, *qual); delete bit_aligned; } @@ -682,7 +682,8 @@ SoftVector *Transceiver::demodulate(TransceiverState *state, */ SoftVector *Transceiver::pullRadioVector(GSM::Time &wTime, double &RSSI, bool &isRssiValid, double &timingOffset, double &noise, - size_t chan) + size_t chan, + Transceiver::BurstQuality *qual) { int success; bool equalize = false; @@ -777,7 +778,7 @@ SoftVector *Transceiver::pullRadioVector(GSM::Time &wTime, double &RSSI, bool &i if (equalize && (type != TSC)) equalize = false; - bits = demodulate(state, *burst, amp, toa, time.TN(), equalize, time, chan); + bits = demodulate(state, *burst, amp, toa, time.TN(), equalize, time, chan, qual); delete radio_burst; return bits; @@ -1041,13 +1042,10 @@ inline float vectorRMS(const Vector &vec) } void Transceiver::estimateBurstQuality(const BitVector &wBits, signalVector *received, - const GSM::Time &wTime, size_t chan) + const GSM::Time &wTime, size_t chan, + Transceiver::BurstQuality &qual) { signalVector *burst; - Vector phase_err(148); // 148 bits - burst length including guard bits - Vector phase_err_deg(148); // 148 bits - burst length including guard bits - int phase_err_max; - float phase_err_rms; // this code supports only 4 SPS modulation // we also assume that received vector is 1 SPS @@ -1065,21 +1063,17 @@ void Transceiver::estimateBurstQuality(const BitVector &wBits, signalVector *rec } // calculate phase error for each bit - for (size_t i=0; igetEnergy() + << " peak: " << std::setw(6) << std::setprecision(1) << qual.phase_err_deg[qual.phase_err_max_idx] +// << " @bit " << std::setw(3) << qual.phase_err_max_idx + << " RMS: " << std::setw(6) << std::setprecision(1) << rad2deg(qual.phase_err_rms) +// << " bits: " << std::setw(5) << std::setprecision(1) << qual.phase_err_deg +// << " energy: " << std::setw(5) << std::setprecision(2) << rxBurst->getEnergy() << " bits: " << *rxBurst; char burstString[gSlotLen+10]; diff --git a/Transceiver52M/Transceiver.h b/Transceiver52M/Transceiver.h index 29427ca..9c71b3a 100644 --- a/Transceiver52M/Transceiver.h +++ b/Transceiver52M/Transceiver.h @@ -157,6 +157,20 @@ public: }; private: + + struct BurstQuality { + BurstQuality() + // 148 bits - burst length including guard bits + : phase_err(148), phase_err_deg(148) + {} + + Vector phase_err; + Vector phase_err_deg; + int phase_err_max_idx; + float phase_err_max; + float phase_err_rms; + }; + int mBasePort; std::string mAddr; @@ -197,7 +211,7 @@ private: /** Pull and demodulate a burst from the receive FIFO */ SoftVector *pullRadioVector(GSM::Time &wTime, double &RSSI, bool &isRssiValid, double &timingOffset, double &noise, - size_t chan = 0); + size_t chan = 0, BurstQuality *qual = NULL); /** Set modulus for specific timeslot */ void setModulus(size_t timeslot, size_t chan); @@ -222,7 +236,8 @@ private: SoftVector *demodulate(TransceiverState *state, signalVector &burst, complex amp, float toa, size_t tn, bool equalize, - GSM::Time &wTime, size_t chan); + GSM::Time &wTime, size_t chan, + BurstQuality *qual=NULL); int mSPSTx; ///< number of samples per Tx symbol int mSPSRx; ///< number of samples per Rx symbol @@ -257,7 +272,7 @@ private: protected: /** Estimate received burst quality and print it to debug output */ - void estimateBurstQuality(const BitVector &wBits, signalVector *received, const GSM::Time &wTime, size_t chan); + void estimateBurstQuality(const BitVector &wBits, signalVector *received, const GSM::Time &wTime, size_t chan, BurstQuality &qual); /** drive lower receive I/O and burst generation */ void driveReceiveRadio(); -- cgit v1.2.3