From 5fd4ba805964783b18b2aab37f0efc4195b06f82 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Wed, 21 Oct 2015 19:50:53 -0400 Subject: [PATCH] Some DC-Spike removal magic.. Pay no attention to the spike behind the curtain.. <*|:-) --- src/AppFrame.cpp | 6 ++-- src/process/SpectrumVisualProcessor.cpp | 42 +++++++++++++++++++++++++ src/process/SpectrumVisualProcessor.h | 2 ++ src/sdr/SDRDeviceInfo.cpp | 4 +-- 4 files changed, 50 insertions(+), 4 deletions(-) diff --git a/src/AppFrame.cpp b/src/AppFrame.cpp index c4f6a30..a8560b1 100644 --- a/src/AppFrame.cpp +++ b/src/AppFrame.cpp @@ -786,7 +786,8 @@ void AppFrame::OnIdle(wxIdleEvent& event) { // wxGetApp().getSpectrumDistributor()->run(); SpectrumVisualProcessor *proc = wxGetApp().getSpectrumProcessor(); - + proc->setHideDC(true); + if (spectrumAvgMeter->inputChanged()) { float val = spectrumAvgMeter->getInputValue(); if (val < 0.01) { @@ -812,7 +813,8 @@ void AppFrame::OnIdle(wxIdleEvent& event) { dproc->setCenterFrequency(demodWaterfallCanvas->getCenterFrequency()); SpectrumVisualProcessor *wproc = waterfallDataThread->getProcessor(); - + wproc->setHideDC(true); + if (waterfallSpeedMeter->inputChanged()) { float val = waterfallSpeedMeter->getInputValue(); waterfallSpeedMeter->setLevel(val); diff --git a/src/process/SpectrumVisualProcessor.cpp b/src/process/SpectrumVisualProcessor.cpp index 8dc890d..8efd111 100644 --- a/src/process/SpectrumVisualProcessor.cpp +++ b/src/process/SpectrumVisualProcessor.cpp @@ -8,6 +8,7 @@ SpectrumVisualProcessor::SpectrumVisualProcessor() : lastInputBandwidth(0), last fftSize.store(0); centerFreq.store(0); bandwidth.store(0); + hideDC.store(false); freqShifter = nco_crcf_create(LIQUID_NCO); shiftFrequency = 0; @@ -95,6 +96,11 @@ void SpectrumVisualProcessor::setup(int fftSize_in) { busy_run.unlock(); } +void SpectrumVisualProcessor::setHideDC(bool hideDC) { + this->hideDC.store(hideDC); +} + + void SpectrumVisualProcessor::process() { if (!isOutputEmpty()) { return; @@ -306,6 +312,42 @@ void SpectrumVisualProcessor::process() { output->spectrum_points[i * 2] = ((float) i / (float) iMax); output->spectrum_points[i * 2 + 1] = v; } + + if (hideDC.load()) { // DC-spike removal + long long freqMin = centerFreq-(bandwidth/2); + long long freqMax = centerFreq+(bandwidth/2); + long long zeroPt = (iqData->frequency-freqMin); + + if (freqMin < iqData->frequency && freqMax > iqData->frequency) { + int freqRange = int(freqMax-freqMin); + int freqStep = freqRange/fftSize; + int fftStart = (zeroPt/freqStep)-(2000/freqStep); + int fftEnd = (zeroPt/freqStep)+(2000/freqStep); + +// std::cout << "range:" << freqRange << ", step: " << freqStep << ", start: " << fftStart << ", end: " << fftEnd << std::endl; + + if (fftEnd-fftStart < 2) { + fftEnd++; + fftStart--; + } + + int numSteps = (fftEnd-fftStart); + int halfWay = fftStart+(numSteps/2); + + if ((fftEnd+numSteps/2+1 < fftSize) && (fftStart-numSteps/2-1 >= 0) && (fftEnd > fftStart)) { + int n = 1; + for (int i = fftStart; i < halfWay; i++) { + output->spectrum_points[i * 2 + 1] = output->spectrum_points[(fftStart - n) * 2 + 1]; + n++; + } + n = 1; + for (int i = halfWay; i < fftEnd; i++) { + output->spectrum_points[i * 2 + 1] = output->spectrum_points[(fftEnd + n) * 2 + 1]; + n++; + } + } + } + } output->fft_ceiling = fft_ceil_maa; output->fft_floor = fft_floor_maa; diff --git a/src/process/SpectrumVisualProcessor.h b/src/process/SpectrumVisualProcessor.h index 6b7d079..38da510 100644 --- a/src/process/SpectrumVisualProcessor.h +++ b/src/process/SpectrumVisualProcessor.h @@ -33,6 +33,7 @@ public: int getDesiredInputSize(); void setup(int fftSize); + void setHideDC(bool hideDC); protected: void process(); @@ -68,4 +69,5 @@ private: std::vector resampleBuffer; std::atomic_int desiredInputSize; std::mutex busy_run; + std::atomic_bool hideDC; }; diff --git a/src/sdr/SDRDeviceInfo.cpp b/src/sdr/SDRDeviceInfo.cpp index 8111fc5..a0ad2b8 100644 --- a/src/sdr/SDRDeviceInfo.cpp +++ b/src/sdr/SDRDeviceInfo.cpp @@ -88,9 +88,9 @@ std::vector &SDRDeviceChannel::getSampleRates() { long SDRDeviceChannel::getSampleRateNear(long sampleRate_in) { long returnRate = sampleRates[0]; long sDelta = (long)sampleRate_in-sampleRates[0]; - long minDelta = abs(sDelta); + long minDelta = std::abs(sDelta); for (std::vector::iterator i = sampleRates.begin(); i != sampleRates.end(); i++) { - long thisDelta = abs(sampleRate_in - (*i)); + long thisDelta = std::abs(sampleRate_in - (*i)); if (thisDelta < minDelta) { minDelta = thisDelta; returnRate = (*i);