GNU Radio Manual and C++ API Reference 3.10.5.1
The Free & Open Software Radio Ecosystem
rotator.h
Go to the documentation of this file.
1/* -*- c++ -*- */
2/*
3 * Copyright 2003,2008,2013 Free Software Foundation, Inc.
4 *
5 * This file is part of GNU Radio
6 *
7 * SPDX-License-Identifier: GPL-3.0-or-later
8 *
9 */
10
11#ifndef _GR_ROTATOR_H_
12#define _GR_ROTATOR_H_
13
14#include <gnuradio/blocks/api.h>
15#include <gnuradio/gr_complex.h>
16#include <volk/volk.h>
17#include <cmath>
18
19namespace gr {
20namespace blocks {
21
23{
24private:
25 gr_complex d_phase;
26 gr_complex d_phase_incr;
27 unsigned int d_counter;
28
29public:
30 rotator() : d_phase(1), d_phase_incr(1), d_counter(0) {}
31
32 gr_complex phase() { return d_phase; }
33 void set_phase(gr_complex phase) { d_phase = phase / std::abs(phase); }
34 void set_phase_incr(gr_complex incr) { d_phase_incr = incr / std::abs(incr); }
35
37 {
38 d_counter++;
39
40 gr_complex z = in * d_phase; // rotate in by phase
41 d_phase *= d_phase_incr; // incr our phase (complex mult == add phases)
42
43 if ((d_counter % 512) == 0)
44 d_phase /=
45 std::abs(d_phase); // Normalize to ensure multiplication is rotation
46
47 return z;
48 }
49
50 void rotateN(gr_complex* out, const gr_complex* in, int n)
51 {
52 volk_32fc_s32fc_x2_rotator_32fc(out, in, d_phase_incr, &d_phase, n);
53 }
54};
55
56} /* namespace blocks */
57} /* namespace gr */
58
59#endif /* _GR_ROTATOR_H_ */
Definition: rotator.h:23
void set_phase(gr_complex phase)
Definition: rotator.h:33
gr_complex rotate(gr_complex in)
Definition: rotator.h:36
gr_complex phase()
Definition: rotator.h:32
rotator()
Definition: rotator.h:30
void set_phase_incr(gr_complex incr)
Definition: rotator.h:34
void rotateN(gr_complex *out, const gr_complex *in, int n)
Definition: rotator.h:50
std::complex< float > gr_complex
Definition: gr_complex.h:15
GNU Radio logging wrapper.
Definition: basic_block.h:29