1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-16 13:21:50 -05:00

Channel Analyzer NG: implemented channel rational downsampler

This commit is contained in:
f4exb 2017-03-01 06:03:04 +01:00
parent f2ec2c9f1d
commit 2f6cf815ee
2 changed files with 19 additions and 7 deletions

View File

@ -33,6 +33,7 @@ ChannelAnalyzerNG::ChannelAnalyzerNG(BasebandSampleSink* sampleSink) :
m_sum = 0; m_sum = 0;
m_usb = true; m_usb = true;
m_magsq = 0; m_magsq = 0;
m_useInterpolator = false;
m_interpolatorDistance = 1.0f; m_interpolatorDistance = 1.0f;
m_interpolatorDistanceRemain = 0.0f; m_interpolatorDistanceRemain = 0.0f;
SSBFilter = new fftfilt(m_config.m_LowCutoff / m_config.m_inputSampleRate, m_config.m_Bandwidth / m_config.m_inputSampleRate, ssbFftLen); SSBFilter = new fftfilt(m_config.m_LowCutoff / m_config.m_inputSampleRate, m_config.m_Bandwidth / m_config.m_inputSampleRate, ssbFftLen);
@ -60,21 +61,30 @@ void ChannelAnalyzerNG::configure(MessageQueue* messageQueue,
void ChannelAnalyzerNG::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly) void ChannelAnalyzerNG::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly)
{ {
fftfilt::cmplx *sideband; fftfilt::cmplx *sideband;
int n_out; Complex ci;
int decim = 1<<m_running.m_spanLog2;
unsigned char decim_mask = decim - 1; // counter LSB bit mask for decimation by 2^(m_scaleLog2 - 1)
m_settingsMutex.lock(); m_settingsMutex.lock();
for(SampleVector::const_iterator it = begin; it < end; ++it) for(SampleVector::const_iterator it = begin; it < end; ++it)
{ {
//Complex c(it->real() / 32768.0f, it->imag() / 32768.0f);
Complex c(it->real(), it->imag()); Complex c(it->real(), it->imag());
c *= m_nco.nextIQ(); c *= m_nco.nextIQ();
processOneSample(c, sideband);
if (m_useInterpolator)
{
if (m_interpolator.decimate(&m_interpolatorDistanceRemain, c, &ci))
{
processOneSample(ci, sideband);
m_interpolatorDistanceRemain += m_interpolatorDistance;
}
}
else
{
processOneSample(c, sideband);
}
} }
if(m_sampleSink != NULL) if(m_sampleSink != 0)
{ {
m_sampleSink->feed(m_sampleBuffer.begin(), m_sampleBuffer.end(), m_running.m_ssb); // m_ssb = positive only m_sampleSink->feed(m_sampleBuffer.begin(), m_sampleBuffer.end(), m_running.m_ssb); // m_ssb = positive only
} }
@ -162,6 +172,7 @@ void ChannelAnalyzerNG::apply(bool force)
m_interpolator.create(16, m_config.m_inputSampleRate, m_config.m_inputSampleRate / 2.2); m_interpolator.create(16, m_config.m_inputSampleRate, m_config.m_inputSampleRate / 2.2);
m_interpolatorDistanceRemain = 0.0f; m_interpolatorDistanceRemain = 0.0f;
m_interpolatorDistance = (Real) m_config.m_inputSampleRate / (Real) m_config.m_channelSampleRate; m_interpolatorDistance = (Real) m_config.m_inputSampleRate / (Real) m_config.m_channelSampleRate;
m_useInterpolator = (m_config.m_inputSampleRate != m_config.m_channelSampleRate); // optim
m_settingsMutex.unlock(); m_settingsMutex.unlock();
} }

View File

@ -121,6 +121,7 @@ private:
fftfilt::cmplx m_sum; fftfilt::cmplx m_sum;
bool m_usb; bool m_usb;
Real m_magsq; Real m_magsq;
bool m_useInterpolator;
NCOF m_nco; NCOF m_nco;
Interpolator m_interpolator; Interpolator m_interpolator;
@ -157,7 +158,7 @@ private:
m_sum += sideband[i]; m_sum += sideband[i];
if (!(m_undersampleCount++ & (decim - 1))) if (!(m_undersampleCount++ & (decim - 1))) // counter LSB bit mask for decimation by 2^(m_scaleLog2 - 1)
{ {
m_sum /= decim; m_sum /= decim;
m_magsq = (m_sum.real() * m_sum.real() + m_sum.imag() * m_sum.imag())/ (1<<30); m_magsq = (m_sum.real() * m_sum.real() + m_sum.imag() * m_sum.imag())/ (1<<30);