2024-06-16 05:31:13 -04:00
|
|
|
/* shift.c
|
|
|
|
|
|
|
|
This file is part of a program that implements a Software-Defined Radio.
|
|
|
|
|
|
|
|
Copyright (C) 2013 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 "shift.hpp"
|
|
|
|
#include "RXA.hpp"
|
|
|
|
|
|
|
|
namespace WDSP {
|
|
|
|
|
2024-07-23 22:33:42 -04:00
|
|
|
void SHIFT::calc_shift()
|
2024-06-16 05:31:13 -04:00
|
|
|
{
|
2024-07-23 22:33:42 -04:00
|
|
|
delta = TWOPI * shift / rate;
|
|
|
|
cos_delta = cos (delta);
|
|
|
|
sin_delta = sin (delta);
|
2024-06-16 05:31:13 -04:00
|
|
|
}
|
|
|
|
|
2024-07-23 22:33:42 -04:00
|
|
|
SHIFT::SHIFT (int _run, int _size, float* _in, float* _out, int _rate, double _fshift)
|
2024-06-16 05:31:13 -04:00
|
|
|
{
|
2024-07-23 22:33:42 -04:00
|
|
|
run = _run;
|
|
|
|
size = _size;
|
|
|
|
in = _in;
|
|
|
|
out = _out;
|
|
|
|
rate = (double) _rate;
|
|
|
|
shift = _fshift;
|
|
|
|
phase = 0.0;
|
|
|
|
calc_shift();
|
2024-06-16 05:31:13 -04:00
|
|
|
}
|
|
|
|
|
2024-07-23 22:33:42 -04:00
|
|
|
void SHIFT::flush()
|
2024-06-16 05:31:13 -04:00
|
|
|
{
|
2024-07-23 22:33:42 -04:00
|
|
|
phase = 0.0;
|
2024-06-16 05:31:13 -04:00
|
|
|
}
|
|
|
|
|
2024-07-23 22:33:42 -04:00
|
|
|
void SHIFT::execute()
|
2024-06-16 05:31:13 -04:00
|
|
|
{
|
2024-07-23 22:33:42 -04:00
|
|
|
if (run)
|
2024-06-16 05:31:13 -04:00
|
|
|
{
|
|
|
|
int i;
|
2024-07-17 15:19:57 -04:00
|
|
|
double I1, Q1, t1, t2;
|
2024-07-23 22:33:42 -04:00
|
|
|
double cos_phase = cos (phase);
|
|
|
|
double sin_phase = sin (phase);
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-07-23 22:33:42 -04:00
|
|
|
for (i = 0; i < size; i++)
|
2024-06-16 05:31:13 -04:00
|
|
|
{
|
2024-07-23 22:33:42 -04:00
|
|
|
I1 = in[2 * i + 0];
|
|
|
|
Q1 = in[2 * i + 1];
|
|
|
|
out[2 * i + 0] = I1 * cos_phase - Q1 * sin_phase;
|
|
|
|
out[2 * i + 1] = I1 * sin_phase + Q1 * cos_phase;
|
2024-06-16 05:31:13 -04:00
|
|
|
t1 = cos_phase;
|
|
|
|
t2 = sin_phase;
|
2024-07-23 22:33:42 -04:00
|
|
|
cos_phase = t1 * cos_delta - t2 * sin_delta;
|
|
|
|
sin_phase = t1 * sin_delta + t2 * cos_delta;
|
|
|
|
phase += delta;
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-07-23 22:33:42 -04:00
|
|
|
if (phase >= TWOPI)
|
|
|
|
phase -= TWOPI;
|
2024-07-17 15:19:57 -04:00
|
|
|
|
2024-07-23 22:33:42 -04:00
|
|
|
if (phase < 0.0 )
|
|
|
|
phase += TWOPI;
|
2024-06-16 05:31:13 -04:00
|
|
|
}
|
|
|
|
}
|
2024-07-23 22:33:42 -04:00
|
|
|
else if (in != out)
|
2024-07-17 15:19:57 -04:00
|
|
|
{
|
2024-07-23 22:33:42 -04:00
|
|
|
std::copy( in, in + size * 2, out);
|
2024-07-17 15:19:57 -04:00
|
|
|
}
|
2024-06-16 05:31:13 -04:00
|
|
|
}
|
|
|
|
|
2024-07-23 22:33:42 -04:00
|
|
|
void SHIFT::setBuffers(float* _in, float* _out)
|
2024-06-16 05:31:13 -04:00
|
|
|
{
|
2024-07-23 22:33:42 -04:00
|
|
|
in = _in;
|
|
|
|
out = _out;
|
2024-06-16 05:31:13 -04:00
|
|
|
}
|
|
|
|
|
2024-07-23 22:33:42 -04:00
|
|
|
void SHIFT::setSamplerate(int _rate)
|
2024-06-16 05:31:13 -04:00
|
|
|
{
|
2024-07-23 22:33:42 -04:00
|
|
|
rate = _rate;
|
|
|
|
phase = 0.0;
|
|
|
|
calc_shift();
|
2024-06-16 05:31:13 -04:00
|
|
|
}
|
|
|
|
|
2024-07-23 22:33:42 -04:00
|
|
|
void SHIFT::setSize(int _size)
|
2024-06-16 05:31:13 -04:00
|
|
|
{
|
2024-07-23 22:33:42 -04:00
|
|
|
size = _size;
|
|
|
|
flush();
|
2024-06-16 05:31:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************************************
|
|
|
|
* *
|
2024-07-23 22:33:42 -04:00
|
|
|
* Non static *
|
2024-06-16 05:31:13 -04:00
|
|
|
* *
|
|
|
|
********************************************************************************************************/
|
|
|
|
|
2024-07-23 22:33:42 -04:00
|
|
|
void SHIFT::SetRun (int _run)
|
2024-06-16 05:31:13 -04:00
|
|
|
{
|
2024-07-23 22:33:42 -04:00
|
|
|
run = _run;
|
2024-06-16 05:31:13 -04:00
|
|
|
}
|
|
|
|
|
2024-07-23 22:33:42 -04:00
|
|
|
void SHIFT::SetFreq(double fshift)
|
2024-06-16 05:31:13 -04:00
|
|
|
{
|
2024-07-23 22:33:42 -04:00
|
|
|
shift = fshift;
|
|
|
|
calc_shift();
|
2024-06-16 05:31:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace WDSP
|