mirror of
https://github.com/f4exb/sdrangel.git
synced 2026-08-28 22:35:40 -04:00
Address cppcheck warnings by checking fopen() results before using the returned file handles and reporting the underlying error on failure. This prevents null file handles from being passed to fprintf() and fclose(), avoiding a potential crash when test output files cannot be created. Explicitly convert RRC filter coefficients to double for fprintf() to match the %f format specifier. Signed-off-by: Robin Getz <rgetz503@gmail.com>
91 lines
3.6 KiB
C++
91 lines
3.6 KiB
C++
///////////////////////////////////////////////////////////////////////////////////
|
|
// 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");
|
|
if (!fd_filter)
|
|
{
|
|
qWarning() << "MainBench::testFFTRRCFilter: failed to open test_rrc_filter.txt : "
|
|
<< strerror(errno);
|
|
return;
|
|
}
|
|
|
|
for (int i = 0; i < RRC_FFT_SIZE; i++) {
|
|
fprintf(fd_filter, "%f\n", static_cast<double>(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");
|
|
if (!fd)
|
|
{
|
|
qWarning() << "MainBench::testFFTRRCFilter: failed to open test_rrc.txt : "
|
|
<< strerror(errno);
|
|
return;
|
|
}
|
|
|
|
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);
|
|
}
|