1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-26 01:39:05 -05:00

DOA2: DOA implementation

This commit is contained in:
f4exb 2022-05-27 23:31:43 +02:00
parent 0e08a35d49
commit 0f7972856f
12 changed files with 256 additions and 49 deletions

View File

@ -293,6 +293,16 @@ void DOA2::applyChannelSettings(uint32_t log2Decim, uint32_t filterChainHash)
m_basebandSink->getInputMessageQueue()->push(msg); m_basebandSink->getInputMessageQueue()->push(msg);
} }
float DOA2::getPhi() const
{
return m_basebandSink ? m_basebandSink->getPhi() : 0.0f;
}
float DOA2::getPositiveDOA() const
{
return std::acos(getPhi()/M_PI)*(180/M_PI);
}
int DOA2::webapiSettingsGet( int DOA2::webapiSettingsGet(
SWGSDRangel::SWGChannelSettings& response, SWGSDRangel::SWGChannelSettings& response,
QString& errorMessage) QString& errorMessage)

View File

@ -125,6 +125,8 @@ public:
ScopeVis *getScopeVis() { return &m_scopeSink; } ScopeVis *getScopeVis() { return &m_scopeSink; }
void applyChannelSettings(uint32_t log2Decim, uint32_t filterChainHash); void applyChannelSettings(uint32_t log2Decim, uint32_t filterChainHash);
float getPhi() const;
float getPositiveDOA() const;
virtual int webapiSettingsGet( virtual int webapiSettingsGet(
SWGSDRangel::SWGChannelSettings& response, SWGSDRangel::SWGChannelSettings& response,

View File

@ -33,6 +33,12 @@ MESSAGE_CLASS_DEFINITION(DOA2Baseband::MsgConfigureCorrelation, Message)
DOA2Baseband::DOA2Baseband(int fftSize) : DOA2Baseband::DOA2Baseband(int fftSize) :
m_correlator(fftSize), m_correlator(fftSize),
m_correlationType(DOA2Settings::CorrelationFFT),
m_fftSize(fftSize),
m_samplesCount(0),
m_magSum(0.0f),
m_wphSum(0.0f),
m_phi(0.0f),
m_scopeSink(nullptr), m_scopeSink(nullptr),
m_mutex(QMutex::Recursive) m_mutex(QMutex::Recursive)
{ {
@ -142,6 +148,10 @@ void DOA2Baseband::run()
{ {
if (m_correlator.performCorr(m_sinks[0].getData(), m_sinks[0].getSize(), m_sinks[1].getData(), m_sinks[1].getSize())) if (m_correlator.performCorr(m_sinks[0].getData(), m_sinks[0].getSize(), m_sinks[1].getData(), m_sinks[1].getSize()))
{ {
if (m_correlationType == DOA2Settings::CorrelationType::CorrelationFFT) {
processDOA(m_correlator.m_xcorr.begin(), m_correlator.m_processed);
}
if (m_scopeSink) if (m_scopeSink)
{ {
std::vector<SampleVector::const_iterator> vbegin; std::vector<SampleVector::const_iterator> vbegin;
@ -221,12 +231,12 @@ bool DOA2Baseband::handleMessage(const Message& cmd)
{ {
QMutexLocker mutexLocker(&m_mutex); QMutexLocker mutexLocker(&m_mutex);
MsgConfigureCorrelation& cfg = (MsgConfigureCorrelation&) cmd; MsgConfigureCorrelation& cfg = (MsgConfigureCorrelation&) cmd;
DOA2Settings::CorrelationType correlationType = cfg.getCorrelationType(); m_correlationType = cfg.getCorrelationType();
qDebug() << "DOA2Baseband::handleMessage: MsgConfigureCorrelation:" qDebug() << "DOA2Baseband::handleMessage: MsgConfigureCorrelation:"
<< " correlationType: " << correlationType; << " correlationType: " << m_correlationType;
m_correlator.setCorrType(correlationType); m_correlator.setCorrType(m_correlationType);
return true; return true;
} }
@ -245,3 +255,24 @@ void DOA2Baseband ::setBasebandSampleRate(unsigned int sampleRate)
m_sinks[istream].reset(); m_sinks[istream].reset();
} }
} }
void DOA2Baseband::processDOA(const std::vector<Complex>::iterator& begin, int nbSamples)
{
const std::vector<Complex>::iterator end = begin + nbSamples;
for (std::vector<Complex>::iterator it = begin; it != end; ++it)
{
float ph = std::arg(*it);
float mag = std::norm(*it);
m_magSum += mag;
m_wphSum += mag*ph;
if (++m_samplesCount == m_fftSize)
{
m_phi = m_wphSum / m_magSum;
m_magSum = 0;
m_wphSum = 0;
m_samplesCount = 0;
}
}
}

View File

@ -110,13 +110,21 @@ public:
void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, unsigned int streamIndex); void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, unsigned int streamIndex);
void setBasebandSampleRate(unsigned int sampleRate); void setBasebandSampleRate(unsigned int sampleRate);
float getPhi() const { return m_phi; }
private: private:
void processFifo(const std::vector<SampleVector>& data, unsigned int ibegin, unsigned int iend); void processFifo(const std::vector<SampleVector>& data, unsigned int ibegin, unsigned int iend);
void run(); void run();
bool handleMessage(const Message& cmd); bool handleMessage(const Message& cmd);
void processDOA(const std::vector<Complex>::iterator& begin, int nbSamples);
DOA2Correlator m_correlator; DOA2Correlator m_correlator;
DOA2Settings::CorrelationType m_correlationType;
int m_fftSize;
int m_samplesCount;
float m_magSum;
float m_wphSum;
float m_phi;
SampleMIFifo m_sampleMIFifo; SampleMIFifo m_sampleMIFifo;
std::vector<SampleVector::const_iterator> m_vbegin; std::vector<SampleVector::const_iterator> m_vbegin;
int m_sizes[2]; int m_sizes[2];

View File

@ -87,7 +87,7 @@ void DOA2Compass::paintEvent(QPaintEvent *)
} }
// draw yaw lines // draw compass lines
{ {
int nyawLines = 36; int nyawLines = 36;
float rotAng = 360.0 / nyawLines; float rotAng = 360.0 / nyawLines;
@ -150,7 +150,7 @@ void DOA2Compass::paintEvent(QPaintEvent *)
painter.rotate(m_azAnt); painter.rotate(m_azAnt);
painter.setPen(Qt::NoPen); painter.setPen(Qt::NoPen);
painter.setBrush(QBrush(Qt::white)); painter.setBrush(QBrush(QColor(192, 192, 192)));
QPointF pointsN[3] = { QPointF pointsN[3] = {
QPointF(fx1, fy1), QPointF(fx1, fy1),
QPointF(fx2, fy2), QPointF(fx2, fy2),

View File

@ -138,10 +138,10 @@ DOA2Correlator::DOA2Correlator(int fftSize) :
m_invFFT2Sequence = fftFactory->getEngine(fftSize, true, &m_invFFT2); m_invFFT2Sequence = fftFactory->getEngine(fftSize, true, &m_invFFT2);
m_dataj = new std::complex<float>[2*fftSize]; // receives actual FFT result hence twice the data FFT size m_dataj = new std::complex<float>[2*fftSize]; // receives actual FFT result hence twice the data FFT size
m_scorr.resize(fftSize);
m_tcorr.resize(fftSize); m_tcorr.resize(fftSize);
m_scorrSize = fftSize; m_xcorr.resize(fftSize);
m_tcorrSize = fftSize; m_tcorrSize = fftSize;
m_xcorrSize = fftSize;
} }
DOA2Correlator::~DOA2Correlator() DOA2Correlator::~DOA2Correlator()
@ -268,6 +268,7 @@ bool DOA2Correlator::performOpCorr(
{ {
unsigned int size = std::min(size0, size1); unsigned int size = std::min(size0, size1);
adjustTCorrSize(size); adjustTCorrSize(size);
adjustXCorrSize(size);
std::transform( std::transform(
data0.begin(), data0.begin(),
@ -294,8 +295,8 @@ bool DOA2Correlator::performFFTProd(
int nfft = 0; int nfft = 0;
SampleVector::const_iterator begin0 = data0.begin(); SampleVector::const_iterator begin0 = data0.begin();
SampleVector::const_iterator begin1 = data1.begin(); SampleVector::const_iterator begin1 = data1.begin();
adjustSCorrSize(size);
adjustTCorrSize(size); adjustTCorrSize(size);
adjustXCorrSize(size);
while (size >= m_fftSize) while (size >= m_fftSize)
{ {
@ -340,21 +341,22 @@ bool DOA2Correlator::performFFTProd(
} }
); );
// copy product to time domain - re-order, convert and scale to FFT size // copy to complex vector for DOA with re-orderong
std::transform( std::copy(
m_invFFT2->in(), m_invFFT2->in(),
m_invFFT2->in() + m_fftSize/2, m_invFFT2->in() + m_fftSize/2,
m_tcorr.begin() + nfft*m_fftSize + m_fftSize/2, m_xcorr.begin() + nfft*m_fftSize + m_fftSize/2
[](const std::complex<float>& a) -> Sample {
Sample s;
s.setReal(a.real()/2.0f);
s.setImag(a.imag()/2.0f);
return s;
}
); );
std::transform( std::copy(
m_invFFT2->in() + m_fftSize/2, m_invFFT2->in() + m_fftSize/2,
m_invFFT2->in() + m_fftSize, m_invFFT2->in() + m_fftSize,
m_xcorr.begin() + nfft*m_fftSize
);
// convert and scale to FFT size for scope time domain display
std::transform(
m_xcorr.begin() + nfft*m_fftSize,
m_xcorr.begin() + nfft*m_fftSize + m_fftSize,
m_tcorr.begin() + nfft*m_fftSize, m_tcorr.begin() + nfft*m_fftSize,
[](const std::complex<float>& a) -> Sample { [](const std::complex<float>& a) -> Sample {
Sample s; Sample s;
@ -364,14 +366,29 @@ bool DOA2Correlator::performFFTProd(
} }
); );
// feed spectrum with the sum // copy product to time domain - re-order, convert and scale to FFT size
std::transform( // std::transform(
begin0, // m_invFFT2->in(),
begin0 + m_fftSize, // m_invFFT2->in() + m_fftSize/2,
begin1, // m_tcorr.begin() + nfft*m_fftSize + m_fftSize/2,
m_scorr.begin() + nfft*m_fftSize, // [](const std::complex<float>& a) -> Sample {
sAdd // Sample s;
); // s.setReal(a.real()/2.0f);
// s.setImag(a.imag()/2.0f);
// return s;
// }
// );
// std::transform(
// m_invFFT2->in() + m_fftSize/2,
// m_invFFT2->in() + m_fftSize,
// m_tcorr.begin() + nfft*m_fftSize,
// [](const std::complex<float>& a) -> Sample {
// Sample s;
// s.setReal(a.real()/2.0f);
// s.setImag(a.imag()/2.0f);
// return s;
// }
// );
size -= m_fftSize; size -= m_fftSize;
begin0 += m_fftSize; begin0 += m_fftSize;
@ -387,17 +404,6 @@ bool DOA2Correlator::performFFTProd(
return nfft > 0; return nfft > 0;
} }
void DOA2Correlator::adjustSCorrSize(int size)
{
int nFFTSize = (size/m_fftSize)*m_fftSize;
if (nFFTSize > m_scorrSize)
{
m_scorr.resize(nFFTSize);
m_scorrSize = nFFTSize;
}
}
void DOA2Correlator::adjustTCorrSize(int size) void DOA2Correlator::adjustTCorrSize(int size)
{ {
int nFFTSize = (size/m_fftSize)*m_fftSize; int nFFTSize = (size/m_fftSize)*m_fftSize;
@ -409,6 +415,17 @@ void DOA2Correlator::adjustTCorrSize(int size)
} }
} }
void DOA2Correlator::adjustXCorrSize(int size)
{
int nFFTSize = (size/m_fftSize)*m_fftSize;
if (nFFTSize > m_xcorrSize)
{
m_xcorr.resize(nFFTSize);
m_xcorrSize = nFFTSize;
}
}
void DOA2Correlator::setPhase(int phase) void DOA2Correlator::setPhase(int phase)
{ {
m_phase = phase; m_phase = phase;

View File

@ -46,10 +46,10 @@ public:
int getFullFFTSize() const { return 2*m_fftSize; } int getFullFFTSize() const { return 2*m_fftSize; }
void setPhase(int phase); void setPhase(int phase);
SampleVector m_scorr; //!< raw correlation result (spectrum) - Sample vector expected SampleVector m_tcorr; //!< correlation result (time or spectrum inverse FFT) - Sample vector expected
SampleVector m_tcorr; //!< correlation result (time or spectrum inverse FFT) - Sample vector expected std::vector<Complex> m_xcorr; //!< correlation result of inverse FFT of FFT prod with conjugate (performFFTProd) for DOA processing
int m_processed; //!< number of samples processed at the end of correlation int m_processed; //!< number of samples processed at the end of correlation
int m_remaining[2]; //!< number of samples remaining per member at the end of correlation int m_remaining[2]; //!< number of samples remaining per member at the end of correlation
signals: signals:
void dataReady(int start, int stop); void dataReady(int start, int stop);
@ -68,8 +68,8 @@ private:
const SampleVector& data1, const SampleVector& data1,
unsigned int size1 unsigned int size1
); );
void adjustSCorrSize(int size);
void adjustTCorrSize(int size); void adjustTCorrSize(int size);
void adjustXCorrSize(int size);
DOA2Settings::CorrelationType m_corrType; DOA2Settings::CorrelationType m_corrType;
unsigned int m_fftSize; //!< FFT length unsigned int m_fftSize; //!< FFT length
@ -86,8 +86,8 @@ private:
SampleVector m_data0w; //!< windowed data 0 SampleVector m_data0w; //!< windowed data 0
SampleVector m_data1w; //!< windowed data 1 SampleVector m_data1w; //!< windowed data 1
SampleVector m_data1p; //!< data1 with phase correction SampleVector m_data1p; //!< data1 with phase correction
int m_scorrSize; //!< spectrum correlations vector size
int m_tcorrSize; //!< time correlations vector size int m_tcorrSize; //!< time correlations vector size
int m_xcorrSize; //!< DOA correlations vector size
int m_phase; //!< phase correction int m_phase; //!< phase correction
int64_t m_sin; //!< scaled sine of phase correction int64_t m_sin; //!< scaled sine of phase correction
int64_t m_cos; //!< scaled cosine of phase correction int64_t m_cos; //!< scaled cosine of phase correction

View File

@ -152,6 +152,8 @@ DOA2GUI::DOA2GUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, MIMOChannel *ch
displayRateAndShift(); displayRateAndShift();
applySettings(true); applySettings(true);
connect(&MainCore::instance()->getMasterTimer(), SIGNAL(timeout()), this, SLOT(tick()));
// Test // Test
ui->compass->setAzNeg(85); ui->compass->setAzNeg(85);
ui->compass->setAzPos(315); ui->compass->setAzPos(315);
@ -200,6 +202,8 @@ void DOA2GUI::displaySettings()
applyDecimation(); applyDecimation();
ui->phaseCorrection->setValue(m_settings.m_phase); ui->phaseCorrection->setValue(m_settings.m_phase);
ui->phaseCorrectionText->setText(tr("%1").arg(m_settings.m_phase)); ui->phaseCorrectionText->setText(tr("%1").arg(m_settings.m_phase));
ui->compass->setAzAnt(m_settings.m_antennaAz);
ui->antAz->setValue(m_settings.m_antennaAz);
getRollupContents()->restoreState(m_rollupState); getRollupContents()->restoreState(m_rollupState);
updateAbsoluteCenterFrequency(); updateAbsoluteCenterFrequency();
blockApplySettings(false); blockApplySettings(false);
@ -318,6 +322,14 @@ void DOA2GUI::on_correlationType_currentIndexChanged(int index)
applySettings(); applySettings();
} }
void DOA2GUI::on_antAz_valueChanged(int value)
{
m_settings.m_antennaAz = value;
ui->compass->setAzAnt(value);
updateDOA();
applySettings();
}
void DOA2GUI::applyDecimation() void DOA2GUI::applyDecimation()
{ {
uint32_t maxHash = 1; uint32_t maxHash = 1;
@ -346,7 +358,9 @@ void DOA2GUI::applyPosition()
void DOA2GUI::tick() void DOA2GUI::tick()
{ {
if (++m_tickCount == 20) { // once per second if (++m_tickCount == 20) // once per second
{
updateDOA();
m_tickCount = 0; m_tickCount = 0;
} }
} }
@ -357,9 +371,21 @@ void DOA2GUI::makeUIConnections()
QObject::connect(ui->position, &QSlider::valueChanged, this, &DOA2GUI::on_position_valueChanged); QObject::connect(ui->position, &QSlider::valueChanged, this, &DOA2GUI::on_position_valueChanged);
QObject::connect(ui->phaseCorrection, &QSlider::valueChanged, this, &DOA2GUI::on_phaseCorrection_valueChanged); QObject::connect(ui->phaseCorrection, &QSlider::valueChanged, this, &DOA2GUI::on_phaseCorrection_valueChanged);
QObject::connect(ui->correlationType, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &DOA2GUI::on_correlationType_currentIndexChanged); QObject::connect(ui->correlationType, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &DOA2GUI::on_correlationType_currentIndexChanged);
QObject::connect(ui->antAz, QOverload<int>::of(&QSpinBox::valueChanged), this, &DOA2GUI::on_antAz_valueChanged);
} }
void DOA2GUI::updateAbsoluteCenterFrequency() void DOA2GUI::updateAbsoluteCenterFrequency()
{ {
setStatusFrequency(m_centerFrequency + m_shiftFrequencyFactor * m_sampleRate); setStatusFrequency(m_centerFrequency + m_shiftFrequencyFactor * m_sampleRate);
} }
void DOA2GUI::updateDOA()
{
float doaAngle = m_doa2->getPositiveDOA();
float posAngle = ui->antAz->value() - doaAngle; // DOA angles are trigonometric but displayed angles are clockwise
float negAngle = ui->antAz->value() + doaAngle;
ui->compass->setAzPos(posAngle);
ui->compass->setAzNeg(negAngle);
ui->posText->setText(tr("%1").arg(ui->compass->getAzPos(), 0, 'f', 0));
ui->negText->setText(tr("%1").arg(ui->compass->getAzNeg(), 0, 'f', 0));
}

View File

@ -87,6 +87,7 @@ private:
bool handleMessage(const Message& message); bool handleMessage(const Message& message);
void makeUIConnections(); void makeUIConnections();
void updateAbsoluteCenterFrequency(); void updateAbsoluteCenterFrequency();
void updateDOA();
void leaveEvent(QEvent*); void leaveEvent(QEvent*);
void enterEvent(QEvent*); void enterEvent(QEvent*);
@ -97,6 +98,7 @@ private slots:
void on_position_valueChanged(int value); void on_position_valueChanged(int value);
void on_phaseCorrection_valueChanged(int value); void on_phaseCorrection_valueChanged(int value);
void on_correlationType_currentIndexChanged(int index); void on_correlationType_currentIndexChanged(int index);
void on_antAz_valueChanged(int value);
void onWidgetRolled(QWidget* widget, bool rollDown); void onWidgetRolled(QWidget* widget, bool rollDown);
void onMenuDialogCalled(const QPoint& p); void onMenuDialogCalled(const QPoint& p);
void tick(); void tick();

View File

@ -335,7 +335,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>98</y> <y>98</y>
<width>720</width> <width>718</width>
<height>334</height> <height>334</height>
</rect> </rect>
</property> </property>
@ -402,8 +402,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>432</y> <y>432</y>
<width>720</width> <width>718</width>
<height>284</height> <height>85</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@ -438,9 +438,115 @@
<number>2</number> <number>2</number>
</property> </property>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QGridLayout" name="gridLayout">
<item> <item row="0" column="1">
<layout class="QHBoxLayout" name="doaValuesLayout">
<item>
<widget class="QLabel" name="posLabel">
<property name="text">
<string>Pos</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="posText">
<property name="text">
<string>000</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="spcLabel1">
<property name="minimumSize">
<size>
<width>10</width>
<height>0</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="negLabel">
<property name="text">
<string>Neg</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="negText">
<property name="text">
<string>000</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="spcLabel1_2">
<property name="minimumSize">
<size>
<width>10</width>
<height>0</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="antLabel">
<property name="text">
<string>Ant</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="antAz">
<property name="minimumSize">
<size>
<width>60</width>
<height>0</height>
</size>
</property>
<property name="wrapping">
<bool>true</bool>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="maximum">
<number>359</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout"/>
</item>
<item row="0" column="0" rowspan="2">
<widget class="DOA2Compass" name="compass" native="true"> <widget class="DOA2Compass" name="compass" native="true">
<property name="minimumSize">
<size>
<width>359</width>
<height>200</height>
</size>
</property>
<property name="font"> <property name="font">
<font> <font>
<family>Liberation Sans</family> <family>Liberation Sans</family>

View File

@ -45,6 +45,7 @@ void DOA2Settings::resetToDefaults()
m_reverseAPIChannelIndex = 0; m_reverseAPIChannelIndex = 0;
m_workspaceIndex = 0; m_workspaceIndex = 0;
m_hidden = false; m_hidden = false;
m_antennaAz = 0;
} }
QByteArray DOA2Settings::serialize() const QByteArray DOA2Settings::serialize() const
@ -65,6 +66,7 @@ QByteArray DOA2Settings::serialize() const
s.writeS32(13,m_workspaceIndex); s.writeS32(13,m_workspaceIndex);
s.writeBlob(14, m_geometryBytes); s.writeBlob(14, m_geometryBytes);
s.writeBool(15, m_hidden); s.writeBool(15, m_hidden);
s.writeS32(16, m_antennaAz);
if (m_scopeGUI) { if (m_scopeGUI) {
s.writeBlob(21, m_scopeGUI->serialize()); s.writeBlob(21, m_scopeGUI->serialize());
@ -121,6 +123,8 @@ bool DOA2Settings::deserialize(const QByteArray& data)
d.readS32(13, &m_workspaceIndex); d.readS32(13, &m_workspaceIndex);
d.readBlob(14, &m_geometryBytes); d.readBlob(14, &m_geometryBytes);
d.readBool(15, &m_hidden, false); d.readBool(15, &m_hidden, false);
d.readS32(16, &tmp, 0);
m_antennaAz = tmp < 0 ? 0 : tmp > 359 ? 359 : tmp;
if (m_scopeGUI) if (m_scopeGUI)
{ {

View File

@ -38,6 +38,7 @@ struct DOA2Settings
uint32_t m_log2Decim; uint32_t m_log2Decim;
uint32_t m_filterChainHash; uint32_t m_filterChainHash;
int m_phase; int m_phase;
int m_antennaAz;
bool m_useReverseAPI; bool m_useReverseAPI;
QString m_reverseAPIAddress; QString m_reverseAPIAddress;
uint16_t m_reverseAPIPort; uint16_t m_reverseAPIPort;