1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-25 09:18:54 -05:00
sdrangel/wdsp/bps.cpp

169 lines
4.4 KiB
C++
Raw Normal View History

2024-06-16 05:31:13 -04:00
/* bandpass.c
This file is part of a program that implements a Software-Defined Radio.
Copyright (C) 2013, 2016, 2017 Warren Pratt, NR0V
Copyright (C) 2024 Edouard Griffiths, F4EXB Adapted to SDRangel
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; either version 2
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 for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
The author can be reached by email at
warren@wpratt.com
*/
#include "comm.hpp"
#include "bps.hpp"
#include "fir.hpp"
#include "bandpass.hpp"
#include "RXA.hpp"
#include "TXA.hpp"
namespace WDSP {
/********************************************************************************************************
* *
* Overlap-Save Bandpass *
* *
********************************************************************************************************/
2024-08-05 14:05:59 -04:00
void BPS::calc()
2024-06-16 05:31:13 -04:00
{
2024-08-05 14:05:59 -04:00
infilt.resize(2 * size * 2);
product.resize(2 * size * 2);
std::vector<float> impulse;
FIR::fir_bandpass(
impulse,
size + 1,
f_low,
f_high,
samplerate,
wintype,
1,
1.0 / (float)(2 * size)
);
FIR::fftcv_mults(mults, 2 * size, impulse.data());
2024-08-05 14:05:59 -04:00
CFor = fftwf_plan_dft_1d(2 * size, (fftwf_complex *) infilt.data(), (fftwf_complex *) product.data(), FFTW_FORWARD, FFTW_PATIENT);
CRev = fftwf_plan_dft_1d(2 * size, (fftwf_complex *) product.data(), (fftwf_complex *) out, FFTW_BACKWARD, FFTW_PATIENT);
2024-06-16 05:31:13 -04:00
}
2024-08-05 14:05:59 -04:00
void BPS::decalc()
2024-06-16 05:31:13 -04:00
{
2024-08-05 14:05:59 -04:00
fftwf_destroy_plan(CRev);
fftwf_destroy_plan(CFor);
2024-06-16 05:31:13 -04:00
}
2024-08-05 14:05:59 -04:00
BPS::BPS(
int _run,
int _position,
int _size,
float* _in,
float* _out,
double _f_low,
double _f_high,
int _samplerate,
int _wintype,
double _gain
) :
run(_run),
position(_position),
size(_size),
in(_in),
out(_out),
f_low(_f_low),
f_high(_f_high),
samplerate((double) _samplerate),
wintype(_wintype),
gain(_gain)
2024-06-16 05:31:13 -04:00
{
2024-08-05 14:05:59 -04:00
calc();
2024-06-16 05:31:13 -04:00
}
2024-08-05 14:05:59 -04:00
BPS::~BPS()
2024-06-16 05:31:13 -04:00
{
2024-08-05 14:05:59 -04:00
decalc();
2024-06-16 05:31:13 -04:00
}
2024-08-05 14:05:59 -04:00
void BPS::flush()
2024-06-16 05:31:13 -04:00
{
2024-08-05 14:05:59 -04:00
std::fill(infilt.begin(), infilt.end(), 0);
2024-06-16 05:31:13 -04:00
}
2024-08-05 14:05:59 -04:00
void BPS::execute(int pos)
2024-06-16 05:31:13 -04:00
{
2024-08-05 14:05:59 -04:00
double I;
double Q;
if (run && pos == position)
2024-06-16 05:31:13 -04:00
{
2024-08-05 14:05:59 -04:00
std::copy(in, in + size * 2, &(infilt[2 * size]));
fftwf_execute (CFor);
for (int i = 0; i < 2 * size; i++)
2024-06-16 05:31:13 -04:00
{
2024-08-05 14:05:59 -04:00
I = gain * product[2 * i + 0];
Q = gain * product[2 * i + 1];
product[2 * i + 0] = (float) (I * mults[2 * i + 0] - Q * mults[2 * i + 1]);
product[2 * i + 1] = (float) (I * mults[2 * i + 1] + Q * mults[2 * i + 0]);
2024-06-16 05:31:13 -04:00
}
2024-08-05 14:05:59 -04:00
fftwf_execute (CRev);
std::copy(&(infilt[2 * size]), &(infilt[2 * size]) + size * 2, infilt.begin());
2024-06-16 05:31:13 -04:00
}
2024-08-05 14:05:59 -04:00
else if (in != out)
std::copy( in, in + size * 2, out);
2024-06-16 05:31:13 -04:00
}
2024-08-05 14:05:59 -04:00
void BPS::setBuffers(float* _in, float* _out)
2024-06-16 05:31:13 -04:00
{
2024-08-05 14:05:59 -04:00
decalc();
in = _in;
out = _out;
calc();
2024-06-16 05:31:13 -04:00
}
2024-08-05 14:05:59 -04:00
void BPS::setSamplerate(int rate)
2024-06-16 05:31:13 -04:00
{
2024-08-05 14:05:59 -04:00
decalc();
samplerate = rate;
calc();
2024-06-16 05:31:13 -04:00
}
2024-08-05 14:05:59 -04:00
void BPS::setSize(int _size)
2024-06-16 05:31:13 -04:00
{
2024-08-05 14:05:59 -04:00
decalc();
size = _size;
calc();
2024-06-16 05:31:13 -04:00
}
2024-08-05 14:05:59 -04:00
void BPS::setFreqs(double _f_low, double _f_high)
2024-06-16 05:31:13 -04:00
{
2024-08-05 14:05:59 -04:00
decalc();
f_low = _f_low;
f_high = _f_high;
calc();
2024-06-16 05:31:13 -04:00
}
2024-08-05 14:05:59 -04:00
void BPS::setRun(int _run)
2024-06-16 05:31:13 -04:00
{
2024-08-05 14:05:59 -04:00
run = _run;
2024-06-16 05:31:13 -04:00
}
/********************************************************************************************************
* *
2024-08-05 14:05:59 -04:00
* Overlap-Save Bandpass: RXA Properties *
2024-06-16 05:31:13 -04:00
* *
********************************************************************************************************/
} // namespace WDSP