1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-24 08:58:40 -05:00
sdrangel/wdsp/bandpass.cpp

250 lines
6.3 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
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-08-02 02:01:46 -04:00
) :
2024-06-16 05:31:13 -04:00
// NOTE: 'nc' must be >= 'size'
2024-08-02 02:01:46 -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)
{
std::vector<float> impulse;
FIR::fir_bandpass (
impulse,
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)
);
fircore = new FIRCORE(size, in, out, mp, impulse);
2024-06-16 05:31:13 -04:00
}
2024-07-29 18:45:32 -04:00
BANDPASS::~BANDPASS()
2024-06-16 05:31:13 -04:00
{
2024-08-06 00:26:53 -04:00
delete (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-08-06 00:26:53 -04:00
fircore->flush();
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)
2024-08-06 00:26:53 -04:00
fircore->execute();
2024-07-29 18:45:32 -04:00
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;
2024-08-06 00:26:53 -04:00
fircore->setBuffers(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;
std::vector<float> impulse;
FIR::fir_bandpass (
impulse,
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)
);
fircore->setImpulse(impulse, 1);
2024-06-16 05:31:13 -04:00
}
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;
2024-08-06 00:26:53 -04:00
fircore->setSize(size);
2024-06-16 05:31:13 -04:00
// recalc impulse because scale factor is a function of size
std::vector<float> impulse;
FIR::fir_bandpass (
impulse,
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)
);
fircore->setImpulse(impulse, 1);
2024-06-16 05:31:13 -04:00
}
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;
std::vector<float> impulse;
FIR::fir_bandpass (
impulse,
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)
);
fircore->setImpulse(impulse, _update);
2024-06-16 05:31:13 -04:00
}
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;
std::vector<float> impulse;
FIR::fir_bandpass (
impulse,
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)
);
fircore->setImpulse(impulse, 1);
2024-06-16 05:31:13 -04:00
}
}
/********************************************************************************************************
* *
* 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
{
std::vector<float> impulse;
FIR::fir_bandpass (
impulse,
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
fircore->setImpulse(impulse, 0);
2024-07-29 18:45:32 -04:00
f_low = _f_low;
f_high = _f_high;
2024-08-06 00:26:53 -04:00
fircore->setUpdate();
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;
std::vector<float> impulse;
FIR::fir_bandpass (
impulse,
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)
);
fircore->setNc(impulse);
2024-06-16 05:31:13 -04:00
}
}
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;
2024-08-06 00:26:53 -04:00
fircore->setMp(mp);
2024-06-16 05:31:13 -04:00
}
}
/********************************************************************************************************
* *
* TXA Properties *
* *
********************************************************************************************************/
} // namespace WDSP