1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-22 17:45:48 -05:00
sdrangel/wdsp/bpsnba.cpp

209 lines
5.6 KiB
C++
Raw Normal View History

2024-07-02 18:52:16 -04:00
/* snb.c
This file is part of a program that implements a Software-Defined Radio.
Copyright (C) 2015, 2016 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 "resample.hpp"
#include "lmath.hpp"
#include "fircore.hpp"
2024-07-02 18:52:16 -04:00
#include "nbp.hpp"
#include "amd.hpp"
#include "anf.hpp"
#include "anr.hpp"
#include "emnr.hpp"
#include "bpsnba.hpp"
#define MAXIMP 256
namespace WDSP {
/********************************************************************************************************
* *
* BPSNBA Bandpass Filter *
* *
********************************************************************************************************/
// This is a thin wrapper for a notched-bandpass filter (nbp). The basic difference is that it provides
// for its input and output to happen at different points in the processing pipeline. This means it must
// include a buffer, 'buff'. Its input and output are done via functions xbpshbain() and xbpshbaout().
2024-07-24 17:11:29 -04:00
void BPSNBA::calc()
2024-07-02 18:52:16 -04:00
{
2024-08-02 02:01:46 -04:00
buff.resize(size * 2);
2024-07-24 17:11:29 -04:00
bpsnba = new NBP (
2024-07-02 18:52:16 -04:00
1, // run, always runs (use bpsnba 'run')
2024-07-24 17:11:29 -04:00
run_notches, // run the notches
2024-07-02 18:52:16 -04:00
0, // position variable for nbp (not for bpsnba), always 0
2024-07-24 17:11:29 -04:00
size, // buffer size
nc, // number of filter coefficients
mp, // minimum phase flag
2024-08-02 02:01:46 -04:00
buff.data(), // pointer to input buffer
2024-07-24 17:11:29 -04:00
out, // pointer to output buffer
f_low, // lower filter frequency
f_high, // upper filter frequency
rate, // sample rate
wintype, // wintype
gain, // gain
autoincr, // auto-increase notch width if below min
maxpb, // max number of passbands
notchdb); // addr of database pointer
2024-07-02 18:52:16 -04:00
}
2024-07-24 17:11:29 -04:00
BPSNBA::BPSNBA(
int _run,
int _run_notches,
int _position,
int _size,
int _nc,
int _mp,
float* _in,
float* _out,
int _rate,
double _abs_low_freq,
double _abs_high_freq,
double _f_low,
double _f_high,
int _wintype,
double _gain,
int _autoincr,
int _maxpb,
NOTCHDB* _notchdb
) :
run(_run),
run_notches(_run_notches),
position(_position),
size(_size),
nc(_nc),
mp(_mp),
in(_in),
out(_out),
rate(_rate),
abs_low_freq(_abs_low_freq),
abs_high_freq(_abs_high_freq),
f_low(_f_low),
f_high(_f_high),
wintype(_wintype),
gain(_gain),
autoincr(_autoincr),
maxpb(_maxpb),
notchdb(_notchdb)
2024-07-02 18:52:16 -04:00
{
2024-07-24 17:11:29 -04:00
calc();
2024-07-02 18:52:16 -04:00
}
2024-07-24 17:11:29 -04:00
void BPSNBA::decalc()
2024-07-02 18:52:16 -04:00
{
2024-08-02 02:01:46 -04:00
delete bpsnba;
2024-07-02 18:52:16 -04:00
}
2024-07-24 17:11:29 -04:00
BPSNBA::~BPSNBA()
2024-07-02 18:52:16 -04:00
{
2024-07-24 17:11:29 -04:00
decalc();
2024-07-02 18:52:16 -04:00
}
2024-07-24 17:11:29 -04:00
void BPSNBA::flush()
2024-07-02 18:52:16 -04:00
{
2024-08-02 02:01:46 -04:00
std::fill(buff.begin(), buff.end(), 0);
2024-07-24 17:11:29 -04:00
bpsnba->flush();
2024-07-02 18:52:16 -04:00
}
2024-07-24 17:11:29 -04:00
void BPSNBA::setBuffers(float* _in, float* _out)
2024-07-02 18:52:16 -04:00
{
2024-07-24 17:11:29 -04:00
decalc();
in = _in;
out = _out;
calc();
2024-07-02 18:52:16 -04:00
}
2024-07-24 17:11:29 -04:00
void BPSNBA::setSamplerate(int _rate)
2024-07-02 18:52:16 -04:00
{
2024-07-24 17:11:29 -04:00
decalc();
rate = _rate;
calc();
2024-07-02 18:52:16 -04:00
}
2024-07-24 17:11:29 -04:00
void BPSNBA::setSize(int _size)
2024-07-02 18:52:16 -04:00
{
2024-07-24 17:11:29 -04:00
decalc();
size = _size;
calc();
2024-07-02 18:52:16 -04:00
}
2024-07-24 17:11:29 -04:00
void BPSNBA::exec_in(int _position)
2024-07-02 18:52:16 -04:00
{
2024-07-24 17:11:29 -04:00
if (run && position == _position)
2024-08-02 02:01:46 -04:00
std::copy(in, in + size * 2, buff.begin());
2024-07-02 18:52:16 -04:00
}
2024-07-24 17:11:29 -04:00
void BPSNBA::exec_out(int _position)
2024-07-02 18:52:16 -04:00
{
2024-07-24 17:11:29 -04:00
if (run && position == _position)
bpsnba->execute(0);
2024-07-02 18:52:16 -04:00
}
2024-07-24 17:11:29 -04:00
void BPSNBA::recalc_bpsnba_filter(int update)
2024-07-02 18:52:16 -04:00
{
// Call anytime one of the parameters listed below has been changed in
// the BPSNBA struct.
2024-07-24 17:11:29 -04:00
NBP *b = bpsnba;
b->fnfrun = run_notches;
b->flow = f_low;
b->fhigh = f_high;
b->wintype = wintype;
b->gain = gain;
b->autoincr = autoincr;
b->calc_impulse();
b->fircore->setImpulse(b->impulse, update);
2024-07-02 18:52:16 -04:00
}
/********************************************************************************************************
* *
2024-07-24 17:11:29 -04:00
* Properties *
2024-07-02 18:52:16 -04:00
* *
********************************************************************************************************/
2024-07-24 17:11:29 -04:00
void BPSNBA::SetNC(int _nc)
2024-07-02 18:52:16 -04:00
{
2024-07-24 17:11:29 -04:00
if (nc != _nc)
2024-07-02 18:52:16 -04:00
{
2024-07-24 17:11:29 -04:00
nc = _nc;
bpsnba->nc = nc;
bpsnba->setNc();
2024-07-02 18:52:16 -04:00
}
}
2024-07-24 17:11:29 -04:00
void BPSNBA::SetMP(int _mp)
2024-07-02 18:52:16 -04:00
{
2024-07-24 17:11:29 -04:00
if (mp != _mp)
2024-07-02 18:52:16 -04:00
{
2024-07-24 17:11:29 -04:00
mp = _mp;
bpsnba->mp = mp;
bpsnba->setMp();
2024-07-02 18:52:16 -04:00
}
}
} // namespace