Some DC-Spike removal magic..

Pay no attention to the spike behind the curtain.. <*|:-)
This commit is contained in:
Charles J. Cliffe 2015-10-21 19:50:53 -04:00
parent fcbe2723e6
commit 5fd4ba8059
4 changed files with 50 additions and 4 deletions

View File

@ -786,7 +786,8 @@ void AppFrame::OnIdle(wxIdleEvent& event) {
// wxGetApp().getSpectrumDistributor()->run(); // wxGetApp().getSpectrumDistributor()->run();
SpectrumVisualProcessor *proc = wxGetApp().getSpectrumProcessor(); SpectrumVisualProcessor *proc = wxGetApp().getSpectrumProcessor();
proc->setHideDC(true);
if (spectrumAvgMeter->inputChanged()) { if (spectrumAvgMeter->inputChanged()) {
float val = spectrumAvgMeter->getInputValue(); float val = spectrumAvgMeter->getInputValue();
if (val < 0.01) { if (val < 0.01) {
@ -812,7 +813,8 @@ void AppFrame::OnIdle(wxIdleEvent& event) {
dproc->setCenterFrequency(demodWaterfallCanvas->getCenterFrequency()); dproc->setCenterFrequency(demodWaterfallCanvas->getCenterFrequency());
SpectrumVisualProcessor *wproc = waterfallDataThread->getProcessor(); SpectrumVisualProcessor *wproc = waterfallDataThread->getProcessor();
wproc->setHideDC(true);
if (waterfallSpeedMeter->inputChanged()) { if (waterfallSpeedMeter->inputChanged()) {
float val = waterfallSpeedMeter->getInputValue(); float val = waterfallSpeedMeter->getInputValue();
waterfallSpeedMeter->setLevel(val); waterfallSpeedMeter->setLevel(val);

View File

@ -8,6 +8,7 @@ SpectrumVisualProcessor::SpectrumVisualProcessor() : lastInputBandwidth(0), last
fftSize.store(0); fftSize.store(0);
centerFreq.store(0); centerFreq.store(0);
bandwidth.store(0); bandwidth.store(0);
hideDC.store(false);
freqShifter = nco_crcf_create(LIQUID_NCO); freqShifter = nco_crcf_create(LIQUID_NCO);
shiftFrequency = 0; shiftFrequency = 0;
@ -95,6 +96,11 @@ void SpectrumVisualProcessor::setup(int fftSize_in) {
busy_run.unlock(); busy_run.unlock();
} }
void SpectrumVisualProcessor::setHideDC(bool hideDC) {
this->hideDC.store(hideDC);
}
void SpectrumVisualProcessor::process() { void SpectrumVisualProcessor::process() {
if (!isOutputEmpty()) { if (!isOutputEmpty()) {
return; return;
@ -306,6 +312,42 @@ void SpectrumVisualProcessor::process() {
output->spectrum_points[i * 2] = ((float) i / (float) iMax); output->spectrum_points[i * 2] = ((float) i / (float) iMax);
output->spectrum_points[i * 2 + 1] = v; 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_ceiling = fft_ceil_maa;
output->fft_floor = fft_floor_maa; output->fft_floor = fft_floor_maa;

View File

@ -33,6 +33,7 @@ public:
int getDesiredInputSize(); int getDesiredInputSize();
void setup(int fftSize); void setup(int fftSize);
void setHideDC(bool hideDC);
protected: protected:
void process(); void process();
@ -68,4 +69,5 @@ private:
std::vector<liquid_float_complex> resampleBuffer; std::vector<liquid_float_complex> resampleBuffer;
std::atomic_int desiredInputSize; std::atomic_int desiredInputSize;
std::mutex busy_run; std::mutex busy_run;
std::atomic_bool hideDC;
}; };

View File

@ -88,9 +88,9 @@ std::vector<long> &SDRDeviceChannel::getSampleRates() {
long SDRDeviceChannel::getSampleRateNear(long sampleRate_in) { long SDRDeviceChannel::getSampleRateNear(long sampleRate_in) {
long returnRate = sampleRates[0]; long returnRate = sampleRates[0];
long sDelta = (long)sampleRate_in-sampleRates[0]; long sDelta = (long)sampleRate_in-sampleRates[0];
long minDelta = abs(sDelta); long minDelta = std::abs(sDelta);
for (std::vector<long>::iterator i = sampleRates.begin(); i != sampleRates.end(); i++) { for (std::vector<long>::iterator i = sampleRates.begin(); i != sampleRates.end(); i++) {
long thisDelta = abs(sampleRate_in - (*i)); long thisDelta = std::abs(sampleRate_in - (*i));
if (thisDelta < minDelta) { if (thisDelta < minDelta) {
minDelta = thisDelta; minDelta = thisDelta;
returnRate = (*i); returnRate = (*i);