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 create_filter(float f1, float f2);
|
||||||
void rtty_filter(float);
|
void rtty_filter(float);
|
||||||
|
|
||||||
int run(const cmplx& in, cmplx **out);
|
int run(const cmplx& in, cmplx **out, bool usb);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -36,15 +36,18 @@ SSBDemod::SSBDemod(AudioFifo* audioFifo, SampleSink* sampleSink) :
|
|||||||
m_interpolator.create(16, m_sampleRate, 5000);
|
m_interpolator.create(16, m_sampleRate, 5000);
|
||||||
m_sampleDistanceRemain = (Real)m_sampleRate / 48000.0;
|
m_sampleDistanceRemain = (Real)m_sampleRate / 48000.0;
|
||||||
|
|
||||||
m_lowpass.create(21, 48000, 5000);
|
|
||||||
|
|
||||||
m_audioBuffer.resize(512);
|
m_audioBuffer.resize(512);
|
||||||
m_audioBufferFill = 0;
|
m_audioBufferFill = 0;
|
||||||
m_undersampleCount = 0;
|
m_undersampleCount = 0;
|
||||||
|
|
||||||
|
m_usb = true;
|
||||||
|
SSBFilter = new fftfilt(0.01, m_Bandwidth / 48000.0, ssbFftLen);
|
||||||
|
// if (!USBFilter) segfault;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSBDemod::~SSBDemod()
|
SSBDemod::~SSBDemod()
|
||||||
{
|
{
|
||||||
|
if (SSBFilter) delete SSBFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SSBDemod::configure(MessageQueue* messageQueue, Real Bandwidth, Real volume)
|
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)
|
void SSBDemod::feed(SampleVector::const_iterator begin, SampleVector::const_iterator end, bool positiveOnly)
|
||||||
{
|
{
|
||||||
Complex ci;
|
Complex ci;
|
||||||
|
cmplx *sideband;
|
||||||
|
int n_out;
|
||||||
bool consumed;
|
bool consumed;
|
||||||
|
|
||||||
for(SampleVector::const_iterator it = begin; it < end; ++it) {
|
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();
|
c *= m_nco.nextIQ();
|
||||||
|
|
||||||
consumed = false;
|
consumed = false;
|
||||||
// could squelch audio if RTL_SDR samplerate is not being fully decimated.
|
|
||||||
if(m_interpolator.interpolate(&m_sampleDistanceRemain, c, &consumed, &ci)) {
|
if(m_interpolator.interpolate(&m_sampleDistanceRemain, c, &consumed, &ci)) {
|
||||||
Real demod = ci.imag() + ci.real();
|
n_out = SSBFilter->run(ci, &sideband, m_usb);
|
||||||
demod = 32768.0 * m_lowpass.filter(demod * 0.7);
|
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
|
// Downsample by 4x for audio display
|
||||||
if (!(m_undersampleCount++ & 3))
|
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);
|
uint res = m_audioFifo->write((const quint8*)&m_audioBuffer[0], m_audioBufferFill, 1);
|
||||||
m_audioBufferFill = 0;
|
m_audioBufferFill = 0;
|
||||||
}
|
}
|
||||||
m_sampleDistanceRemain += (Real)m_sampleRate / 48000.0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(m_audioFifo->write((const quint8*)&m_audioBuffer[0], m_audioBufferFill, 0) != m_audioBufferFill)
|
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)
|
bool SSBDemod::handleMessage(Message* cmd)
|
||||||
{
|
{
|
||||||
|
float band;
|
||||||
|
|
||||||
if(DSPSignalNotification::match(cmd)) {
|
if(DSPSignalNotification::match(cmd)) {
|
||||||
DSPSignalNotification* signal = (DSPSignalNotification*)cmd;
|
DSPSignalNotification* signal = (DSPSignalNotification*)cmd;
|
||||||
qDebug("%d samples/sec, %lld Hz offset", signal->getSampleRate(), signal->getFrequencyOffset());
|
qDebug("%d samples/sec, %lld Hz offset", signal->getSampleRate(), signal->getFrequencyOffset());
|
||||||
@ -113,9 +123,20 @@ bool SSBDemod::handleMessage(Message* cmd)
|
|||||||
return true;
|
return true;
|
||||||
} else if(MsgConfigureSSBDemod::match(cmd)) {
|
} else if(MsgConfigureSSBDemod::match(cmd)) {
|
||||||
MsgConfigureSSBDemod* cfg = (MsgConfigureSSBDemod*)cmd;
|
MsgConfigureSSBDemod* cfg = (MsgConfigureSSBDemod*)cmd;
|
||||||
m_Bandwidth = cfg->getBandwidth();
|
|
||||||
m_interpolator.create(16, m_sampleRate, m_Bandwidth);
|
band = cfg->getBandwidth();
|
||||||
m_lowpass.create(21, 48000, 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 = cfg->getVolume();
|
||||||
m_volume *= m_volume * 0.1;
|
m_volume *= m_volume * 0.1;
|
||||||
cmd->completed();
|
cmd->completed();
|
||||||
|
@ -22,10 +22,12 @@
|
|||||||
#include "dsp/samplesink.h"
|
#include "dsp/samplesink.h"
|
||||||
#include "dsp/nco.h"
|
#include "dsp/nco.h"
|
||||||
#include "dsp/interpolator.h"
|
#include "dsp/interpolator.h"
|
||||||
#include "dsp/lowpass.h"
|
#include "dsp/fftfilt.h"
|
||||||
#include "audio/audiofifo.h"
|
#include "audio/audiofifo.h"
|
||||||
#include "util/message.h"
|
#include "util/message.h"
|
||||||
|
|
||||||
|
#define ssbFftLen 1024
|
||||||
|
|
||||||
class AudioFifo;
|
class AudioFifo;
|
||||||
|
|
||||||
class SSBDemod : public SampleSink {
|
class SSBDemod : public SampleSink {
|
||||||
@ -75,11 +77,12 @@ private:
|
|||||||
int m_undersampleCount;
|
int m_undersampleCount;
|
||||||
int m_sampleRate;
|
int m_sampleRate;
|
||||||
int m_frequency;
|
int m_frequency;
|
||||||
|
bool m_usb;
|
||||||
|
|
||||||
NCO m_nco;
|
NCO m_nco;
|
||||||
Interpolator m_interpolator;
|
Interpolator m_interpolator;
|
||||||
Real m_sampleDistanceRemain;
|
Real m_sampleDistanceRemain;
|
||||||
Lowpass<Real> m_lowpass;
|
fftfilt* SSBFilter;
|
||||||
|
|
||||||
AudioVector m_audioBuffer;
|
AudioVector m_audioBuffer;
|
||||||
uint m_audioBufferFill;
|
uint m_audioBufferFill;
|
||||||
|
@ -42,10 +42,10 @@
|
|||||||
<item row="0" column="1">
|
<item row="0" column="1">
|
||||||
<widget class="QSlider" name="BW">
|
<widget class="QSlider" name="BW">
|
||||||
<property name="minimum">
|
<property name="minimum">
|
||||||
<number>1</number>
|
<number>-8</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="maximum">
|
<property name="maximum">
|
||||||
<number>20</number>
|
<number>8</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="pageStep">
|
<property name="pageStep">
|
||||||
<number>1</number>
|
<number>1</number>
|
||||||
|
@ -68,7 +68,7 @@ void USBDemod::feed(SampleVector::const_iterator begin, SampleVector::const_iter
|
|||||||
b += it->imag();
|
b += it->imag();
|
||||||
c = Complex(a / 65536.0, b / 65536.0);
|
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++) {
|
for (int i = 0; i < n_out; i++) {
|
||||||
Real demod = (sideband[i].real() + sideband[i].imag()) * 0.7 * 32768.0;
|
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)) {
|
} else if(MsgConfigureUSBDemod::match(cmd)) {
|
||||||
MsgConfigureUSBDemod* cfg = (MsgConfigureUSBDemod*)cmd;
|
MsgConfigureUSBDemod* cfg = (MsgConfigureUSBDemod*)cmd;
|
||||||
m_Bandwidth = cfg->getBandwidth();
|
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 = cfg->getVolume();
|
||||||
m_volume *= m_volume * 0.1;
|
m_volume *= m_volume * 0.1;
|
||||||
cmd->completed();
|
cmd->completed();
|
||||||
|
@ -22,7 +22,6 @@
|
|||||||
#include "dsp/samplesink.h"
|
#include "dsp/samplesink.h"
|
||||||
#include "dsp/nco.h"
|
#include "dsp/nco.h"
|
||||||
#include "dsp/interpolator.h"
|
#include "dsp/interpolator.h"
|
||||||
#include "dsp/lowpass.h"
|
|
||||||
#include "dsp/fftfilt.h"
|
#include "dsp/fftfilt.h"
|
||||||
#include "audio/audiofifo.h"
|
#include "audio/audiofifo.h"
|
||||||
#include "util/message.h"
|
#include "util/message.h"
|
||||||
|
@ -144,7 +144,7 @@ void fftfilt::create_filter(float f1, float f2)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Filter with fast convolution (overlap-add algorithm).
|
// 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;
|
timedata[inptr++] = in;
|
||||||
|
|
||||||
@ -155,12 +155,19 @@ int fftfilt::run(const cmplx & in, cmplx **out)
|
|||||||
memcpy(freqdata, timedata, flen * sizeof(cmplx));
|
memcpy(freqdata, timedata, flen * sizeof(cmplx));
|
||||||
fft->ComplexFFT(freqdata);
|
fft->ComplexFFT(freqdata);
|
||||||
|
|
||||||
// Discard negative frequencies for ssb
|
// Discard frequencies for ssb
|
||||||
for (int i = 0; i < flen2; i++) {
|
if ( usb )
|
||||||
freqdata[i] *= filter[i];
|
for (int i = 0; i < flen2; i++) {
|
||||||
freqdata[flen2 + i] = 0;
|
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);
|
fft->InverseComplexFFT(freqdata);
|
||||||
|
|
||||||
// overlap and add
|
// overlap and add
|
||||||
|
Loading…
Reference in New Issue
Block a user