1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-25 01:18:38 -05:00
sdrangel/wdsp/snotch.cpp

138 lines
3.4 KiB
C++
Raw Permalink Normal View History

2024-07-30 19:37:17 -04:00
/* iir.c
This file is part of a program that implements a Software-Defined Radio.
Copyright (C) 2014, 2022, 2023 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 "snotch.hpp"
namespace WDSP {
/********************************************************************************************************
* *
* Bi-Quad Notch *
* *
********************************************************************************************************/
2024-07-31 18:31:28 -04:00
void SNOTCH::calc()
2024-07-30 19:37:17 -04:00
{
2024-08-03 05:05:12 -04:00
double fn;
double qk;
double qr;
double csn;
fn = f / rate;
2024-07-30 19:37:17 -04:00
csn = cos (TWOPI * fn);
2024-07-31 18:31:28 -04:00
qr = 1.0 - 3.0 * bw;
2024-07-30 19:37:17 -04:00
qk = (1.0 - 2.0 * qr * csn + qr * qr) / (2.0 * (1.0 - csn));
2024-07-31 18:31:28 -04:00
a0 = + qk;
a1 = - 2.0 * qk * csn;
a2 = + qk;
b1 = + 2.0 * qr * csn;
b2 = - qr * qr;
flush();
2024-07-30 19:37:17 -04:00
}
2024-07-31 18:31:28 -04:00
SNOTCH::SNOTCH(
int _run,
int _size,
float* _in,
float* _out,
int _rate,
double _f,
double _bw
) :
run(_run),
size(_size),
in(_in),
out(_out),
rate(_rate),
f(_f),
bw(_bw)
2024-07-30 19:37:17 -04:00
{
2024-07-31 18:31:28 -04:00
calc();
2024-07-30 19:37:17 -04:00
}
2024-07-31 18:31:28 -04:00
void SNOTCH::flush()
2024-07-30 19:37:17 -04:00
{
2024-07-31 18:31:28 -04:00
x1 = x2 = y1 = y2 = 0.0;
2024-07-30 19:37:17 -04:00
}
2024-07-31 18:31:28 -04:00
void SNOTCH::execute()
2024-07-30 19:37:17 -04:00
{
2024-07-31 18:31:28 -04:00
if (run)
2024-07-30 19:37:17 -04:00
{
2024-08-03 05:05:12 -04:00
for (int i = 0; i < size; i++)
2024-07-30 19:37:17 -04:00
{
2024-07-31 18:31:28 -04:00
x0 = in[2 * i + 0];
2024-08-03 05:05:12 -04:00
out[2 * i + 0] = (float) (a0 * x0 + a1 * x1 + a2 * x2 + b1 * y1 + b2 * y2);
2024-07-31 18:31:28 -04:00
y2 = y1;
y1 = out[2 * i + 0];
x2 = x1;
x1 = x0;
2024-07-30 19:37:17 -04:00
}
}
2024-07-31 18:31:28 -04:00
else if (out != in)
2024-07-30 19:37:17 -04:00
{
2024-07-31 18:31:28 -04:00
std::copy( in, in + size * 2, out);
2024-07-30 19:37:17 -04:00
}
}
2024-07-31 18:31:28 -04:00
void SNOTCH::setBuffers(float* _in, float* _out)
2024-07-30 19:37:17 -04:00
{
2024-07-31 18:31:28 -04:00
in = _in;
out = _out;
2024-07-30 19:37:17 -04:00
}
2024-07-31 18:31:28 -04:00
void SNOTCH::setSamplerate(int _rate)
2024-07-30 19:37:17 -04:00
{
2024-07-31 18:31:28 -04:00
rate = _rate;
calc();
2024-07-30 19:37:17 -04:00
}
2024-07-31 18:31:28 -04:00
void SNOTCH::setSize(int _size)
2024-07-30 19:37:17 -04:00
{
2024-07-31 18:31:28 -04:00
size = _size;
flush();
2024-07-30 19:37:17 -04:00
}
/********************************************************************************************************
* *
* RXA Properties *
* *
********************************************************************************************************/
2024-07-31 18:31:28 -04:00
void SNOTCH::setFreq(double _freq)
2024-07-30 19:37:17 -04:00
{
2024-07-31 18:31:28 -04:00
f = _freq;
calc();
2024-07-30 19:37:17 -04:00
}
2024-07-31 18:31:28 -04:00
void SNOTCH::setRun(int _run)
2024-07-30 19:37:17 -04:00
{
2024-07-31 18:31:28 -04:00
run = _run;
2024-07-30 19:37:17 -04:00
}
} // namespace WDSP