71 changed files with 1694 additions and 183 deletions
@ -0,0 +1,149 @@
@@ -0,0 +1,149 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2026 Edouard Griffiths, F4EXB <f4exb06@gmail.com> //
|
||||
// //
|
||||
// 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 //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// 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/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "rrcfilterdialog.h" |
||||
#include "ui_rrcfilterdialog.h" |
||||
|
||||
RRCFilterDialog::RRCFilterDialog(QWidget* parent) : |
||||
QDialog(parent), |
||||
ui(new Ui::RRCFilterDialog), |
||||
m_rrcType(ChannelAnalyzerSettings::RRCFIR), |
||||
m_rrcSymbolSpan(8), |
||||
m_rrcNormalization(ChannelAnalyzerSettings::RRCNormGain), |
||||
m_rrcFFTLog2Size(9) |
||||
{ |
||||
ui->setupUi(this); |
||||
makeUIConnections(); |
||||
} |
||||
|
||||
RRCFilterDialog::~RRCFilterDialog() |
||||
{ |
||||
delete ui; |
||||
} |
||||
|
||||
void RRCFilterDialog::setRRCType(ChannelAnalyzerSettings::RRCType rrcType) |
||||
{ |
||||
ui->firGroup->blockSignals(true); |
||||
ui->fftGroup->blockSignals(true); |
||||
|
||||
ui->firGroup->setChecked(false); |
||||
ui->fftGroup->setChecked(false); |
||||
|
||||
switch(rrcType) |
||||
{ |
||||
case ChannelAnalyzerSettings::RRCFIR: |
||||
ui->firGroup->setChecked(true); |
||||
break; |
||||
case ChannelAnalyzerSettings::RRCFFT: |
||||
ui->fftGroup->setChecked(true); |
||||
break; |
||||
default: |
||||
break; |
||||
} |
||||
|
||||
ui->firGroup->blockSignals(false); |
||||
ui->fftGroup->blockSignals(false); |
||||
|
||||
m_rrcType = rrcType; |
||||
} |
||||
|
||||
void RRCFilterDialog::setRRCSymbolSpan(int symbolSpan) |
||||
{ |
||||
m_rrcSymbolSpan = symbolSpan; |
||||
ui->symbolSpan->setValue(symbolSpan); |
||||
} |
||||
|
||||
void RRCFilterDialog::setRRCNormalization(ChannelAnalyzerSettings::RRCNormalization normalization) |
||||
{ |
||||
m_rrcNormalization = normalization; |
||||
ui->normalization->setCurrentIndex((int) normalization); |
||||
} |
||||
|
||||
void RRCFilterDialog::setRRCFFTLog2Size(int log2Size) |
||||
{ |
||||
m_rrcFFTLog2Size = log2Size; |
||||
ui->fftSize->setCurrentIndex(log2Size - 7); |
||||
} |
||||
|
||||
void RRCFilterDialog::on_symbolSpan_valueChanged(int value) |
||||
{ |
||||
m_rrcSymbolSpan = value; |
||||
emit valueChanged(ChangedRRCSymbolSpan); |
||||
} |
||||
|
||||
void RRCFilterDialog::on_normalization_currentIndexChanged(int index) |
||||
{ |
||||
m_rrcNormalization = (ChannelAnalyzerSettings::RRCNormalization) index; |
||||
emit valueChanged(ChangedRRCNormalization); |
||||
} |
||||
|
||||
void RRCFilterDialog::on_fftLog2Size_currentIndexChanged(int index) |
||||
{ |
||||
m_rrcFFTLog2Size = index + 7; |
||||
emit valueChanged(ChangedRRCFFTLog2Size); |
||||
} |
||||
|
||||
void RRCFilterDialog::on_firGroup_clicked(bool checked) |
||||
{ |
||||
qDebug("RRCFilterDialog::on_firGroup_clicked: checked: %d", checked); |
||||
|
||||
if (checked) |
||||
{ |
||||
ui->fftGroup->blockSignals(true); |
||||
ui->fftGroup->setChecked(false); |
||||
ui->fftGroup->blockSignals(false); |
||||
|
||||
m_rrcType = ChannelAnalyzerSettings::RRCFIR; |
||||
emit valueChanged(ChangedRRCType); |
||||
} |
||||
else |
||||
{ |
||||
ui->firGroup->blockSignals(true); |
||||
ui->firGroup->setChecked(true); |
||||
ui->firGroup->blockSignals(false); |
||||
} |
||||
} |
||||
|
||||
void RRCFilterDialog::on_fftGroup_clicked(bool checked) |
||||
{ |
||||
qDebug("RRCFilterDialog::on_fftGroup_clicked: checked: %d", checked); |
||||
|
||||
if (checked) |
||||
{ |
||||
ui->firGroup->blockSignals(true); |
||||
ui->firGroup->setChecked(false); |
||||
ui->firGroup->blockSignals(false); |
||||
|
||||
m_rrcType = ChannelAnalyzerSettings::RRCFFT; |
||||
emit valueChanged(ChangedRRCType); |
||||
} |
||||
else |
||||
{ |
||||
ui->fftGroup->blockSignals(true); |
||||
ui->fftGroup->setChecked(true); |
||||
ui->fftGroup->blockSignals(false); |
||||
} |
||||
} |
||||
|
||||
void RRCFilterDialog::makeUIConnections() |
||||
{ |
||||
connect(ui->firGroup, &QGroupBox::clicked, this, &RRCFilterDialog::on_firGroup_clicked); |
||||
connect(ui->fftGroup, &QGroupBox::clicked, this, &RRCFilterDialog::on_fftGroup_clicked); |
||||
connect(ui->symbolSpan, QOverload<int>::of(&QSpinBox::valueChanged), this, &RRCFilterDialog::on_symbolSpan_valueChanged); |
||||
connect(ui->normalization, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &RRCFilterDialog::on_normalization_currentIndexChanged); |
||||
connect(ui->fftSize, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &RRCFilterDialog::on_fftLog2Size_currentIndexChanged); |
||||
} |
||||
@ -0,0 +1,69 @@
@@ -0,0 +1,69 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2026 Edouard Griffiths, F4EXB <f4exb06@gmail.com> //
|
||||
// //
|
||||
// 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 //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// 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/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
#ifndef PLUGINS_CHANNELRX_CHANALYZER_RRCFILTERDIALOG_H_ |
||||
#define PLUGINS_CHANNELRX_CHANALYZER_RRCFILTERDIALOG_H_ |
||||
|
||||
#include <QDialog> |
||||
#include "chanalyzersettings.h" |
||||
|
||||
|
||||
namespace Ui { |
||||
class RRCFilterDialog; |
||||
} |
||||
|
||||
class RRCFilterDialog : public QDialog { |
||||
Q_OBJECT |
||||
public: |
||||
enum ValueChanged { |
||||
ChangedRRCType, |
||||
ChangedRRCSymbolSpan, |
||||
ChangedRRCNormalization, |
||||
ChangedRRCFFTLog2Size, |
||||
}; |
||||
|
||||
explicit RRCFilterDialog(QWidget* parent = nullptr); |
||||
~RRCFilterDialog() override; |
||||
|
||||
void setRRCType(ChannelAnalyzerSettings::RRCType rrcType); |
||||
void setRRCSymbolSpan(int symbolSpan); |
||||
void setRRCNormalization(ChannelAnalyzerSettings::RRCNormalization normalization); |
||||
void setRRCFFTLog2Size(int log2Size); |
||||
|
||||
ChannelAnalyzerSettings::RRCType getRRCType() const { return m_rrcType; } |
||||
int getRRCSymbolSpan() const { return m_rrcSymbolSpan; } |
||||
ChannelAnalyzerSettings::RRCNormalization getRRCNormalization() const { return m_rrcNormalization; } |
||||
int getRRCFFTLog2Size() const { return m_rrcFFTLog2Size; } |
||||
|
||||
signals: |
||||
void valueChanged(int valueChanged); |
||||
|
||||
private: |
||||
Ui::RRCFilterDialog* ui; |
||||
ChannelAnalyzerSettings::RRCType m_rrcType; |
||||
int m_rrcSymbolSpan; |
||||
ChannelAnalyzerSettings::RRCNormalization m_rrcNormalization; |
||||
int m_rrcFFTLog2Size; |
||||
|
||||
void on_firGroup_clicked(bool checked); |
||||
void on_fftGroup_clicked(bool checked); |
||||
void on_symbolSpan_valueChanged(int value); |
||||
void on_normalization_currentIndexChanged(int index); |
||||
void on_fftLog2Size_currentIndexChanged(int index); |
||||
void makeUIConnections(); |
||||
}; |
||||
|
||||
#endif /* PLUGINS_CHANNELRX_CHANALYZER_RRCFILTERDIALOG_H_ */ |
||||
@ -0,0 +1,258 @@
@@ -0,0 +1,258 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<ui version="4.0"> |
||||
<class>RRCFilterDialog</class> |
||||
<widget class="QDialog" name="RRCFilterDialog"> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>0</x> |
||||
<y>0</y> |
||||
<width>407</width> |
||||
<height>197</height> |
||||
</rect> |
||||
</property> |
||||
<property name="windowTitle"> |
||||
<string>RRC Filter Settings</string> |
||||
</property> |
||||
<layout class="QVBoxLayout" name="verticalLayout"> |
||||
<item> |
||||
<widget class="QGroupBox" name="firGroup"> |
||||
<property name="minimumSize"> |
||||
<size> |
||||
<width>370</width> |
||||
<height>70</height> |
||||
</size> |
||||
</property> |
||||
<property name="toolTip"> |
||||
<string>Use a FIR RRC filter</string> |
||||
</property> |
||||
<property name="styleSheet"> |
||||
<string notr="true">QGroupBox { |
||||
border: 1px solid gray; |
||||
} </string> |
||||
</property> |
||||
<property name="title"> |
||||
<string>FIR</string> |
||||
</property> |
||||
<property name="checkable"> |
||||
<bool>true</bool> |
||||
</property> |
||||
<property name="checked"> |
||||
<bool>false</bool> |
||||
</property> |
||||
<widget class="QLabel" name="symbolSpanLabel"> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>10</x> |
||||
<y>30</y> |
||||
<width>91</width> |
||||
<height>26</height> |
||||
</rect> |
||||
</property> |
||||
<property name="text"> |
||||
<string>Symbol Span</string> |
||||
</property> |
||||
</widget> |
||||
<widget class="QSpinBox" name="symbolSpan"> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>100</x> |
||||
<y>30</y> |
||||
<width>70</width> |
||||
<height>29</height> |
||||
</rect> |
||||
</property> |
||||
<property name="toolTip"> |
||||
<string>Symbol span</string> |
||||
</property> |
||||
<property name="alignment"> |
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> |
||||
</property> |
||||
<property name="minimum"> |
||||
<number>6</number> |
||||
</property> |
||||
<property name="maximum"> |
||||
<number>12</number> |
||||
</property> |
||||
<property name="value"> |
||||
<number>8</number> |
||||
</property> |
||||
</widget> |
||||
<widget class="QLabel" name="normalizationLabel"> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>180</x> |
||||
<y>30</y> |
||||
<width>101</width> |
||||
<height>26</height> |
||||
</rect> |
||||
</property> |
||||
<property name="text"> |
||||
<string>Normalization</string> |
||||
</property> |
||||
</widget> |
||||
<widget class="QComboBox" name="normalization"> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>280</x> |
||||
<y>30</y> |
||||
<width>101</width> |
||||
<height>32</height> |
||||
</rect> |
||||
</property> |
||||
<property name="toolTip"> |
||||
<string>RRC normalization type</string> |
||||
</property> |
||||
<item> |
||||
<property name="text"> |
||||
<string>Energy</string> |
||||
</property> |
||||
</item> |
||||
<item> |
||||
<property name="text"> |
||||
<string>Amplitude</string> |
||||
</property> |
||||
</item> |
||||
<item> |
||||
<property name="text"> |
||||
<string>Gain</string> |
||||
</property> |
||||
</item> |
||||
</widget> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<widget class="QGroupBox" name="fftGroup"> |
||||
<property name="minimumSize"> |
||||
<size> |
||||
<width>370</width> |
||||
<height>70</height> |
||||
</size> |
||||
</property> |
||||
<property name="toolTip"> |
||||
<string>Use a FFT RRC filter</string> |
||||
</property> |
||||
<property name="styleSheet"> |
||||
<string notr="true">QGroupBox { |
||||
border: 1px solid gray; |
||||
} </string> |
||||
</property> |
||||
<property name="title"> |
||||
<string>FFT</string> |
||||
</property> |
||||
<property name="checkable"> |
||||
<bool>true</bool> |
||||
</property> |
||||
<property name="checked"> |
||||
<bool>false</bool> |
||||
</property> |
||||
<widget class="QLabel" name="fftSizeLabel"> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>10</x> |
||||
<y>30</y> |
||||
<width>81</width> |
||||
<height>26</height> |
||||
</rect> |
||||
</property> |
||||
<property name="text"> |
||||
<string>FFT Size</string> |
||||
</property> |
||||
</widget> |
||||
<widget class="QComboBox" name="fftSize"> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>80</x> |
||||
<y>30</y> |
||||
<width>94</width> |
||||
<height>32</height> |
||||
</rect> |
||||
</property> |
||||
<property name="toolTip"> |
||||
<string>Size of FFT filter</string> |
||||
</property> |
||||
<item> |
||||
<property name="text"> |
||||
<string>128</string> |
||||
</property> |
||||
</item> |
||||
<item> |
||||
<property name="text"> |
||||
<string>256</string> |
||||
</property> |
||||
</item> |
||||
<item> |
||||
<property name="text"> |
||||
<string>512</string> |
||||
</property> |
||||
</item> |
||||
<item> |
||||
<property name="text"> |
||||
<string>1024</string> |
||||
</property> |
||||
</item> |
||||
<item> |
||||
<property name="text"> |
||||
<string>2048</string> |
||||
</property> |
||||
</item> |
||||
<item> |
||||
<property name="text"> |
||||
<string>4096</string> |
||||
</property> |
||||
</item> |
||||
<item> |
||||
<property name="text"> |
||||
<string>8192</string> |
||||
</property> |
||||
</item> |
||||
</widget> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<widget class="QDialogButtonBox" name="buttonBox"> |
||||
<property name="orientation"> |
||||
<enum>Qt::Horizontal</enum> |
||||
</property> |
||||
<property name="standardButtons"> |
||||
<set>QDialogButtonBox::Close</set> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
</layout> |
||||
</widget> |
||||
<resources/> |
||||
<connections> |
||||
<connection> |
||||
<sender>buttonBox</sender> |
||||
<signal>accepted()</signal> |
||||
<receiver>RRCFilterDialog</receiver> |
||||
<slot>accept()</slot> |
||||
<hints> |
||||
<hint type="sourcelabel"> |
||||
<x>248</x> |
||||
<y>254</y> |
||||
</hint> |
||||
<hint type="destinationlabel"> |
||||
<x>157</x> |
||||
<y>274</y> |
||||
</hint> |
||||
</hints> |
||||
</connection> |
||||
<connection> |
||||
<sender>buttonBox</sender> |
||||
<signal>rejected()</signal> |
||||
<receiver>RRCFilterDialog</receiver> |
||||
<slot>reject()</slot> |
||||
<hints> |
||||
<hint type="sourcelabel"> |
||||
<x>316</x> |
||||
<y>260</y> |
||||
</hint> |
||||
<hint type="destinationlabel"> |
||||
<x>286</x> |
||||
<y>274</y> |
||||
</hint> |
||||
</hints> |
||||
</connection> |
||||
</connections> |
||||
</ui> |
||||
@ -0,0 +1,187 @@
@@ -0,0 +1,187 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany //
|
||||
// written by Christian Daniel //
|
||||
// Copyright (C) 2015-2019, 2023 Edouard Griffiths, F4EXB <f4exb06@gmail.com> //
|
||||
// Copyright (C) 2026 SDRangel contributors //
|
||||
// //
|
||||
// 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 //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// 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/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "dsp/fftfilterrrc.h" |
||||
|
||||
#include <algorithm> |
||||
#include <cmath> |
||||
#include <cstring> |
||||
|
||||
FFTFilterRRC::FFTFilterRRC(int len) : |
||||
m_fftLen(len), |
||||
m_fftLen2(len / 2), |
||||
m_fft(nullptr), |
||||
m_filter(nullptr), |
||||
m_fftBuffer(nullptr), |
||||
m_overlapBuffer(nullptr), |
||||
m_outputBuffer(nullptr), |
||||
m_inputIndex(0), |
||||
m_symbolRate(0.0f), |
||||
m_rolloff(0.0f) |
||||
{ |
||||
initFilter(); |
||||
} |
||||
|
||||
FFTFilterRRC::~FFTFilterRRC() |
||||
{ |
||||
delete m_fft; |
||||
delete[] m_filter; |
||||
delete[] m_fftBuffer; |
||||
delete[] m_overlapBuffer; |
||||
delete[] m_outputBuffer; |
||||
} |
||||
|
||||
void FFTFilterRRC::initFilter() |
||||
{ |
||||
m_fft = new g_fft<float>(m_fftLen); |
||||
|
||||
m_filter = new Complex[m_fftLen]; |
||||
m_fftBuffer = new Complex[m_fftLen]; |
||||
m_overlapBuffer = new Complex[m_fftLen2]; |
||||
m_outputBuffer = new Complex[m_fftLen2]; |
||||
|
||||
// Initialize all buffers to zero
|
||||
std::fill(m_filter, m_filter + m_fftLen, Complex(0.0f, 0.0f)); |
||||
std::fill(m_fftBuffer, m_fftBuffer + m_fftLen, Complex(0.0f, 0.0f)); |
||||
std::fill(m_overlapBuffer, m_overlapBuffer + m_fftLen2, Complex(0.0f, 0.0f)); |
||||
std::fill(m_outputBuffer, m_outputBuffer + m_fftLen2, Complex(0.0f, 0.0f)); |
||||
|
||||
m_inputIndex = 0; |
||||
} |
||||
|
||||
void FFTFilterRRC::create(float symbolRate, float rolloff) |
||||
{ |
||||
m_symbolRate = symbolRate; |
||||
m_rolloff = rolloff; |
||||
|
||||
// Clamp rolloff to valid range [0, 1]
|
||||
if (m_rolloff < 0.0f) { |
||||
m_rolloff = 0.0f; |
||||
} else if (m_rolloff > 1.0f) { |
||||
m_rolloff = 1.0f; |
||||
} |
||||
|
||||
// Create filter directly in frequency domain
|
||||
std::fill(m_filter, m_filter + m_fftLen, Complex(0.0f, 0.0f)); |
||||
|
||||
for (int i = 0; i < m_fftLen; i++) { |
||||
m_filter[i] = computeRRCResponse(m_symbolRate, m_rolloff, i, m_fftLen); |
||||
} |
||||
|
||||
// Normalize for unity gain in passband
|
||||
float maxMag = 0.0f; |
||||
for (int i = 0; i < m_fftLen; i++) { |
||||
float mag = std::abs(m_filter[i]); |
||||
if (mag > maxMag) { |
||||
maxMag = mag; |
||||
} |
||||
} |
||||
|
||||
if (maxMag > 0.0f) { |
||||
for (int i = 0; i < m_fftLen; i++) { |
||||
m_filter[i] /= maxMag; |
||||
} |
||||
} |
||||
} |
||||
|
||||
FFTFilterRRC::Complex FFTFilterRRC::computeRRCResponse( |
||||
float symbolRate, |
||||
float rolloff, |
||||
int binIndex, |
||||
int fftLen) const |
||||
{ |
||||
// Normalize frequency to [-0.5, 0.5]
|
||||
// FFT bins: 0 to fftLen/2-1 are positive frequencies (0 to 0.5)
|
||||
// fftLen/2 to fftLen-1 are negative frequencies (-0.5 to 0)
|
||||
float freq = static_cast<float>(binIndex) / static_cast<float>(fftLen); |
||||
|
||||
// Map to [-0.5, 0.5] range
|
||||
if (freq > 0.5f) { |
||||
freq -= 1.0f; |
||||
} |
||||
|
||||
// Absolute frequency
|
||||
float absFreq = std::abs(freq); |
||||
|
||||
// Compute frequency boundaries
|
||||
// For RRC: passband is Rs/2, where Rs is symbol rate
|
||||
// Transition band: Rs/2 * (1-beta) to Rs/2 * (1+beta)
|
||||
float f1 = symbolRate * (1.0f - rolloff) / 2.0f; // Start of transition band
|
||||
float f2 = symbolRate * (1.0f + rolloff) / 2.0f; // End of transition band
|
||||
|
||||
Complex response; |
||||
|
||||
if (absFreq <= f1) { |
||||
// Passband: constant response
|
||||
response = Complex(1.0f, 0.0f); |
||||
} else if (absFreq > f1 && absFreq <= f2) { |
||||
// Transition band: raised cosine roll-off
|
||||
// H(f) = 0.5 * [1 + cos(pi/beta * (|f|/Rs - (1-beta)/2))]
|
||||
float normalizedFreq = absFreq / symbolRate; // Normalize by symbol rate
|
||||
float arg = (M_PI / rolloff) * (normalizedFreq - (1.0f - rolloff) / 2.0f); |
||||
float amplitude = 0.5f * (1.0f + std::cos(arg)); |
||||
response = Complex(amplitude, 0.0f); |
||||
} else { |
||||
// Stopband: zero response
|
||||
response = Complex(0.0f, 0.0f); |
||||
} |
||||
|
||||
return response; |
||||
} |
||||
|
||||
int FFTFilterRRC::process(const Complex& input, Complex** output) |
||||
{ |
||||
// Store input sample in first half of FFT buffer
|
||||
m_fftBuffer[m_inputIndex] = input; |
||||
m_inputIndex++; |
||||
|
||||
// Process when first half is full
|
||||
if (m_inputIndex < m_fftLen2) { |
||||
return 0; // Not enough samples yet
|
||||
} |
||||
|
||||
// Second half of FFT buffer is already zero-padded from initialization
|
||||
// or previous processing (overlap-add method)
|
||||
|
||||
// Perform forward FFT
|
||||
m_fft->ComplexFFT(m_fftBuffer); |
||||
|
||||
// Apply filter in frequency domain (element-wise multiplication)
|
||||
for (int i = 0; i < m_fftLen; i++) { |
||||
m_fftBuffer[i] *= m_filter[i]; |
||||
} |
||||
|
||||
// Perform inverse FFT
|
||||
m_fft->InverseComplexFFT(m_fftBuffer); |
||||
|
||||
// Overlap-add: first half gets added to overlap buffer, second half becomes new overlap
|
||||
for (int i = 0; i < m_fftLen2; i++) { |
||||
m_outputBuffer[i] = m_fftBuffer[i] + m_overlapBuffer[i]; |
||||
m_overlapBuffer[i] = m_fftBuffer[i + m_fftLen2]; |
||||
} |
||||
|
||||
// Reset input index and clear first half of FFT buffer for next block
|
||||
m_inputIndex = 0; |
||||
std::fill(m_fftBuffer, m_fftBuffer + m_fftLen2, Complex(0.0f, 0.0f)); |
||||
|
||||
// Return pointer to output buffer
|
||||
*output = m_outputBuffer; |
||||
return m_fftLen2; |
||||
} |
||||
@ -0,0 +1,150 @@
@@ -0,0 +1,150 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany //
|
||||
// written by Christian Daniel //
|
||||
// Copyright (C) 2015-2019, 2023 Edouard Griffiths, F4EXB <f4exb06@gmail.com> //
|
||||
// Copyright (C) 2026 SDRangel contributors //
|
||||
// //
|
||||
// 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 //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// 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/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef INCLUDE_DSP_FFTFILTERRRC_H |
||||
#define INCLUDE_DSP_FFTFILTERRRC_H |
||||
|
||||
#include <complex> |
||||
#include <vector> |
||||
|
||||
#include "gfft.h" |
||||
#include "export.h" |
||||
|
||||
/**
|
||||
* @brief FFT-based root raised cosine filter for complex signals |
||||
* |
||||
* Implements a frequency-domain root raised cosine (RRC) filter using overlap-add |
||||
* FFT convolution. The RRC filter is commonly used for pulse shaping in digital |
||||
* communications to minimize intersymbol interference (ISI) while satisfying |
||||
* the Nyquist criterion. |
||||
* |
||||
* The filter operates in the frequency domain for computational efficiency, |
||||
* applying the RRC frequency response directly to the FFT bins of the input signal. |
||||
*/ |
||||
class SDRBASE_API FFTFilterRRC |
||||
{ |
||||
public: |
||||
using Complex = std::complex<float>; |
||||
|
||||
/**
|
||||
* @brief Construct FFT-based root raised cosine filter |
||||
* |
||||
* @param len FFT length (should be power of 2 for efficiency) |
||||
*/ |
||||
explicit FFTFilterRRC(int len); |
||||
|
||||
/**
|
||||
* @brief Destructor |
||||
*/ |
||||
~FFTFilterRRC(); |
||||
|
||||
// Disable copy semantics (manages raw pointers)
|
||||
FFTFilterRRC(const FFTFilterRRC&) = delete; |
||||
FFTFilterRRC& operator=(const FFTFilterRRC&) = delete; |
||||
|
||||
/**
|
||||
* @brief Create root raised cosine filter in frequency domain |
||||
* |
||||
* @param symbolRate Symbol rate in Hz (normalized to sample rate) |
||||
* @param rolloff Roll-off factor (beta) - typically 0.2 to 0.5 |
||||
* 0 = rectangular, 1 = full cosine roll-off |
||||
* |
||||
* The filter bandwidth extends from -symbolRate*(1+rolloff)/2 to |
||||
* +symbolRate*(1+rolloff)/2 in normalized frequency (0 to 0.5 = Nyquist). |
||||
* |
||||
* Creates mathematically correct RRC frequency response for use in |
||||
* digital communications applications. |
||||
*/ |
||||
void create(float symbolRate, float rolloff); |
||||
/**
|
||||
* @brief Process one complex input sample through the filter |
||||
* |
||||
* Uses overlap-add FFT convolution. Accumulates input samples until |
||||
* a half-buffer is filled, then performs FFT, frequency-domain multiplication |
||||
* with the RRC filter, IFFT, and overlap-add to produce output samples. |
||||
* |
||||
* @param input Complex input sample |
||||
* @param output Pointer to output buffer (will point to internal buffer) |
||||
* @return Number of output samples available (0 or fftLen/2) |
||||
*/ |
||||
int process(const Complex& input, Complex** output); |
||||
|
||||
/**
|
||||
* @brief Get FFT length |
||||
* @return FFT length in samples |
||||
*/ |
||||
int getFFTLength() const { return m_fftLen; } |
||||
|
||||
/**
|
||||
* @brief Get current symbol rate |
||||
* @return Symbol rate (normalized) |
||||
*/ |
||||
float getSymbolRate() const { return m_symbolRate; } |
||||
|
||||
/**
|
||||
* @brief Get current rolloff factor |
||||
* @return Rolloff factor (beta) |
||||
*/ |
||||
float getRolloff() const { return m_rolloff; } |
||||
|
||||
/**
|
||||
* @brief Get pointer to frequency-domain filter coefficients |
||||
* |
||||
* The filter coefficients are in the frequency domain, corresponding to the FFT bins. |
||||
* |
||||
* @return Pointer to array of complex filter coefficients (length = FFT length) |
||||
*/ |
||||
const Complex* getFilter() const { return m_filter; } |
||||
|
||||
private: |
||||
/**
|
||||
* @brief Initialize internal buffers and FFT engine |
||||
*/ |
||||
void initFilter(); |
||||
|
||||
/**
|
||||
* @brief Compute RRC frequency response for a given frequency bin |
||||
* |
||||
* Implements the RRC transfer function in frequency domain: |
||||
* - For |f| <= (1-beta)/(2T): H(f) = T |
||||
* - For (1-beta)/(2T) < |f| <= (1+beta)/(2T): H(f) = T/2 * [1 + cos(pi*T/beta * (|f| - (1-beta)/(2T)))] |
||||
* - For |f| > (1+beta)/(2T): H(f) = 0 |
||||
* |
||||
* @param symbolRate Symbol rate (normalized to sample rate) |
||||
* @param rolloff Roll-off factor (beta) |
||||
* @param binIndex FFT bin index |
||||
* @param fftLen FFT length |
||||
* @return Complex frequency response at this bin |
||||
*/ |
||||
Complex computeRRCResponse(float symbolRate, float rolloff, int binIndex, int fftLen) const; |
||||
|
||||
int m_fftLen; //!< FFT length
|
||||
int m_fftLen2; //!< Half FFT length
|
||||
g_fft<float>* m_fft; //!< FFT engine
|
||||
Complex* m_filter; //!< Frequency-domain filter coefficients
|
||||
Complex* m_fftBuffer; //!< Time-domain input buffer for FFT
|
||||
Complex* m_overlapBuffer; //!< Overlap buffer for overlap-add
|
||||
Complex* m_outputBuffer; //!< Output buffer
|
||||
int m_inputIndex; //!< Current input buffer index
|
||||
float m_symbolRate; //!< Current symbol rate (normalized)
|
||||
float m_rolloff; //!< Current rolloff factor
|
||||
}; |
||||
|
||||
#endif // INCLUDE_DSP_FFTFILTERRRC_H
|
||||
@ -0,0 +1,192 @@
@@ -0,0 +1,192 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany //
|
||||
// written by Christian Daniel //
|
||||
// Copyright (C) 2015-2019, 2023 Edouard Griffiths, F4EXB <f4exb06@gmail.com> //
|
||||
// Copyright (C) 2026 SDRangel contributors //
|
||||
// //
|
||||
// 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 //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// 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/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "dsp/firfilterrrc.h" |
||||
|
||||
#include <algorithm> |
||||
#include <cmath> |
||||
|
||||
FIRFilterRRC::FIRFilterRRC() : |
||||
m_ptr(0), |
||||
m_symbolRate(0.0f), |
||||
m_rolloff(0.0f), |
||||
m_samplesPerSymbol(0) |
||||
{ |
||||
} |
||||
|
||||
void FIRFilterRRC::create(float symbolRate, float rolloff, int symbolSpan, Normalization normalization) |
||||
{ |
||||
m_symbolRate = symbolRate; |
||||
m_rolloff = rolloff; |
||||
|
||||
// Clamp rolloff to valid range [0, 1]
|
||||
if (m_rolloff < 0.0f) { |
||||
m_rolloff = 0.0f; |
||||
} else if (m_rolloff > 1.0f) { |
||||
m_rolloff = 1.0f; |
||||
} |
||||
|
||||
// Calculate samples per symbol
|
||||
m_samplesPerSymbol = static_cast<int>(std::round(1.0f / symbolRate)); |
||||
|
||||
// Calculate number of taps (always odd for symmetry)
|
||||
int numTaps = symbolSpan * m_samplesPerSymbol + 1; |
||||
if ((numTaps & 1) == 0) { |
||||
numTaps++; // Ensure odd number of taps
|
||||
} |
||||
|
||||
// Allocate tap storage (only half + center due to symmetry)
|
||||
int halfTaps = numTaps / 2 + 1; |
||||
m_taps.resize(halfTaps); |
||||
|
||||
// Calculate filter taps
|
||||
int center = numTaps / 2; |
||||
for (int i = 0; i < halfTaps; i++) |
||||
{ |
||||
// Time offset from center in symbol periods
|
||||
float t = static_cast<float>(i - center) / static_cast<float>(m_samplesPerSymbol); |
||||
m_taps[i] = computeRRCTap(t, m_rolloff); |
||||
} |
||||
|
||||
// Apply normalization
|
||||
if (normalization == Normalization::Energy) |
||||
{ |
||||
// Normalize energy: sqrt(sum of squares) = 1
|
||||
float sum = 0.0f; |
||||
for (int i = 0; i < halfTaps - 1; i++) { |
||||
sum += m_taps[i] * m_taps[i] * 2.0f; // Two symmetric taps
|
||||
} |
||||
sum += m_taps[halfTaps - 1] * m_taps[halfTaps - 1]; // Center tap
|
||||
float scale = std::sqrt(sum); |
||||
|
||||
if (scale > 0.0f) { |
||||
for (int i = 0; i < halfTaps; i++) { |
||||
m_taps[i] /= scale; |
||||
} |
||||
} |
||||
} |
||||
else if (normalization == Normalization::Amplitude) |
||||
{ |
||||
// Normalize amplitude: max output for bipolar sequence ≈ 1
|
||||
float maxGain = 0.0f; |
||||
for (int offset = 0; offset < m_samplesPerSymbol; offset++) |
||||
{ |
||||
float gain = 0.0f; |
||||
for (int i = offset; i < halfTaps - 1; i += m_samplesPerSymbol) { |
||||
gain += std::abs(m_taps[i]) * 2.0f; // Both sides
|
||||
} |
||||
// Add center tap if aligned
|
||||
if ((center - offset) % m_samplesPerSymbol == 0) { |
||||
gain += std::abs(m_taps[halfTaps - 1]); |
||||
} |
||||
if (gain > maxGain) { |
||||
maxGain = gain; |
||||
} |
||||
} |
||||
|
||||
if (maxGain > 0.0f) { |
||||
for (int i = 0; i < halfTaps; i++) { |
||||
m_taps[i] /= maxGain; |
||||
} |
||||
} |
||||
} |
||||
else if (normalization == Normalization::Gain) |
||||
{ |
||||
// Normalize for unity gain: sum of taps = 1
|
||||
float sum = 0.0f; |
||||
for (int i = 0; i < halfTaps - 1; i++) { |
||||
sum += m_taps[i] * 2.0f; // Two symmetric taps
|
||||
} |
||||
sum += m_taps[halfTaps - 1]; // Center tap
|
||||
|
||||
if (sum > 0.0f) { |
||||
for (int i = 0; i < halfTaps; i++) { |
||||
m_taps[i] /= sum; |
||||
} |
||||
} |
||||
} |
||||
|
||||
// Initialize sample buffer
|
||||
m_samples.resize(numTaps); |
||||
std::fill(m_samples.begin(), m_samples.end(), Complex(0.0f, 0.0f)); |
||||
m_ptr = 0; |
||||
} |
||||
|
||||
float FIRFilterRRC::computeRRCTap(float t, float rolloff) const |
||||
{ |
||||
constexpr float Ts = 1.0f; // Symbol period (normalized)
|
||||
const float beta = rolloff; |
||||
|
||||
// Handle special case: t = 0
|
||||
if (t == 0.0f) { |
||||
// h(0) = (1/T) * (1 + beta*(4/π - 1))
|
||||
return (1.0f / Ts) * (1.0f + beta * (4.0f / M_PI - 1.0f)); |
||||
} |
||||
|
||||
// Check for zeros of denominator: 1 - (4*β*t/T)² = 0
|
||||
// This occurs at t = ±T/(4*β)
|
||||
const float denomCheck = 4.0f * beta * t / Ts; |
||||
if (std::abs(std::abs(denomCheck) - 1.0f) < 1e-6f && beta > 0.0f) |
||||
{ |
||||
// h(±T/4β) = (β/(T*√2)) * [(1+2/π)*sin(π/4β) + (1-2/π)*cos(π/4β)]
|
||||
const float arg = M_PI / (4.0f * beta); |
||||
return (beta / (Ts * std::sqrt(2.0f))) * |
||||
((1.0f + 2.0f / M_PI) * std::sin(arg) + |
||||
(1.0f - 2.0f / M_PI) * std::cos(arg)); |
||||
} |
||||
|
||||
// General case
|
||||
const float numerator = std::sin(M_PI * t / Ts * (1.0f - beta)) + |
||||
4.0f * beta * t / Ts * std::cos(M_PI * t / Ts * (1.0f + beta)); |
||||
const float denominator = M_PI * t / Ts * (1.0f - denomCheck * denomCheck); |
||||
|
||||
return numerator / (denominator * Ts); |
||||
} |
||||
|
||||
FIRFilterRRC::Complex FIRFilterRRC::filter(const Complex& input) |
||||
{ |
||||
const int numTaps = static_cast<int>(m_samples.size()); |
||||
const int halfTaps = static_cast<int>(m_taps.size()) - 1; |
||||
|
||||
// Store input sample in circular buffer
|
||||
m_samples[m_ptr] = input; |
||||
|
||||
// Perform convolution using symmetry
|
||||
Complex acc(0.0f, 0.0f); |
||||
int a = m_ptr; |
||||
int b = (a == numTaps - 1) ? 0 : a + 1; |
||||
|
||||
// Process symmetric pairs
|
||||
for (int i = 0; i < halfTaps; i++) |
||||
{ |
||||
acc += (m_samples[a] + m_samples[b]) * m_taps[i]; |
||||
|
||||
a = (a == 0) ? numTaps - 1 : a - 1; |
||||
b = (b == numTaps - 1) ? 0 : b + 1; |
||||
} |
||||
|
||||
// Add center tap
|
||||
acc += m_samples[a] * m_taps[halfTaps]; |
||||
|
||||
// Advance circular buffer pointer
|
||||
m_ptr = (m_ptr == static_cast<size_t>(numTaps) - 1) ? 0 : m_ptr + 1; |
||||
|
||||
return acc; |
||||
} |
||||
@ -0,0 +1,153 @@
@@ -0,0 +1,153 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany //
|
||||
// written by Christian Daniel //
|
||||
// Copyright (C) 2015-2019, 2023 Edouard Griffiths, F4EXB <f4exb06@gmail.com> //
|
||||
// Copyright (C) 2026 SDRangel contributors //
|
||||
// //
|
||||
// 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 //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// 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/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef INCLUDE_DSP_FIRFILTERRRC_H |
||||
#define INCLUDE_DSP_FIRFILTERRRC_H |
||||
|
||||
#include <complex> |
||||
#include <vector> |
||||
|
||||
#include "export.h" |
||||
|
||||
/**
|
||||
* @brief FIR root raised cosine filter for complex signals |
||||
* |
||||
* Implements a time-domain FIR root raised cosine (RRC) filter using direct |
||||
* convolution. The RRC filter is commonly used for pulse shaping in digital |
||||
* communications to minimize intersymbol interference (ISI) while satisfying |
||||
* the Nyquist criterion. |
||||
* |
||||
* This filter offers sample-by-sample processing with low latency, making it |
||||
* suitable for real-time applications. For longer filters or higher throughput, |
||||
* consider using FFTFilterRRC which uses frequency-domain processing. |
||||
*/ |
||||
class SDRBASE_API FIRFilterRRC |
||||
{ |
||||
public: |
||||
using Complex = std::complex<float>; |
||||
|
||||
/**
|
||||
* @brief Normalization modes for filter taps |
||||
*/ |
||||
enum class Normalization { |
||||
Energy, //!< Impulse response energy normalized (TX+RX = raised cosine peak = 1) - for matched filter pairs
|
||||
Amplitude, //!< Bipolar symbol sequence output amplitude normalized to ±1 - for pulse amplitude preservation
|
||||
Gain //!< Unity gain (0 dB) - tap coefficients sum to 1 - for continuous wave input
|
||||
}; |
||||
|
||||
/**
|
||||
* @brief Construct FIR root raised cosine filter |
||||
*/ |
||||
FIRFilterRRC(); |
||||
|
||||
/**
|
||||
* @brief Destructor |
||||
*/ |
||||
~FIRFilterRRC() = default; |
||||
|
||||
/**
|
||||
* @brief Create root raised cosine filter taps |
||||
* |
||||
* @param symbolRate Symbol rate (normalized to sample rate, 0 to 0.5) |
||||
* @param rolloff Roll-off factor (beta) - typically 0.2 to 0.5 |
||||
* 0 = rectangular, 1 = full cosine roll-off |
||||
* @param symbolSpan Number of symbols over which filter is spread |
||||
* Typical values: 6-12 (more = better filtering, more delay) |
||||
* @param normalization How to normalize the filter taps |
||||
* |
||||
* Total number of taps = symbolSpan * samplesPerSymbol + 1 (always odd). |
||||
* For symbolRate=0.05 (20 samples/symbol), symbolSpan=8 gives 161 taps. |
||||
*/ |
||||
void create(float symbolRate, float rolloff, int symbolSpan = 8, |
||||
Normalization normalization = Normalization::Energy); |
||||
|
||||
/**
|
||||
* @brief Process one complex input sample through the filter |
||||
* |
||||
* Direct convolution with stored tap coefficients. Processes samples |
||||
* one at a time with minimal latency. |
||||
* |
||||
* @param input Complex input sample |
||||
* @return Filtered complex output sample |
||||
*/ |
||||
Complex filter(const Complex& input); |
||||
|
||||
/**
|
||||
* @brief Get current symbol rate |
||||
* @return Symbol rate (normalized) |
||||
*/ |
||||
float getSymbolRate() const { return m_symbolRate; } |
||||
|
||||
/**
|
||||
* @brief Get current rolloff factor |
||||
* @return Rolloff factor (beta) |
||||
*/ |
||||
float getRolloff() const { return m_rolloff; } |
||||
|
||||
/**
|
||||
* @brief Get number of taps in filter |
||||
* @return Number of filter taps |
||||
*/ |
||||
int getNumTaps() const { return static_cast<int>(m_taps.size()); } |
||||
|
||||
/**
|
||||
* @brief Get samples per symbol |
||||
* @return Samples per symbol (1/symbolRate) |
||||
*/ |
||||
int getSamplesPerSymbol() const { return m_samplesPerSymbol; } |
||||
|
||||
/**
|
||||
* @brief Get filter delay in samples |
||||
* @return Group delay (approximately numTaps/2) |
||||
*/ |
||||
int getDelay() const { return getNumTaps() / 2; } |
||||
|
||||
/**
|
||||
* @brief Get reference to filter tap coefficients |
||||
* |
||||
* The taps are stored as half + center due to symmetry. The full impulse |
||||
* response can be reconstructed by mirroring the taps around the center. |
||||
* |
||||
* @return Reference to vector of filter tap coefficients (half + center) |
||||
*/ |
||||
const std::vector<float>& getTaps() const { return m_taps; } |
||||
|
||||
private: |
||||
/**
|
||||
* @brief Compute time-domain RRC tap value |
||||
* |
||||
* Implements the mathematical RRC impulse response: |
||||
* h(t) = [sin(π*t/T*(1-β)) + 4*β*t/T*cos(π*t/T*(1+β))] / [π*t/T*(1-(4*β*t/T)²)] |
||||
* |
||||
* @param t Time index (in symbol periods) |
||||
* @param rolloff Roll-off factor (beta) |
||||
* @return Tap value at time t |
||||
*/ |
||||
float computeRRCTap(float t, float rolloff) const; |
||||
|
||||
std::vector<float> m_taps; //!< Filter tap coefficients (symmetric, stored as half + center)
|
||||
std::vector<Complex> m_samples; //!< Circular buffer for input samples
|
||||
size_t m_ptr; //!< Current position in circular buffer
|
||||
float m_symbolRate; //!< Symbol rate (normalized)
|
||||
float m_rolloff; //!< Rolloff factor (beta)
|
||||
int m_samplesPerSymbol; //!< Samples per symbol (1/symbolRate)
|
||||
}; |
||||
|
||||
#endif // INCLUDE_DSP_FIRFILTERRRC_H
|
||||
@ -0,0 +1,77 @@
@@ -0,0 +1,77 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2026 Edouard Griffiths, F4EXB <f4exb06@gmail.com> //
|
||||
// //
|
||||
// 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 //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// 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/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "mainbench.h" |
||||
#include "dsp/fftfilterrrc.h" |
||||
#include <QDebug> |
||||
|
||||
void MainBench::testFFTRRCFilter() |
||||
{ |
||||
qDebug() << "MainBench::testFFTRRCFilter"; |
||||
const int RRC_FFT_SIZE = 512; |
||||
std::complex<float>* rrcFilterOut = nullptr; |
||||
FFTFilterRRC filter(RRC_FFT_SIZE); |
||||
filter.create(0.05f, 0.35f); // 2400 baud, 0.35 rolloff
|
||||
|
||||
qDebug() << "MainBench::testFFTRRCFilter: filter created"; |
||||
FILE *fd_filter = fopen("test_rrc_filter.txt", "w"); |
||||
|
||||
for (int i = 0; i < RRC_FFT_SIZE; i++) { |
||||
fprintf(fd_filter, "%f\n", std::abs(filter.getFilter()[i])); |
||||
} |
||||
qDebug() << "MainBench::testFFTRRCFilter: filter coefficients written to test_rrc_filter.txt"; |
||||
fclose(fd_filter); |
||||
|
||||
qDebug() << "MainBench::testFFTRRCFilter: running filter"; |
||||
FILE *fd = fopen("test_rrc.txt", "w"); |
||||
int outLen = 0; |
||||
|
||||
for (int i = 0; i < 5000; i++) |
||||
{ |
||||
int ss = 48000 / 2400; // Samples per symbol at 2400 baud
|
||||
int d = i / ss; // Symbol index at 2400 baud
|
||||
Real s = (d % 2 == 0) ? 1.0f : -1.0f; // BPSK symbol sequence
|
||||
Real x = (i % ss == 0 ? s : 0.0f); // Pulsed signal at 2400 Hz
|
||||
// Real phi = i * (1200.0 / 48000.0) * (2*3.141);
|
||||
// Real x = sin(phi) > 0.0 ? 1.0f : -1.0f; // Simulate a BPSK signal at 1200 baud
|
||||
filter.process(Complex(x, 0.0f), &rrcFilterOut); |
||||
outLen++; |
||||
|
||||
if (outLen % (RRC_FFT_SIZE / 2) == 0) |
||||
{ |
||||
// printf("\ni=%d n_out: %d\n", i, n_out);
|
||||
|
||||
for (int j = 0; j < outLen; j++) |
||||
{ |
||||
Complex rrc = rrcFilterOut[j]; |
||||
fprintf(fd, "%f\n", rrc.real()); |
||||
} |
||||
|
||||
outLen = 0; |
||||
} |
||||
} |
||||
|
||||
// output any remaining samples
|
||||
for (int j = 0; j < outLen; j++) |
||||
{ |
||||
Complex rrc = rrcFilterOut[j]; |
||||
fprintf(fd, "%f\n", rrc.real()); |
||||
} |
||||
|
||||
qDebug() << "MainBench::testFFTRRCFilter: output samples written to test_fftrrc.txt"; |
||||
fclose(fd); |
||||
} |
||||
@ -0,0 +1,50 @@
@@ -0,0 +1,50 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (C) 2026 Edouard Griffiths, F4EXB <f4exb06@gmail.com> //
|
||||
// //
|
||||
// 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 //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// 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/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "mainbench.h" |
||||
#include "dsp/firfilterrrc.h" |
||||
#include <QDebug> |
||||
|
||||
void MainBench::testFIRRRCFilter() |
||||
{ |
||||
qDebug() << "MainBench::testFIRRRCFilter"; |
||||
FIRFilterRRC filter; |
||||
filter.create(0.05f, 0.35f, 8, FIRFilterRRC::Normalization::Gain); // 2400 baud, 0.35 rolloff
|
||||
|
||||
qDebug() << "MainBench::testFIRRRCFilter: filter created"; |
||||
FILE *fd_filter = fopen("test_rrc_filter.txt", "w"); |
||||
const std::vector<float>& taps = filter.getTaps(); |
||||
for (auto tap : taps) { |
||||
fprintf(fd_filter, "%f\n", std::abs(tap)); |
||||
} |
||||
qDebug() << "MainBench::testFIRRRCFilter: filter coefficients written to test_rrc_filter.txt"; |
||||
fclose(fd_filter); |
||||
|
||||
qDebug() << "MainBench::testFIRRRCFilter: running filter"; |
||||
FILE *fd = fopen("test_rrc.txt", "w"); |
||||
|
||||
for (int i = 0; i < 1000; i++) |
||||
{ |
||||
Real phi = i * (1200.0 / 48000.0) * (2*3.141); |
||||
Real x = sin(phi) > 0.0 ? 1.0f : -1.0f; // Simulate a BPSK signal at 1200 baud
|
||||
Complex rrc = filter.filter(Complex(x, 0.0f)); |
||||
fprintf(fd, "%f\n", rrc.real()); |
||||
} |
||||
|
||||
qDebug() << "MainBench::testFIRRRCFilter: output samples written to test_firrrc.txt"; |
||||
fclose(fd); |
||||
} |
||||
@ -0,0 +1,41 @@
@@ -0,0 +1,41 @@
|
||||
#!/usr/bin/env python3 |
||||
import matplotlib.pyplot as plt |
||||
import numpy as np |
||||
|
||||
with open('../build/test_rrc_filter.txt', 'r') as f: |
||||
filter_data = f.read() |
||||
|
||||
filter_out = [float(x) for x in filter_data.splitlines()] |
||||
xf = np.array(filter_out) |
||||
|
||||
with open('../build/test_rrc.txt', 'r') as f: |
||||
data = f.read() |
||||
|
||||
out = [float(x) for x in data.splitlines()] |
||||
# marks = [127, 254, 383, 511, 639, 767, 895, 1023] |
||||
# marks = [127, 254, 383, 511] |
||||
x = np.array(out) |
||||
|
||||
fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(12, 6)) |
||||
|
||||
ax2.plot(xf) |
||||
ax2.set_title('RRC Filter Coefficients') |
||||
ax2.set_xlabel('Index') |
||||
ax2.set_ylabel('Amplitude') |
||||
ax2.grid(True) |
||||
|
||||
ax1.set_title('RRC Filter Output (Real Part)') |
||||
ax1.plot(x) |
||||
# ax1.scatter(marks, x[marks], |
||||
# color='red', marker='.', s=100, zorder=5, edgecolors='black') |
||||
# plt.annotate('126', xy=(126, x[126]), xytext=(6, 0), |
||||
# arrowprops=dict(facecolor='black', shrink=0.05), |
||||
# fontsize=12, ha='center') |
||||
ax1.set_xlabel('Index') |
||||
ax1.set_ylabel('Real part') |
||||
ax1.grid(True) |
||||
|
||||
|
||||
plt.subplots_adjust(hspace=0.4) |
||||
plt.savefig('plot.png', dpi=150, bbox_inches='tight') |
||||
plt.close() # Prevents memory leaks |
||||
Loading…
Reference in new issue