2016-10-17 02:58:49 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
2019-04-25 03:14:17 -04:00
|
|
|
// Copyright (C) 2016-2019 F4EXB //
|
2016-10-17 02:58:49 -04:00
|
|
|
// written by Edouard Griffiths //
|
|
|
|
// //
|
|
|
|
// This program is free software; you can redistribute it and/or modify //
|
|
|
|
// it under the terms of the GNU General Public License as published by //
|
|
|
|
// the Free Software Foundation as version 3 of the License, or //
|
2019-04-11 08:32:15 -04:00
|
|
|
// (at your option) any later version. //
|
2016-10-17 02:58:49 -04:00
|
|
|
// //
|
|
|
|
// This program is distributed in the hope that it will be useful, //
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
|
|
|
// GNU General Public License V3 for more details. //
|
|
|
|
// //
|
|
|
|
// You should have received a copy of the GNU General Public License //
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-10-02 15:52:39 -04:00
|
|
|
#include <dsp/downchannelizer.h>
|
2014-05-18 11:52:39 -04:00
|
|
|
#include "dsp/inthalfbandfilter.h"
|
|
|
|
#include "dsp/dspcommands.h"
|
2019-04-25 19:27:36 -04:00
|
|
|
#include "dsp/hbfilterchainconverter.h"
|
2014-05-18 11:52:39 -04:00
|
|
|
|
2015-08-21 02:54:28 -04:00
|
|
|
#include <QString>
|
2015-08-09 04:33:04 -04:00
|
|
|
#include <QDebug>
|
2015-05-14 21:12:27 -04:00
|
|
|
|
2016-10-02 15:52:39 -04:00
|
|
|
MESSAGE_CLASS_DEFINITION(DownChannelizer::MsgChannelizerNotification, Message)
|
2019-04-25 03:14:17 -04:00
|
|
|
MESSAGE_CLASS_DEFINITION(DownChannelizer::MsgSetChannelizer, Message)
|
2015-08-19 16:12:52 -04:00
|
|
|
|
2016-10-02 16:29:04 -04:00
|
|
|
DownChannelizer::DownChannelizer(BasebandSampleSink* sampleSink) :
|
2019-04-25 19:27:36 -04:00
|
|
|
m_filterChainSetMode(false),
|
2014-05-18 11:52:39 -04:00
|
|
|
m_sampleSink(sampleSink),
|
2015-08-23 20:06:11 -04:00
|
|
|
m_inputSampleRate(0),
|
|
|
|
m_requestedOutputSampleRate(0),
|
2014-05-18 11:52:39 -04:00
|
|
|
m_requestedCenterFrequency(0),
|
2015-08-09 18:09:10 -04:00
|
|
|
m_currentOutputSampleRate(0),
|
2014-05-18 11:52:39 -04:00
|
|
|
m_currentCenterFrequency(0)
|
|
|
|
{
|
2016-10-08 04:35:07 -04:00
|
|
|
QString name = "DownChannelizer(" + m_sampleSink->objectName() + ")";
|
2015-08-21 02:54:28 -04:00
|
|
|
setObjectName(name);
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
2016-10-02 15:52:39 -04:00
|
|
|
DownChannelizer::~DownChannelizer()
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
|
|
|
freeFilterChain();
|
|
|
|
}
|
|
|
|
|
2016-10-02 15:52:39 -04:00
|
|
|
void DownChannelizer::configure(MessageQueue* messageQueue, int sampleRate, int centerFrequency)
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
2015-08-13 23:00:28 -04:00
|
|
|
Message* cmd = new DSPConfigureChannelizer(sampleRate, centerFrequency);
|
|
|
|
messageQueue->push(cmd);
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
2019-04-25 19:27:36 -04:00
|
|
|
void DownChannelizer::set(MessageQueue* messageQueue, unsigned int log2Decim, unsigned int filterChainHash)
|
|
|
|
{
|
|
|
|
Message* cmd = new MsgSetChannelizer(log2Decim, filterChainHash);
|
|
|
|
messageQueue->push(cmd);
|
|
|
|
}
|
|
|
|
|
2016-10-02 15:52:39 -04:00
|
|
|
void DownChannelizer::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly)
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
2015-08-23 18:51:27 -04:00
|
|
|
if(m_sampleSink == 0) {
|
2014-06-15 04:32:25 -04:00
|
|
|
m_sampleBuffer.clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-04 10:31:54 -04:00
|
|
|
if (m_filterStages.size() == 0) // optimization when no downsampling is done anyway
|
|
|
|
{
|
|
|
|
m_sampleSink->feed(begin, end, positiveOnly);
|
|
|
|
}
|
|
|
|
else
|
2015-09-06 04:21:06 -04:00
|
|
|
{
|
2016-10-04 10:31:54 -04:00
|
|
|
m_mutex.lock();
|
2015-09-06 04:21:06 -04:00
|
|
|
|
2016-10-04 10:31:54 -04:00
|
|
|
for(SampleVector::const_iterator sample = begin; sample != end; ++sample)
|
2015-09-06 04:21:06 -04:00
|
|
|
{
|
2016-10-04 10:31:54 -04:00
|
|
|
Sample s(*sample);
|
|
|
|
FilterStages::iterator stage = m_filterStages.begin();
|
|
|
|
|
|
|
|
for (; stage != m_filterStages.end(); ++stage)
|
2015-09-06 04:21:06 -04:00
|
|
|
{
|
2016-10-04 10:31:54 -04:00
|
|
|
if(!(*stage)->work(&s))
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2015-09-06 04:21:06 -04:00
|
|
|
}
|
|
|
|
|
2016-10-04 10:31:54 -04:00
|
|
|
if(stage == m_filterStages.end())
|
|
|
|
{
|
2017-05-11 20:41:51 -04:00
|
|
|
s.m_real /= (1<<(m_filterStages.size()));
|
|
|
|
s.m_imag /= (1<<(m_filterStages.size()));
|
2016-10-04 10:31:54 -04:00
|
|
|
m_sampleBuffer.push_back(s);
|
|
|
|
}
|
2015-09-06 04:21:06 -04:00
|
|
|
}
|
2014-05-18 11:52:39 -04:00
|
|
|
|
2016-10-04 10:31:54 -04:00
|
|
|
m_mutex.unlock();
|
2015-09-06 04:21:06 -04:00
|
|
|
|
2016-10-04 10:31:54 -04:00
|
|
|
m_sampleSink->feed(m_sampleBuffer.begin(), m_sampleBuffer.end(), positiveOnly);
|
|
|
|
m_sampleBuffer.clear();
|
|
|
|
}
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
2016-10-02 15:52:39 -04:00
|
|
|
void DownChannelizer::start()
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
2015-08-23 20:06:11 -04:00
|
|
|
if (m_sampleSink != 0)
|
2015-08-12 19:14:21 -04:00
|
|
|
{
|
2016-10-08 04:35:07 -04:00
|
|
|
qDebug() << "DownChannelizer::start: thread: " << thread()
|
2015-08-23 18:51:27 -04:00
|
|
|
<< " m_inputSampleRate: " << m_inputSampleRate
|
|
|
|
<< " m_requestedOutputSampleRate: " << m_requestedOutputSampleRate
|
|
|
|
<< " m_requestedCenterFrequency: " << m_requestedCenterFrequency;
|
2014-05-18 11:52:39 -04:00
|
|
|
m_sampleSink->start();
|
2015-08-12 19:14:21 -04:00
|
|
|
}
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
2016-10-02 15:52:39 -04:00
|
|
|
void DownChannelizer::stop()
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
2015-08-23 18:51:27 -04:00
|
|
|
if(m_sampleSink != 0)
|
2014-05-18 11:52:39 -04:00
|
|
|
m_sampleSink->stop();
|
|
|
|
}
|
|
|
|
|
2016-10-02 15:52:39 -04:00
|
|
|
bool DownChannelizer::handleMessage(const Message& cmd)
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
2015-09-06 19:15:55 -04:00
|
|
|
// TODO: apply changes only if input sample rate or requested output sample rate change. Change of center frequency has no impact.
|
|
|
|
|
2015-08-17 02:29:34 -04:00
|
|
|
if (DSPSignalNotification::match(cmd))
|
2015-08-09 18:09:10 -04:00
|
|
|
{
|
2015-08-17 02:29:34 -04:00
|
|
|
DSPSignalNotification& notif = (DSPSignalNotification&) cmd;
|
|
|
|
m_inputSampleRate = notif.getSampleRate();
|
2016-10-08 04:35:07 -04:00
|
|
|
qDebug() << "DownChannelizer::handleMessage: DSPSignalNotification: m_inputSampleRate: " << m_inputSampleRate;
|
2019-04-25 19:27:36 -04:00
|
|
|
|
|
|
|
if (!m_filterChainSetMode) {
|
|
|
|
applyConfiguration();
|
|
|
|
}
|
2015-08-13 23:00:28 -04:00
|
|
|
|
2015-08-23 18:51:27 -04:00
|
|
|
if (m_sampleSink != 0)
|
2015-08-09 18:09:10 -04:00
|
|
|
{
|
2017-12-28 23:48:54 -05:00
|
|
|
DSPSignalNotification* rep = new DSPSignalNotification(notif); // make a copy
|
|
|
|
m_sampleSink->getInputMessageQueue()->push(rep);
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
2015-08-09 18:09:10 -04:00
|
|
|
|
2015-07-12 03:32:54 -04:00
|
|
|
emit inputSampleRateChanged();
|
2014-05-18 11:52:39 -04:00
|
|
|
return true;
|
2015-08-09 18:09:10 -04:00
|
|
|
}
|
2015-08-19 16:12:52 -04:00
|
|
|
else if (DSPConfigureChannelizer::match(cmd))
|
2015-08-09 18:09:10 -04:00
|
|
|
{
|
2015-08-17 02:29:34 -04:00
|
|
|
DSPConfigureChannelizer& chan = (DSPConfigureChannelizer&) cmd;
|
|
|
|
m_requestedOutputSampleRate = chan.getSampleRate();
|
|
|
|
m_requestedCenterFrequency = chan.getCenterFrequency();
|
2015-08-13 23:00:28 -04:00
|
|
|
|
2016-10-08 04:35:07 -04:00
|
|
|
qDebug() << "DownChannelizer::handleMessage: DSPConfigureChannelizer:"
|
2015-08-09 18:09:10 -04:00
|
|
|
<< " m_requestedOutputSampleRate: " << m_requestedOutputSampleRate
|
|
|
|
<< " m_requestedCenterFrequency: " << m_requestedCenterFrequency;
|
2015-08-13 23:00:28 -04:00
|
|
|
|
2014-05-18 11:52:39 -04:00
|
|
|
applyConfiguration();
|
2015-08-13 23:00:28 -04:00
|
|
|
|
2014-05-18 11:52:39 -04:00
|
|
|
return true;
|
2015-08-09 18:09:10 -04:00
|
|
|
}
|
2019-04-25 03:14:17 -04:00
|
|
|
else if (MsgSetChannelizer::match(cmd))
|
|
|
|
{
|
|
|
|
MsgSetChannelizer& chan = (MsgSetChannelizer&) cmd;
|
|
|
|
qDebug() << "DownChannelizer::handleMessage: MsgSetChannelizer";
|
2019-04-25 19:27:36 -04:00
|
|
|
applySetting(chan.getLog2Decim(), chan.getFilterChainHash());
|
2019-04-25 03:14:17 -04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2018-03-05 20:23:47 -05:00
|
|
|
else if (BasebandSampleSink::MsgThreadedSink::match(cmd))
|
|
|
|
{
|
2018-03-29 04:03:52 -04:00
|
|
|
qDebug() << "DownChannelizer::handleMessage: MsgThreadedSink: forwarded to demod";
|
2018-03-05 20:23:47 -05:00
|
|
|
return m_sampleSink->handleMessage(cmd); // this message is passed to the demod
|
|
|
|
}
|
2015-08-09 18:09:10 -04:00
|
|
|
else
|
|
|
|
{
|
2018-03-29 04:03:52 -04:00
|
|
|
qDebug() << "DownChannelizer::handleMessage: " << cmd.getIdentifier() << " unhandled";
|
2017-12-28 23:48:54 -05:00
|
|
|
return false;
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-02 15:52:39 -04:00
|
|
|
void DownChannelizer::applyConfiguration()
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
2019-04-25 19:27:36 -04:00
|
|
|
m_filterChainSetMode = false;
|
|
|
|
|
2015-08-23 20:06:11 -04:00
|
|
|
if (m_inputSampleRate == 0)
|
|
|
|
{
|
2016-10-08 04:35:07 -04:00
|
|
|
qDebug() << "DownChannelizer::applyConfiguration: m_inputSampleRate=0 aborting";
|
2015-08-23 20:06:11 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-06 04:21:06 -04:00
|
|
|
m_mutex.lock();
|
|
|
|
|
2014-05-18 11:52:39 -04:00
|
|
|
freeFilterChain();
|
2015-08-23 20:06:11 -04:00
|
|
|
|
2014-05-18 11:52:39 -04:00
|
|
|
m_currentCenterFrequency = createFilterChain(
|
|
|
|
m_inputSampleRate / -2, m_inputSampleRate / 2,
|
|
|
|
m_requestedCenterFrequency - m_requestedOutputSampleRate / 2, m_requestedCenterFrequency + m_requestedOutputSampleRate / 2);
|
2015-08-23 20:06:11 -04:00
|
|
|
|
2015-09-06 04:21:06 -04:00
|
|
|
m_mutex.unlock();
|
|
|
|
|
2017-05-11 20:41:51 -04:00
|
|
|
//debugFilterChain();
|
|
|
|
|
2014-05-18 11:52:39 -04:00
|
|
|
m_currentOutputSampleRate = m_inputSampleRate / (1 << m_filterStages.size());
|
2015-07-12 03:32:54 -04:00
|
|
|
|
2016-10-08 04:35:07 -04:00
|
|
|
qDebug() << "DownChannelizer::applyConfiguration in=" << m_inputSampleRate
|
2015-05-15 05:29:41 -04:00
|
|
|
<< ", req=" << m_requestedOutputSampleRate
|
|
|
|
<< ", out=" << m_currentOutputSampleRate
|
2015-08-09 04:33:04 -04:00
|
|
|
<< ", fc=" << m_currentCenterFrequency;
|
2015-08-23 18:51:27 -04:00
|
|
|
|
|
|
|
if (m_sampleSink != 0)
|
|
|
|
{
|
2017-12-28 23:14:40 -05:00
|
|
|
MsgChannelizerNotification *notif = MsgChannelizerNotification::create(m_currentOutputSampleRate, m_currentCenterFrequency);
|
|
|
|
m_sampleSink->getInputMessageQueue()->push(notif);
|
2015-08-23 18:51:27 -04:00
|
|
|
}
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
2019-04-25 19:27:36 -04:00
|
|
|
void DownChannelizer::applySetting(unsigned int log2Decim, unsigned int filterChainHash)
|
2019-04-25 03:14:17 -04:00
|
|
|
{
|
2019-04-25 19:27:36 -04:00
|
|
|
m_filterChainSetMode = true;
|
|
|
|
std::vector<unsigned int> stageIndexes;
|
|
|
|
m_currentCenterFrequency = m_inputSampleRate * HBFilterChainConverter::convertToIndexes(log2Decim, filterChainHash, stageIndexes);
|
|
|
|
m_requestedCenterFrequency = m_currentCenterFrequency;
|
2019-04-25 03:14:17 -04:00
|
|
|
|
2019-04-25 19:27:36 -04:00
|
|
|
m_mutex.lock();
|
2019-04-25 03:14:17 -04:00
|
|
|
freeFilterChain();
|
2019-04-25 19:27:36 -04:00
|
|
|
setFilterChain(stageIndexes);
|
2019-04-25 03:14:17 -04:00
|
|
|
m_mutex.unlock();
|
|
|
|
|
|
|
|
m_currentOutputSampleRate = m_inputSampleRate / (1 << m_filterStages.size());
|
|
|
|
m_requestedOutputSampleRate = m_currentOutputSampleRate;
|
|
|
|
|
2019-04-25 19:27:36 -04:00
|
|
|
qDebug() << "DownChannelizer::applySetting inputSampleRate:" << m_inputSampleRate
|
|
|
|
<< " currentOutputSampleRate: " << m_currentOutputSampleRate
|
|
|
|
<< " currentCenterFrequency: " << m_currentCenterFrequency
|
|
|
|
<< " nb_filters: " << stageIndexes.size()
|
|
|
|
<< " nb_stages: " << m_filterStages.size();
|
2019-04-25 03:14:17 -04:00
|
|
|
|
|
|
|
if (m_sampleSink != 0)
|
|
|
|
{
|
|
|
|
MsgChannelizerNotification *notif = MsgChannelizerNotification::create(m_currentOutputSampleRate, m_currentCenterFrequency);
|
|
|
|
m_sampleSink->getInputMessageQueue()->push(notif);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-22 02:46:05 -05:00
|
|
|
#ifdef SDR_RX_SAMPLE_24BIT
|
2018-01-21 15:48:36 -05:00
|
|
|
DownChannelizer::FilterStage::FilterStage(Mode mode) :
|
2018-05-07 19:35:08 -04:00
|
|
|
m_filter(new IntHalfbandFilterEO<qint64, qint64, DOWNCHANNELIZER_HB_FILTER_ORDER>),
|
2018-01-21 15:48:36 -05:00
|
|
|
m_workFunction(0),
|
|
|
|
m_mode(mode),
|
2018-05-01 16:02:30 -04:00
|
|
|
m_sse(true)
|
2018-01-21 15:48:36 -05:00
|
|
|
{
|
|
|
|
switch(mode) {
|
|
|
|
case ModeCenter:
|
2018-05-07 19:35:08 -04:00
|
|
|
m_workFunction = &IntHalfbandFilterEO<qint64, qint64, DOWNCHANNELIZER_HB_FILTER_ORDER>::workDecimateCenter;
|
2018-01-21 15:48:36 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ModeLowerHalf:
|
2018-05-07 19:35:08 -04:00
|
|
|
m_workFunction = &IntHalfbandFilterEO<qint64, qint64, DOWNCHANNELIZER_HB_FILTER_ORDER>::workDecimateLowerHalf;
|
2018-01-21 15:48:36 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ModeUpperHalf:
|
2018-05-07 19:35:08 -04:00
|
|
|
m_workFunction = &IntHalfbandFilterEO<qint64, qint64, DOWNCHANNELIZER_HB_FILTER_ORDER>::workDecimateUpperHalf;
|
2018-01-21 15:48:36 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
2016-11-07 12:51:32 -05:00
|
|
|
DownChannelizer::FilterStage::FilterStage(Mode mode) :
|
2018-05-07 19:35:08 -04:00
|
|
|
m_filter(new IntHalfbandFilterEO<qint32, qint32, DOWNCHANNELIZER_HB_FILTER_ORDER>),
|
2018-05-01 16:02:30 -04:00
|
|
|
m_workFunction(0),
|
|
|
|
m_mode(mode),
|
|
|
|
m_sse(true)
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
2018-05-01 16:02:30 -04:00
|
|
|
switch(mode) {
|
|
|
|
case ModeCenter:
|
2018-05-07 19:35:08 -04:00
|
|
|
m_workFunction = &IntHalfbandFilterEO<qint32, qint32, DOWNCHANNELIZER_HB_FILTER_ORDER>::workDecimateCenter;
|
2018-05-01 16:02:30 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ModeLowerHalf:
|
2018-05-07 19:35:08 -04:00
|
|
|
m_workFunction = &IntHalfbandFilterEO<qint32, qint32, DOWNCHANNELIZER_HB_FILTER_ORDER>::workDecimateLowerHalf;
|
2018-05-01 16:02:30 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ModeUpperHalf:
|
2018-05-07 19:35:08 -04:00
|
|
|
m_workFunction = &IntHalfbandFilterEO<qint32, qint32, DOWNCHANNELIZER_HB_FILTER_ORDER>::workDecimateUpperHalf;
|
2018-05-01 16:02:30 -04:00
|
|
|
break;
|
|
|
|
}
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
2016-11-07 12:51:32 -05:00
|
|
|
#endif
|
2018-05-01 16:02:30 -04:00
|
|
|
|
2016-10-02 15:52:39 -04:00
|
|
|
DownChannelizer::FilterStage::~FilterStage()
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
|
|
|
delete m_filter;
|
|
|
|
}
|
|
|
|
|
2016-10-02 15:52:39 -04:00
|
|
|
bool DownChannelizer::signalContainsChannel(Real sigStart, Real sigEnd, Real chanStart, Real chanEnd) const
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
|
|
|
//qDebug(" testing signal [%f, %f], channel [%f, %f]", sigStart, sigEnd, chanStart, chanEnd);
|
|
|
|
if(sigEnd <= sigStart)
|
|
|
|
return false;
|
|
|
|
if(chanEnd <= chanStart)
|
|
|
|
return false;
|
|
|
|
return (sigStart <= chanStart) && (sigEnd >= chanEnd);
|
|
|
|
}
|
|
|
|
|
2016-10-02 15:52:39 -04:00
|
|
|
Real DownChannelizer::createFilterChain(Real sigStart, Real sigEnd, Real chanStart, Real chanEnd)
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
|
|
|
Real sigBw = sigEnd - sigStart;
|
|
|
|
Real rot = sigBw / 4;
|
|
|
|
|
2019-04-25 03:14:17 -04:00
|
|
|
qDebug("DownChannelizer::createFilterChain: Signal [%.1f, %.1f] (BW %.1f), Channel [%.1f, %.1f], Rot %.1f", sigStart, sigEnd, sigBw, chanStart, chanEnd, rot);
|
2014-05-18 11:52:39 -04:00
|
|
|
|
|
|
|
// check if it fits into the left half
|
2019-04-25 03:14:17 -04:00
|
|
|
if(signalContainsChannel(sigStart, sigStart + sigBw / 2.0, chanStart, chanEnd))
|
|
|
|
{
|
|
|
|
qDebug("DownChannelizer::createFilterChain: -> take left half (rotate by +1/4 and decimate by 2)");
|
2014-05-18 11:52:39 -04:00
|
|
|
m_filterStages.push_back(new FilterStage(FilterStage::ModeLowerHalf));
|
|
|
|
return createFilterChain(sigStart, sigStart + sigBw / 2.0, chanStart, chanEnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if it fits into the right half
|
2019-04-25 03:14:17 -04:00
|
|
|
if(signalContainsChannel(sigEnd - sigBw / 2.0f, sigEnd, chanStart, chanEnd))
|
|
|
|
{
|
|
|
|
qDebug("DownChannelizer::createFilterChain: -> take right half (rotate by -1/4 and decimate by 2)");
|
2014-05-18 11:52:39 -04:00
|
|
|
m_filterStages.push_back(new FilterStage(FilterStage::ModeUpperHalf));
|
|
|
|
return createFilterChain(sigEnd - sigBw / 2.0f, sigEnd, chanStart, chanEnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if it fits into the center
|
2019-04-25 03:14:17 -04:00
|
|
|
if(signalContainsChannel(sigStart + rot, sigEnd - rot, chanStart, chanEnd))
|
|
|
|
{
|
|
|
|
qDebug("DownChannelizer::createFilterChain: -> take center half (decimate by 2)");
|
2014-05-18 11:52:39 -04:00
|
|
|
m_filterStages.push_back(new FilterStage(FilterStage::ModeCenter));
|
2015-05-14 21:12:27 -04:00
|
|
|
return createFilterChain(sigStart + rot, sigEnd - rot, chanStart, chanEnd);
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
2019-04-25 03:14:17 -04:00
|
|
|
|
2014-05-18 11:52:39 -04:00
|
|
|
Real ofs = ((chanEnd - chanStart) / 2.0 + chanStart) - ((sigEnd - sigStart) / 2.0 + sigStart);
|
2019-04-25 03:14:17 -04:00
|
|
|
qDebug("DownChannelizer::createFilterChain: -> complete (final BW %.1f, frequency offset %.1f)", sigBw, ofs);
|
2014-05-18 11:52:39 -04:00
|
|
|
return ofs;
|
|
|
|
}
|
|
|
|
|
2019-04-25 19:27:36 -04:00
|
|
|
void DownChannelizer::setFilterChain(const std::vector<unsigned int>& stageIndexes)
|
2019-04-25 03:14:17 -04:00
|
|
|
{
|
|
|
|
// filters are described from lower to upper level but the chain is constructed the other way round
|
|
|
|
std::vector<unsigned int>::const_reverse_iterator rit = stageIndexes.rbegin();
|
|
|
|
|
|
|
|
// Each index is a base 3 number with 0 = low, 1 = center, 2 = high
|
|
|
|
// Functions at upper level will convert a number to base 3 to describe the filter chain. Common converting
|
|
|
|
// algorithms will go from LSD to MSD. This explains the reverse order.
|
|
|
|
for (; rit != stageIndexes.rend(); ++rit)
|
|
|
|
{
|
2019-04-25 19:27:36 -04:00
|
|
|
if (*rit == 0) {
|
2019-04-25 03:14:17 -04:00
|
|
|
m_filterStages.push_back(new FilterStage(FilterStage::ModeLowerHalf));
|
2019-04-25 19:27:36 -04:00
|
|
|
} else if (*rit == 1) {
|
2019-04-25 03:14:17 -04:00
|
|
|
m_filterStages.push_back(new FilterStage(FilterStage::ModeCenter));
|
2019-04-25 19:27:36 -04:00
|
|
|
} else if (*rit == 2) {
|
2019-04-25 03:14:17 -04:00
|
|
|
m_filterStages.push_back(new FilterStage(FilterStage::ModeUpperHalf));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-02 15:52:39 -04:00
|
|
|
void DownChannelizer::freeFilterChain()
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
|
|
|
for(FilterStages::iterator it = m_filterStages.begin(); it != m_filterStages.end(); ++it)
|
|
|
|
delete *it;
|
|
|
|
m_filterStages.clear();
|
|
|
|
}
|
2017-05-11 20:41:51 -04:00
|
|
|
|
|
|
|
void DownChannelizer::debugFilterChain()
|
|
|
|
{
|
2018-12-01 21:06:04 -05:00
|
|
|
qDebug("DownChannelizer::debugFilterChain: %lu stages", m_filterStages.size());
|
2017-05-11 20:41:51 -04:00
|
|
|
|
|
|
|
for(FilterStages::iterator it = m_filterStages.begin(); it != m_filterStages.end(); ++it)
|
|
|
|
{
|
|
|
|
switch ((*it)->m_mode)
|
|
|
|
{
|
|
|
|
case FilterStage::ModeCenter:
|
|
|
|
qDebug("DownChannelizer::debugFilterChain: center %s", (*it)->m_sse ? "sse" : "no_sse");
|
|
|
|
break;
|
|
|
|
case FilterStage::ModeLowerHalf:
|
|
|
|
qDebug("DownChannelizer::debugFilterChain: lower %s", (*it)->m_sse ? "sse" : "no_sse");
|
|
|
|
break;
|
|
|
|
case FilterStage::ModeUpperHalf:
|
|
|
|
qDebug("DownChannelizer::debugFilterChain: upper %s", (*it)->m_sse ? "sse" : "no_sse");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
qDebug("DownChannelizer::debugFilterChain: none %s", (*it)->m_sse ? "sse" : "no_sse");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|