GNU Radio C++ API Reference 3.10.12.0
The Free & Open Software Radio Ecosystem
 
Loading...
Searching...
No Matches
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 * SPDX-License-Identifier: GPL-3.0-or-later
8 *
9 */
10
11#ifndef INCLUDED_GR_FXPT_VCO_H
12#define INCLUDED_GR_FXPT_VCO_H
13
14#include <gnuradio/api.h>
15#include <gnuradio/fxpt.h>
16#include <gnuradio/gr_complex.h>
17
18namespace gr {
19
20/*!
21 * \brief Voltage Controlled Oscillator (VCO)
22 * \ingroup misc
23 */
24class /*GR_RUNTIME_API*/ fxpt_vco
25{
26 int32_t d_phase;
27
28public:
29 fxpt_vco() : d_phase(0) {}
30
32
33 // radians
34 void set_phase(float angle) { d_phase = fxpt::float_to_fixed(angle); }
35
36 void adjust_phase(float delta_phase)
37 {
38 d_phase += (uint32_t)fxpt::float_to_fixed(delta_phase);
39 }
40
41 float get_phase() const { return fxpt::fixed_to_float(d_phase); }
42
43 // compute sin and cos for current phase angle
44 void sincos(float* sinx, float* cosx) const
45 {
46 *sinx = fxpt::sin(d_phase);
47 *cosx = fxpt::cos(d_phase);
48 }
49
50 // compute complex sine a block at a time
51 void sincos(gr_complex* output,
52 const float* input,
53 int noutput_items,
54 float k,
55 float ampl = 1.0)
56 {
57 for (int i = 0; i < noutput_items; i++) {
58 output[i] = gr_complex((float)(fxpt::cos(d_phase) * ampl),
59 (float)(fxpt::sin(d_phase) * ampl));
60 adjust_phase(input[i] * k);
61 }
62 }
63
64 // compute a block at a time
65 void
66 cos(float* output, const float* input, int noutput_items, float k, float ampl = 1.0)
67 {
68 for (int i = 0; i < noutput_items; i++) {
69 output[i] = (float)(fxpt::cos(d_phase) * ampl);
70 adjust_phase(input[i] * k);
71 }
72 }
73
74 // compute cos or sin for current phase angle
75 float cos() const { return fxpt::cos(d_phase); }
76 float sin() const { return fxpt::sin(d_phase); }
77};
78
79} /* namespace gr */
80
81#endif /* INCLUDED_GR_FXPT_VCO_H */
Voltage Controlled Oscillator (VCO)
Definition fxpt_vco.h:25
void sincos(gr_complex *output, const float *input, int noutput_items, float k, float ampl=1.0)
Definition fxpt_vco.h:51
void cos(float *output, const float *input, int noutput_items, float k, float ampl=1.0)
Definition fxpt_vco.h:66
fxpt_vco()
Definition fxpt_vco.h:29
void set_phase(float angle)
Definition fxpt_vco.h:34
float sin() const
Definition fxpt_vco.h:76
~fxpt_vco()
Definition fxpt_vco.h:31
void adjust_phase(float delta_phase)
Definition fxpt_vco.h:36
float cos() const
Definition fxpt_vco.h:75
void sincos(float *sinx, float *cosx) const
Definition fxpt_vco.h:44
float get_phase() const
Definition fxpt_vco.h:41
static float cos(int32_t x)
Definition fxpt.h:65
static int32_t float_to_fixed(float x)
Definition fxpt.h:41
static float sin(int32_t x)
Given a fixed point angle x, return float sine (x)
Definition fxpt.h:55
static float fixed_to_float(int32_t x)
Definition fxpt.h:50
std::complex< float > gr_complex
Definition gr_complex.h:15
GNU Radio logging wrapper.
Definition basic_block.h:29