From 30dab49869bd4b3df86242d6e093bdf0357efdda Mon Sep 17 00:00:00 2001 From: Hexameron Date: Sun, 13 Jul 2014 09:06:43 +0100 Subject: [PATCH] Single sideband. --- include-gpl/dsp/fftfilt.h | 2 +- plugins/channel/ssb/ssbdemod.cpp | 39 +++++++++++++++++++++++------- plugins/channel/ssb/ssbdemod.h | 7 ++++-- plugins/channel/ssb/ssbdemodgui.ui | 4 +-- plugins/channel/usb/usbdemod.cpp | 4 +-- plugins/channel/usb/usbdemod.h | 1 - sdrbase/dsp/fftfilt.cxx | 19 ++++++++++----- 7 files changed, 53 insertions(+), 23 deletions(-) diff --git a/include-gpl/dsp/fftfilt.h b/include-gpl/dsp/fftfilt.h index e5d009383..e135fcdfd 100644 --- a/include-gpl/dsp/fftfilt.h +++ b/include-gpl/dsp/fftfilt.h @@ -48,7 +48,7 @@ public: void create_filter(float f1, float f2); void rtty_filter(float); - int run(const cmplx& in, cmplx **out); + int run(const cmplx& in, cmplx **out, bool usb); }; #endif diff --git a/plugins/channel/ssb/ssbdemod.cpp b/plugins/channel/ssb/ssbdemod.cpp index 8f626a465..e483fff2a 100644 --- a/plugins/channel/ssb/ssbdemod.cpp +++ b/plugins/channel/ssb/ssbdemod.cpp @@ -36,15 +36,18 @@ SSBDemod::SSBDemod(AudioFifo* audioFifo, SampleSink* sampleSink) : m_interpolator.create(16, m_sampleRate, 5000); m_sampleDistanceRemain = (Real)m_sampleRate / 48000.0; - m_lowpass.create(21, 48000, 5000); - m_audioBuffer.resize(512); m_audioBufferFill = 0; m_undersampleCount = 0; + + m_usb = true; + SSBFilter = new fftfilt(0.01, m_Bandwidth / 48000.0, ssbFftLen); + // if (!USBFilter) segfault; } SSBDemod::~SSBDemod() { + if (SSBFilter) delete SSBFilter; } void SSBDemod::configure(MessageQueue* messageQueue, Real Bandwidth, Real volume) @@ -56,6 +59,8 @@ void SSBDemod::configure(MessageQueue* messageQueue, Real Bandwidth, Real volume void SSBDemod::feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly) { Complex ci; + cmplx *sideband; + int n_out; bool consumed; for(SampleVector::const_iterator it = begin; it < end; ++it) { @@ -63,10 +68,14 @@ void SSBDemod::feed(SampleVector::const_iterator begin, SampleVector::const_iter c *= m_nco.nextIQ(); consumed = false; - // could squelch audio if RTL_SDR samplerate is not being fully decimated. if(m_interpolator.interpolate(&m_sampleDistanceRemain, c, &consumed, &ci)) { - Real demod = ci.imag() + ci.real(); - demod = 32768.0 * m_lowpass.filter(demod * 0.7); + n_out = SSBFilter->run(ci, &sideband, m_usb); + m_sampleDistanceRemain += (Real)m_sampleRate / 48000.0; + } else + n_out = 0; + + for (int i = 0; i < n_out; i++) { + Real demod = (sideband[i].real() + sideband[i].imag()) * 0.7 * 32768.0; // Downsample by 4x for audio display if (!(m_undersampleCount++ & 3)) @@ -80,7 +89,6 @@ void SSBDemod::feed(SampleVector::const_iterator begin, SampleVector::const_iter uint res = m_audioFifo->write((const quint8*)&m_audioBuffer[0], m_audioBufferFill, 1); m_audioBufferFill = 0; } - m_sampleDistanceRemain += (Real)m_sampleRate / 48000.0; } } if(m_audioFifo->write((const quint8*)&m_audioBuffer[0], m_audioBufferFill, 0) != m_audioBufferFill) @@ -102,6 +110,8 @@ void SSBDemod::stop() bool SSBDemod::handleMessage(Message* cmd) { + float band; + if(DSPSignalNotification::match(cmd)) { DSPSignalNotification* signal = (DSPSignalNotification*)cmd; qDebug("%d samples/sec, %lld Hz offset", signal->getSampleRate(), signal->getFrequencyOffset()); @@ -113,9 +123,20 @@ bool SSBDemod::handleMessage(Message* cmd) return true; } else if(MsgConfigureSSBDemod::match(cmd)) { MsgConfigureSSBDemod* cfg = (MsgConfigureSSBDemod*)cmd; - m_Bandwidth = cfg->getBandwidth(); - m_interpolator.create(16, m_sampleRate, m_Bandwidth); - m_lowpass.create(21, 48000, cfg->getBandwidth()); + + band = cfg->getBandwidth(); + if (band < 0) { + band = -band; + m_usb = false; + } else + m_usb = true; + if (band < 500.0f) + band = 500.0f; + m_Bandwidth = band; + + m_interpolator.create(16, m_sampleRate, band * 2.0f); + SSBFilter->create_filter(0.3f / 48.0f, m_Bandwidth / 48000.0f); + m_volume = cfg->getVolume(); m_volume *= m_volume * 0.1; cmd->completed(); diff --git a/plugins/channel/ssb/ssbdemod.h b/plugins/channel/ssb/ssbdemod.h index fd4427d69..0557a0ff8 100644 --- a/plugins/channel/ssb/ssbdemod.h +++ b/plugins/channel/ssb/ssbdemod.h @@ -22,10 +22,12 @@ #include "dsp/samplesink.h" #include "dsp/nco.h" #include "dsp/interpolator.h" -#include "dsp/lowpass.h" +#include "dsp/fftfilt.h" #include "audio/audiofifo.h" #include "util/message.h" +#define ssbFftLen 1024 + class AudioFifo; class SSBDemod : public SampleSink { @@ -75,11 +77,12 @@ private: int m_undersampleCount; int m_sampleRate; int m_frequency; + bool m_usb; NCO m_nco; Interpolator m_interpolator; Real m_sampleDistanceRemain; - Lowpass m_lowpass; + fftfilt* SSBFilter; AudioVector m_audioBuffer; uint m_audioBufferFill; diff --git a/plugins/channel/ssb/ssbdemodgui.ui b/plugins/channel/ssb/ssbdemodgui.ui index 2dfed425b..114986e00 100644 --- a/plugins/channel/ssb/ssbdemodgui.ui +++ b/plugins/channel/ssb/ssbdemodgui.ui @@ -42,10 +42,10 @@ - 1 + -8 - 20 + 8 1 diff --git a/plugins/channel/usb/usbdemod.cpp b/plugins/channel/usb/usbdemod.cpp index c669d7288..6a1506ce2 100644 --- a/plugins/channel/usb/usbdemod.cpp +++ b/plugins/channel/usb/usbdemod.cpp @@ -68,7 +68,7 @@ void USBDemod::feed(SampleVector::const_iterator begin, SampleVector::const_iter b += it->imag(); c = Complex(a / 65536.0, b / 65536.0); - n_out = USBFilter->run(c, &sideband); + n_out = USBFilter->run(c, &sideband, true); for (int i = 0; i < n_out; i++) { Real demod = (sideband[i].real() + sideband[i].imag()) * 0.7 * 32768.0; @@ -113,7 +113,7 @@ bool USBDemod::handleMessage(Message* cmd) } else if(MsgConfigureUSBDemod::match(cmd)) { MsgConfigureUSBDemod* cfg = (MsgConfigureUSBDemod*)cmd; m_Bandwidth = cfg->getBandwidth(); - USBFilter->create_filter(0.01, m_Bandwidth / 48000.0); + USBFilter->create_filter(0.3 / 48.0, m_Bandwidth / 48000.0); m_volume = cfg->getVolume(); m_volume *= m_volume * 0.1; cmd->completed(); diff --git a/plugins/channel/usb/usbdemod.h b/plugins/channel/usb/usbdemod.h index f0440cd74..4abf10730 100644 --- a/plugins/channel/usb/usbdemod.h +++ b/plugins/channel/usb/usbdemod.h @@ -22,7 +22,6 @@ #include "dsp/samplesink.h" #include "dsp/nco.h" #include "dsp/interpolator.h" -#include "dsp/lowpass.h" #include "dsp/fftfilt.h" #include "audio/audiofifo.h" #include "util/message.h" diff --git a/sdrbase/dsp/fftfilt.cxx b/sdrbase/dsp/fftfilt.cxx index 1de6a2aae..1c4acf9d8 100644 --- a/sdrbase/dsp/fftfilt.cxx +++ b/sdrbase/dsp/fftfilt.cxx @@ -144,7 +144,7 @@ void fftfilt::create_filter(float f1, float f2) } // Filter with fast convolution (overlap-add algorithm). -int fftfilt::run(const cmplx & in, cmplx **out) +int fftfilt::run(const cmplx & in, cmplx **out, bool usb) { timedata[inptr++] = in; @@ -155,12 +155,19 @@ int fftfilt::run(const cmplx & in, cmplx **out) memcpy(freqdata, timedata, flen * sizeof(cmplx)); fft->ComplexFFT(freqdata); - // Discard negative frequencies for ssb - for (int i = 0; i < flen2; i++) { - freqdata[i] *= filter[i]; - freqdata[flen2 + i] = 0; - } + // Discard frequencies for ssb + if ( usb ) + for (int i = 0; i < flen2; i++) { + freqdata[i] *= filter[i]; + freqdata[flen2 + i] = 0; + } + else + for (int i = 0; i < flen2; i++) { + freqdata[i] = 0; + freqdata[flen2 + i] *= filter[flen2 + i]; + } + // in-place FFT: freqdata overwritten with filtered timedata fft->InverseComplexFFT(freqdata); // overlap and add