1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-09-21 12:26:34 -04:00
sdrangel/wdsp/bandpass.cpp

279 lines
7.6 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 "bandpass.hpp"
#include "fir.hpp"
#include "fircore.hpp"
2024-06-16 05:31:13 -04:00
#include "RXA.hpp"
#include "TXA.hpp"
namespace WDSP {
/********************************************************************************************************
* *
* Partitioned Overlap-Save Bandpass *
* *
********************************************************************************************************/
2024-07-29 18:45:32 -04:00
BANDPASS::BANDPASS(
int _run,
int _position,
int _size,
int _nc,
int _mp,
float* _in,
float* _out,
double _f_low,
double _f_high,
int _samplerate,
int _wintype,
double _gain
)
2024-06-16 05:31:13 -04:00
{
// NOTE: 'nc' must be >= 'size'
2024-07-29 18:45:32 -04:00
run = _run;
position = _position;
size = _size;
nc = _nc;
mp = _mp;
in = _in;
out = _out;
f_low = _f_low;
f_high = _f_high;
samplerate = _samplerate;
wintype = _wintype;
gain = _gain;
float* impulse = FIR::fir_bandpass (
2024-07-29 18:45:32 -04:00
nc,
f_low,
f_high,
samplerate,
wintype,
1,
2024-07-29 18:45:32 -04:00
gain / (double)(2 * size)
);
2024-07-29 18:45:32 -04:00
fircore = FIRCORE::create_fircore (size, in, out, nc, mp, impulse);
2024-06-16 05:31:13 -04:00
delete[] impulse;
}
2024-07-29 18:45:32 -04:00
BANDPASS::~BANDPASS()
2024-06-16 05:31:13 -04:00
{
2024-07-29 18:45:32 -04:00
FIRCORE::destroy_fircore (fircore);
2024-06-16 05:31:13 -04:00
}
2024-07-29 18:45:32 -04:00
void BANDPASS::flush()
2024-06-16 05:31:13 -04:00
{
2024-07-29 18:45:32 -04:00
FIRCORE::flush_fircore(fircore);
2024-06-16 05:31:13 -04:00
}
2024-07-29 18:45:32 -04:00
void BANDPASS::execute(int pos)
2024-06-16 05:31:13 -04:00
{
2024-07-29 18:45:32 -04:00
if (run && position == pos)
FIRCORE::xfircore(fircore);
else if (out != in)
std::copy(in, in + size * 2, out);
2024-06-16 05:31:13 -04:00
}
2024-07-29 18:45:32 -04:00
void BANDPASS::setBuffers(float* _in, float* _out)
2024-06-16 05:31:13 -04:00
{
2024-07-29 18:45:32 -04:00
in = _in;
out = _out;
FIRCORE::setBuffers_fircore(fircore, in, out);
2024-06-16 05:31:13 -04:00
}
2024-07-29 18:45:32 -04:00
void BANDPASS::setSamplerate(int _rate)
2024-06-16 05:31:13 -04:00
{
2024-07-29 18:45:32 -04:00
samplerate = _rate;
float* impulse = FIR::fir_bandpass (
2024-07-29 18:45:32 -04:00
nc,
f_low,
f_high,
samplerate,
wintype,
1,
2024-07-29 18:45:32 -04:00
gain / (double) (2 * size)
);
2024-07-29 18:45:32 -04:00
FIRCORE::setImpulse_fircore (fircore, impulse, 1);
2024-06-16 05:31:13 -04:00
delete[] impulse;
}
2024-07-29 18:45:32 -04:00
void BANDPASS::setSize(int _size)
2024-06-16 05:31:13 -04:00
{
// NOTE: 'size' must be <= 'nc'
2024-07-29 18:45:32 -04:00
size = _size;
FIRCORE::setSize_fircore (fircore, size);
2024-06-16 05:31:13 -04:00
// recalc impulse because scale factor is a function of size
float* impulse = FIR::fir_bandpass (
2024-07-29 18:45:32 -04:00
nc,
f_low,
f_high,
samplerate,
wintype,
1,
2024-07-29 18:45:32 -04:00
gain / (double) (2 * size)
);
2024-07-29 18:45:32 -04:00
FIRCORE::setImpulse_fircore (fircore, impulse, 1);
2024-06-16 05:31:13 -04:00
delete[] (impulse);
}
2024-07-29 18:45:32 -04:00
void BANDPASS::setGain(double _gain, int _update)
2024-06-16 05:31:13 -04:00
{
2024-07-29 18:45:32 -04:00
gain = _gain;
float* impulse = FIR::fir_bandpass (
2024-07-29 18:45:32 -04:00
nc,
f_low,
f_high,
samplerate,
wintype,
1,
2024-07-29 18:45:32 -04:00
gain / (double) (2 * size)
);
2024-07-29 18:45:32 -04:00
FIRCORE::setImpulse_fircore (fircore, impulse, _update);
2024-06-16 05:31:13 -04:00
delete[] (impulse);
}
2024-07-29 18:45:32 -04:00
void BANDPASS::calcBandpassFilter(double _f_low, double _f_high, double _gain)
2024-06-16 05:31:13 -04:00
{
2024-07-29 18:45:32 -04:00
if ((f_low != _f_low) || (f_high != _f_high) || (gain != _gain))
2024-06-16 05:31:13 -04:00
{
2024-07-29 18:45:32 -04:00
f_low = _f_low;
f_high = _f_high;
gain = _gain;
float* impulse = FIR::fir_bandpass (
2024-07-29 18:45:32 -04:00
nc,
f_low,
f_high,
samplerate,
wintype,
1,
2024-07-29 18:45:32 -04:00
gain / (double)(2 * size)
);
2024-07-29 18:45:32 -04:00
FIRCORE::setImpulse_fircore (fircore, impulse, 1);
2024-06-16 05:31:13 -04:00
delete[] (impulse);
}
}
/********************************************************************************************************
* *
* RXA Properties *
* *
********************************************************************************************************/
2024-07-29 18:45:32 -04:00
void BANDPASS::setBandpassFreqs(double _f_low, double _f_high)
2024-06-16 05:31:13 -04:00
{
2024-07-29 18:45:32 -04:00
if ((_f_low != f_low) || (_f_high != f_high))
2024-06-16 05:31:13 -04:00
{
float* impulse = FIR::fir_bandpass (
2024-07-29 18:45:32 -04:00
nc,
_f_low,
_f_high,
samplerate,
wintype,
1,
2024-07-29 18:45:32 -04:00
gain / (double)(2 * size)
);
2024-07-13 17:59:46 -04:00
2024-07-29 18:45:32 -04:00
FIRCORE::setImpulse_fircore (fircore, impulse, 0);
2024-06-16 05:31:13 -04:00
delete[] (impulse);
2024-07-29 18:45:32 -04:00
f_low = _f_low;
f_high = _f_high;
FIRCORE::setUpdate_fircore (fircore);
2024-06-16 05:31:13 -04:00
}
}
2024-07-29 18:45:32 -04:00
void BANDPASS::SetBandpassNC(int _nc)
2024-06-16 05:31:13 -04:00
{
// NOTE: 'nc' must be >= 'size'
2024-07-29 18:45:32 -04:00
if (_nc != nc)
2024-06-16 05:31:13 -04:00
{
2024-07-29 18:45:32 -04:00
nc = _nc;
float* impulse = FIR::fir_bandpass (
2024-07-29 18:45:32 -04:00
nc,
f_low,
f_high,
samplerate,
wintype,
1,
2024-07-29 18:45:32 -04:00
gain / (double)( 2 * size)
);
2024-07-29 18:45:32 -04:00
FIRCORE::setNc_fircore (fircore, nc, impulse);
2024-06-16 05:31:13 -04:00
delete[] (impulse);
}
}
2024-07-29 18:45:32 -04:00
void BANDPASS::SetBandpassMP(int _mp)
2024-06-16 05:31:13 -04:00
{
2024-07-29 18:45:32 -04:00
if (_mp != mp)
2024-06-16 05:31:13 -04:00
{
2024-07-29 18:45:32 -04:00
mp = _mp;
FIRCORE::setMp_fircore (fircore, mp);
2024-06-16 05:31:13 -04:00
}
}
/********************************************************************************************************
* *
* TXA Properties *
* *
********************************************************************************************************/
//PORT
2024-06-24 21:50:48 -04:00
//void SetTXABandpassFreqs (int channel, float f_low, float f_high)
2024-06-16 05:31:13 -04:00
//{
2024-06-24 21:50:48 -04:00
// float* impulse;
2024-06-16 05:31:13 -04:00
// BANDPASS a;
// a = txa.bp0;
2024-06-16 05:31:13 -04:00
// if ((f_low != a->f_low) || (f_high != a->f_high))
// {
// a->f_low = f_low;
// a->f_high = f_high;
2024-06-24 21:50:48 -04:00
// impulse = fir_bandpass (a->nc, a->f_low, a->f_high, a->samplerate, a->wintype, 1, a->gain / (float)(2 * a->size));
2024-07-29 18:45:32 -04:00
// setImpulse_fircore (a->fircore, impulse, 1);
2024-06-16 05:31:13 -04:00
// delete[] (impulse);
// }
// a = txa.bp1;
2024-06-16 05:31:13 -04:00
// if ((f_low != a->f_low) || (f_high != a->f_high))
// {
// a->f_low = f_low;
// a->f_high = f_high;
2024-06-24 21:50:48 -04:00
// impulse = fir_bandpass (a->nc, a->f_low, a->f_high, a->samplerate, a->wintype, 1, a->gain / (float)(2 * a->size));
2024-07-29 18:45:32 -04:00
// setImpulse_fircore (a->fircore, impulse, 1);
2024-06-16 05:31:13 -04:00
// delete[] (impulse);
// }
// a = txa.bp2;
2024-06-16 05:31:13 -04:00
// if ((f_low != a->f_low) || (f_high != a->f_high))
// {
// a->f_low = f_low;
// a->f_high = f_high;
2024-06-24 21:50:48 -04:00
// impulse = fir_bandpass (a->nc, a->f_low, a->f_high, a->samplerate, a->wintype, 1, a->gain / (float)(2 * a->size));
2024-07-29 18:45:32 -04:00
// setImpulse_fircore (a->fircore, impulse, 1);
2024-06-16 05:31:13 -04:00
// delete[] (impulse);
// }
//}
} // namespace WDSP