1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-21 23:55:13 -05:00
sdrangel/wdsp/phrot.cpp

164 lines
3.9 KiB
C++
Raw Permalink Normal View History

2024-07-30 19:37:17 -04:00
/* phrot.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 "phrot.hpp"
namespace WDSP {
/********************************************************************************************************
* *
* Phase Rotator *
* *
********************************************************************************************************/
2024-07-31 18:31:28 -04:00
void PHROT::calc()
2024-07-30 19:37:17 -04:00
{
double g;
2024-08-03 05:05:12 -04:00
x0.resize(nstages);
x1.resize(nstages);
y0.resize(nstages);
y1.resize(nstages);
2024-07-31 18:31:28 -04:00
g = tan (PI * fc / (float)rate);
b0 = (g - 1.0) / (g + 1.0);
b1 = 1.0;
a1 = b0;
2024-07-30 19:37:17 -04:00
}
2024-07-31 18:31:28 -04:00
PHROT::PHROT(
int _run,
int _size,
float* _in,
float* _out,
int _rate,
double _fc,
int _nstages
) :
run(_run),
size(_size),
in(_in),
out(_out),
rate(_rate),
fc(_fc),
nstages(_nstages)
2024-07-30 19:37:17 -04:00
{
2024-08-03 05:05:12 -04:00
reverse = 0;
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 PHROT::flush()
2024-07-30 19:37:17 -04:00
{
2024-07-31 18:31:28 -04:00
std::fill (x0.begin(), x0.end(), 0);
std::fill (x1.begin(), x1.end(), 0);
std::fill (y0.begin(), y0.end(), 0);
std::fill (y1.begin(), y1.end(), 0);
2024-07-30 19:37:17 -04:00
}
2024-07-31 18:31:28 -04:00
void PHROT::execute()
2024-07-30 19:37:17 -04:00
{
2024-07-31 18:31:28 -04:00
if (reverse)
2024-07-30 19:37:17 -04:00
{
2024-07-31 18:31:28 -04:00
for (int i = 0; i < size; i++)
in[2 * i + 0] = -in[2 * i + 0];
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-07-31 18:31:28 -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[0] = in[2 * i + 0];
2024-07-30 19:37:17 -04:00
2024-07-31 18:31:28 -04:00
for (int n = 0; n < nstages; n++)
2024-07-30 19:37:17 -04:00
{
2024-07-31 18:31:28 -04:00
if (n > 0) x0[n] = y0[n - 1];
y0[n] = b0 * x0[n]
+ b1 * x1[n]
- a1 * y1[n];
y1[n] = y0[n];
x1[n] = x0[n];
2024-07-30 19:37:17 -04:00
}
2024-08-03 05:05:12 -04:00
out[2 * i + 0] = (float) y0[nstages - 1];
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 PHROT::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 PHROT::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 PHROT::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
}
/********************************************************************************************************
* *
* TXA Properties *
* *
********************************************************************************************************/
2024-08-03 05:05:12 -04:00
void PHROT::setRun(int _run)
2024-07-30 19:37:17 -04:00
{
2024-08-03 05:05:12 -04:00
run = _run;
2024-07-30 19:37:17 -04:00
2024-07-31 18:31:28 -04:00
if (run)
flush();
2024-07-30 19:37:17 -04:00
}
2024-07-31 18:31:28 -04:00
void PHROT::setCorner(double corner)
2024-07-30 19:37:17 -04:00
{
2024-07-31 18:31:28 -04:00
fc = corner;
calc();
2024-07-30 19:37:17 -04:00
}
2024-07-31 18:31:28 -04:00
void PHROT::setNstages(int _nstages)
2024-07-30 19:37:17 -04:00
{
2024-07-31 18:31:28 -04:00
nstages = _nstages;
calc();
2024-07-30 19:37:17 -04:00
}
2024-07-31 18:31:28 -04:00
void PHROT::setReverse(int _reverse)
2024-07-30 19:37:17 -04:00
{
2024-07-31 18:31:28 -04:00
reverse = _reverse;
2024-07-30 19:37:17 -04:00
}
} // namespace WDSP