From 63ae20781af39e9cb6673e910e99e28f86c6adb0 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Mon, 21 Aug 2017 18:56:25 +0200 Subject: Normalise the CFR FFT --- src/OfdmGenerator.cpp | 12 ++++++++++-- src/OfdmGenerator.h | 6 +++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/OfdmGenerator.cpp b/src/OfdmGenerator.cpp index 41c1c85..8d1a560 100644 --- a/src/OfdmGenerator.cpp +++ b/src/OfdmGenerator.cpp @@ -173,6 +173,10 @@ int OfdmGenerator::process(Buffer* const dataIn, Buffer* dataOut) myNumClip = 0; myNumErrorClip = 0; + // It is not guaranteed that fftw keeps the FFT input vector intact. + // That's why we copy it to the reference. + std::vector reference; + for (size_t i = 0; i < myNbSymbols; ++i) { myFftIn[0][0] = 0; myFftIn[0][1] = 0; @@ -183,7 +187,6 @@ int OfdmGenerator::process(Buffer* const dataIn, Buffer* dataOut) memcpy(&myFftIn[myNegDst], &in[myNegSrc], myNegSize * sizeof(FFT_TYPE)); - std::vector reference; if (myCfr) { reference.resize(mySpacing); memcpy(reference.data(), myFftIn, mySpacing * sizeof(FFT_TYPE)); @@ -240,8 +243,13 @@ void OfdmGenerator::cfr_one_iteration(complexf *symbol, const complexf *referenc const float err_clip_squared = myCfrErrorClip * myCfrErrorClip; for (size_t i = 0; i < mySpacing; i++) { + // FFTW computes an unnormalised trasform, i.e. a FFT-IFFT pair + // or vice-versa give back the original vector scaled by a factor + // FFT-size. Because we're comparing our constellation point + // (calculated with IFFT-clip-FFT) against reference (input to + // the IFFT), we need to divide by our FFT size. const complexf constellation_point = - reinterpret_cast(myCfrPostFft)[i]; + reinterpret_cast(myCfrPostFft)[i] / (float)mySpacing; complexf error = reference[i] - constellation_point; diff --git a/src/OfdmGenerator.h b/src/OfdmGenerator.h index a41d583..ad39f5b 100644 --- a/src/OfdmGenerator.h +++ b/src/OfdmGenerator.h @@ -72,9 +72,9 @@ class OfdmGenerator : public ModCodec, public RemoteControllable fftwf_plan myFftPlan; fftwf_complex *myFftIn, *myFftOut; - size_t myNbSymbols; - size_t myNbCarriers; - size_t mySpacing; + const size_t myNbSymbols; + const size_t myNbCarriers; + const size_t mySpacing; unsigned myPosSrc; unsigned myPosDst; unsigned myPosSize; -- cgit v1.2.3