mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-22 08:04:49 -05:00
Single sideband.
This commit is contained in:
parent
84d53dde4e
commit
30dab49869
@ -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
|
||||
|
@ -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();
|
||||
|
@ -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<Real> m_lowpass;
|
||||
fftfilt* SSBFilter;
|
||||
|
||||
AudioVector m_audioBuffer;
|
||||
uint m_audioBufferFill;
|
||||
|
@ -42,10 +42,10 @@
|
||||
<item row="0" column="1">
|
||||
<widget class="QSlider" name="BW">
|
||||
<property name="minimum">
|
||||
<number>1</number>
|
||||
<number>-8</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>20</number>
|
||||
<number>8</number>
|
||||
</property>
|
||||
<property name="pageStep">
|
||||
<number>1</number>
|
||||
|
@ -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();
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user