diff --git a/lib/hooks/dft.cpp b/lib/hooks/dft.cpp index 994e7f4d0..2b3f84808 100644 --- a/lib/hooks/dft.cpp +++ b/lib/hooks/dft.cpp @@ -58,11 +58,13 @@ protected: std::shared_ptr phasorPhase; std::shared_ptr phasorAmplitude; std::shared_ptr phasorFreq; + std::shared_ptr ppsSigSync; enum WindowType windowType; enum PaddingType paddingType; std::vector> smpMemory; + std::vector ppsMemory;//this is just temporary for debugging std::vector>> dftMatrix; std::vector> dftResults; std::vector filterWindowCoefficents; @@ -75,6 +77,7 @@ protected: double endFreqency; double frequencyResolution; unsigned dftRate; + unsigned ppsIndex; unsigned windowSize; unsigned windowMultiplier; /**< Multiplyer for the window to achieve frequency resolution */ unsigned freqCount; /**< Number of requency bins that are calculated */ @@ -96,6 +99,7 @@ public: windowType(WindowType::NONE), paddingType(PaddingType::ZERO), smpMemory(), + ppsMemory(), dftMatrix(), dftResults(), filterWindowCoefficents(), @@ -107,6 +111,7 @@ public: endFreqency(0), frequencyResolution(0), dftRate(0), + ppsIndex(0), windowSize(0), windowMultiplier(0), freqCount(0), @@ -117,13 +122,17 @@ public: lastDftCal({0, 0}), signalIndex() { - bool debug = false; - if (debug) { + logger = logging.get("hook:dft"); + + format = format_type_lookup("villas.human"); + + if (logger->level() >= SPDLOG_LEVEL_DEBUG) { origSigSync = std::make_shared("/tmp/plot/origSigSync"); windowdSigSync = std::make_shared("/tmp/plot/windowdSigSync"); phasorPhase = std::make_shared("/tmp/plot/phasorPhase"); phasorAmplitude = std::make_shared("/tmp/plot/phasorAmplitude"); phasorFreq = std::make_shared("/tmp/plot/phasorFreq"); + ppsSigSync = std::make_shared("/tmp/plot/ppsSigSync"); } } @@ -153,9 +162,13 @@ public: vlist_push(&signals, phaseSig); vlist_push(&signals, rocofSig); - smpMemory.emplace_back(windowSize, 0.0); + smpMemory.emplace_back(std::vector(windowSize, 0.0)); } + //temporary ppsMemory + ppsMemory.clear(); + ppsMemory.resize(windowSize, 0.0); + /* Calculate how much zero padding ist needed for a needed resolution */ windowMultiplier = ceil(((double)sampleRate / windowSize) / frequencyResolution); @@ -202,7 +215,8 @@ public: "window_type", &windowTypeC, "padding_type", &paddingTypeC, "sync", &syncDft, - "signal_index", &jsonChannelList + "signal_index", &jsonChannelList, + "pps_index", &ppsIndex ); if (ret) throw ConfigError(cfg, err, "node-config-hook-dft"); @@ -277,6 +291,11 @@ public: for (unsigned i = 0; i < signalIndex.size(); i++) smpMemory[i][smpMemPos % windowSize] = smp->data[signalIndex[i]].f; + //debugging for pps signal this should only be temporary + if (ppsSigSync) + ppsMemory[smpMemPos % windowSize] = smp->data[ppsIndex].f; + //debugging for pps signal this should only be temporary + smpMemPos++; bool runDft = false; @@ -289,6 +308,16 @@ public: if (runDft) { for (unsigned i = 0; i < signalIndex.size(); i++) { + + //debugging for pps signal this should only be temporary + if (ppsSigSync) { + double tmpPPSWindow[windowSize]; + for (unsigned i = 0; i< windowSize; i++) + tmpPPSWindow[i] = ppsMemory[(i + smpMemPos) % windowSize]; + ppsSigSync->writeData(windowSize, tmpPPSWindow); + } + //debugging for pps signal this should only be temporary + calculateDft(PaddingType::ZERO, smpMemory[i], smpMemPos); double maxF = 0; double maxA = 0; @@ -313,7 +342,9 @@ public: smp->data[i * 4 + 3].f = 0; /* RoCof */ if (phasorPhase) - phasorPhase->writeDataBinary(1, &(smp->data[i * 4 + 2].f)); + phasorPhase->writeData(1, &(smp->data[i * 4 + 2].f)); + if (phasorAmplitude) + phasorAmplitude->writeData(1, &(smp->data[i * 4 + 1].f)); } } dftCalcCnt++; @@ -356,8 +387,8 @@ public: if (origSigSync) origSigSync->writeDataBinary(windowSize, tmpSmpWindow); - if (dftCalcCnt > 1 && phasorAmplitude) - phasorAmplitude->writeDataBinary(1, &tmpSmpWindow[windowSize - 1]); + //if (dftCalcCnt > 1 && phasorAmplitude) + // phasorAmplitude->writeData(1, &tmpSmpWindow[windowSize - 1]); for (unsigned i = 0; i< windowSize; i++) tmpSmpWindow[i] *= filterWindowCoefficents[i];