GNU Radio Manual and C++ API Reference 3.8.5.0
The Free & Open Software Radio Ecosystem
 
Loading...
Searching...
No Matches
fxpt_nco.h
Go to the documentation of this file.
1/* -*- c++ -*- */
2/*
3 * Copyright 2002,2004,2013 Free Software Foundation, Inc.
4 *
5 * This file is part of GNU Radio
6 *
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
10 * any later version.
11 *
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Radio; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
21 */
22
23#ifndef INCLUDED_GR_FXPT_NCO_H
24#define INCLUDED_GR_FXPT_NCO_H
25
26#include <gnuradio/api.h>
27#include <gnuradio/fxpt.h>
28#include <gnuradio/gr_complex.h>
29#include <stdint.h>
30
31namespace gr {
32
33/*!
34 * \brief Numerically Controlled Oscillator (NCO)
35 * \ingroup misc
36 */
37class /*GR_RUNTIME_API*/ fxpt_nco
38{
39 uint32_t d_phase;
40 int32_t d_phase_inc;
41
42public:
43 fxpt_nco() : d_phase(0), d_phase_inc(0) {}
44
46
47 // radians
48 void set_phase(float angle) { d_phase = gr::fxpt::float_to_fixed(angle); }
49
50 void adjust_phase(float delta_phase)
51 {
52 d_phase += gr::fxpt::float_to_fixed(delta_phase);
53 }
54
55 // angle_rate is in radians / step
56 void set_freq(float angle_rate)
57 {
58 d_phase_inc = gr::fxpt::float_to_fixed(angle_rate);
59 }
60
61 // angle_rate is a delta in radians / step
62 void adjust_freq(float delta_angle_rate)
63 {
64 d_phase_inc += gr::fxpt::float_to_fixed(delta_angle_rate);
65 }
66
67 // increment current phase angle
68
69 void step() { d_phase += d_phase_inc; }
70
71 void step(int n) { d_phase += d_phase_inc * n; }
72
73 // units are radians / step
74 float get_phase() const { return gr::fxpt::fixed_to_float(d_phase); }
75 float get_freq() const { return gr::fxpt::fixed_to_float(d_phase_inc); }
76
77 // compute sin and cos for current phase angle
78 void sincos(float* sinx, float* cosx) const
79 {
80 *sinx = gr::fxpt::sin(d_phase);
81 *cosx = gr::fxpt::cos(d_phase);
82 }
83
84 // compute cos and sin for a block of phase angles
85 void sincos(gr_complex* output, int noutput_items, double ampl = 1.0)
86 {
87 for (int i = 0; i < noutput_items; i++) {
88 output[i] =
89 gr_complex(gr::fxpt::cos(d_phase) * ampl, gr::fxpt::sin(d_phase) * ampl);
90 step();
91 }
92 }
93
94 // compute sin for a block of phase angles
95 void sin(float* output, int noutput_items, double ampl = 1.0)
96 {
97 for (int i = 0; i < noutput_items; i++) {
98 output[i] = (float)(gr::fxpt::sin(d_phase) * ampl);
99 step();
100 }
101 }
102
103 // compute cos for a block of phase angles
104 void cos(float* output, int noutput_items, double ampl = 1.0)
105 {
106 for (int i = 0; i < noutput_items; i++) {
107 output[i] = (float)(gr::fxpt::cos(d_phase) * ampl);
108 step();
109 }
110 }
111
112 // compute sin for a block of phase angles
113 void sin(std::int8_t* output, int noutput_items, double ampl = 1.0)
114 {
115 for (int i = 0; i < noutput_items; i++) {
116 output[i] = (std::int8_t)(gr::fxpt::sin(d_phase) * ampl);
117 step();
118 }
119 }
120
121 // compute cos for a block of phase angles
122 void cos(std::int8_t* output, int noutput_items, double ampl = 1.0)
123 {
124 for (int i = 0; i < noutput_items; i++) {
125 output[i] = (std::int8_t)(gr::fxpt::cos(d_phase) * ampl);
126 step();
127 }
128 }
129
130 // compute sin for a block of phase angles
131 void sin(short* output, int noutput_items, double ampl = 1.0)
132 {
133 for (int i = 0; i < noutput_items; i++) {
134 output[i] = (short)(gr::fxpt::sin(d_phase) * ampl);
135 step();
136 }
137 }
138
139 // compute cos for a block of phase angles
140 void cos(short* output, int noutput_items, double ampl = 1.0)
141 {
142 for (int i = 0; i < noutput_items; i++) {
143 output[i] = (short)(gr::fxpt::cos(d_phase) * ampl);
144 step();
145 }
146 }
147
148 // compute sin for a block of phase angles
149 void sin(int* output, int noutput_items, double ampl = 1.0)
150 {
151 for (int i = 0; i < noutput_items; i++) {
152 output[i] = (int)(gr::fxpt::sin(d_phase) * ampl);
153 step();
154 }
155 }
156
157 // compute cos for a block of phase angles
158 void cos(int* output, int noutput_items, double ampl = 1.0)
159 {
160 for (int i = 0; i < noutput_items; i++) {
161 output[i] = (int)(gr::fxpt::cos(d_phase) * ampl);
162 step();
163 }
164 }
165
166 // compute cos or sin for current phase angle
167 float cos() const { return gr::fxpt::cos(d_phase); }
168 float sin() const { return gr::fxpt::sin(d_phase); }
169};
170
171} /* namespace gr */
172
173#endif /* INCLUDED_GR_FXPT_NCO_H */
Numerically Controlled Oscillator (NCO)
Definition fxpt_nco.h:38
void sin(int *output, int noutput_items, double ampl=1.0)
Definition fxpt_nco.h:149
float get_phase() const
Definition fxpt_nco.h:74
void adjust_freq(float delta_angle_rate)
Definition fxpt_nco.h:62
void adjust_phase(float delta_phase)
Definition fxpt_nco.h:50
void cos(short *output, int noutput_items, double ampl=1.0)
Definition fxpt_nco.h:140
fxpt_nco()
Definition fxpt_nco.h:43
void sincos(gr_complex *output, int noutput_items, double ampl=1.0)
Definition fxpt_nco.h:85
float get_freq() const
Definition fxpt_nco.h:75
void set_freq(float angle_rate)
Definition fxpt_nco.h:56
void cos(int *output, int noutput_items, double ampl=1.0)
Definition fxpt_nco.h:158
void cos(std::int8_t *output, int noutput_items, double ampl=1.0)
Definition fxpt_nco.h:122
~fxpt_nco()
Definition fxpt_nco.h:45
void cos(float *output, int noutput_items, double ampl=1.0)
Definition fxpt_nco.h:104
float cos() const
Definition fxpt_nco.h:167
void sin(short *output, int noutput_items, double ampl=1.0)
Definition fxpt_nco.h:131
void sincos(float *sinx, float *cosx) const
Definition fxpt_nco.h:78
void set_phase(float angle)
Definition fxpt_nco.h:48
void step()
Definition fxpt_nco.h:69
float sin() const
Definition fxpt_nco.h:168
void sin(std::int8_t *output, int noutput_items, double ampl=1.0)
Definition fxpt_nco.h:113
void step(int n)
Definition fxpt_nco.h:71
void sin(float *output, int noutput_items, double ampl=1.0)
Definition fxpt_nco.h:95
static float cos(int32_t x)
Definition fxpt.h:76
static int32_t float_to_fixed(float x)
Definition fxpt.h:52
static float sin(int32_t x)
Given a fixed point angle x, return float sine (x)
Definition fxpt.h:66
static float fixed_to_float(int32_t x)
Definition fxpt.h:61
std::complex< float > gr_complex
Definition gr_complex.h:27
GNU Radio logging wrapper for log4cpp library (C++ port of log4j)
Definition basic_block.h:46