GNU Radio Manual and C++ API Reference 3.7.14.0
The Free & Open Software Radio Ecosystem
fxpt_vco.h
Go to the documentation of this file.
1/* -*- c++ -*- */
2/*
3 * Copyright 2002,2004,2005,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_VCO_H
24#define INCLUDED_GR_FXPT_VCO_H
25
26#include <gnuradio/api.h>
27#include <gnuradio/fxpt.h>
28#include <gnuradio/gr_complex.h>
29
30namespace gr {
31
32/*!
33 * \brief Voltage Controlled Oscillator (VCO)
34 * \ingroup misc
35 */
36class /*GR_RUNTIME_API*/ fxpt_vco
37{
38 int32_t d_phase;
39
40public:
41 fxpt_vco() : d_phase(0) {}
42
44
45 // radians
46 void set_phase(float angle) { d_phase = fxpt::float_to_fixed(angle); }
47
48 void adjust_phase(float delta_phase) { d_phase += fxpt::float_to_fixed(delta_phase); }
49
50 float get_phase() const { return fxpt::fixed_to_float(d_phase); }
51
52 // compute sin and cos for current phase angle
53 void sincos(float* sinx, float* cosx) const
54 {
55 *sinx = fxpt::sin(d_phase);
56 *cosx = fxpt::cos(d_phase);
57 }
58
59 // compute complex sine a block at a time
60 void sincos(gr_complex* output,
61 const float* input,
62 int noutput_items,
63 float k,
64 float ampl = 1.0)
65 {
66 for (int i = 0; i < noutput_items; i++) {
67 output[i] = gr_complex((float)(fxpt::cos(d_phase) * ampl),
68 (float)(fxpt::sin(d_phase) * ampl));
69 adjust_phase(input[i] * k);
70 }
71 }
72
73 // compute a block at a time
74 void
75 cos(float* output, const float* input, int noutput_items, float k, float ampl = 1.0)
76 {
77 for (int i = 0; i < noutput_items; i++) {
78 output[i] = (float)(fxpt::cos(d_phase) * ampl);
79 adjust_phase(input[i] * k);
80 }
81 }
82
83 // compute cos or sin for current phase angle
84 float cos() const { return fxpt::cos(d_phase); }
85 float sin() const { return fxpt::sin(d_phase); }
86};
87
88} /* namespace gr */
89
90#endif /* INCLUDED_GR_FXPT_VCO_H */
Voltage Controlled Oscillator (VCO)
Definition: fxpt_vco.h:37
void sincos(gr_complex *output, const float *input, int noutput_items, float k, float ampl=1.0)
Definition: fxpt_vco.h:60
void cos(float *output, const float *input, int noutput_items, float k, float ampl=1.0)
Definition: fxpt_vco.h:75
fxpt_vco()
Definition: fxpt_vco.h:41
void set_phase(float angle)
Definition: fxpt_vco.h:46
float sin() const
Definition: fxpt_vco.h:85
~fxpt_vco()
Definition: fxpt_vco.h:43
void adjust_phase(float delta_phase)
Definition: fxpt_vco.h:48
float cos() const
Definition: fxpt_vco.h:84
void sincos(float *sinx, float *cosx) const
Definition: fxpt_vco.h:53
float get_phase() const
Definition: fxpt_vco.h:50
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
Include this header to use the message passing features.
Definition: basic_block.h:45