GNU Radio Manual and C++ API Reference  3.10.9.1
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  * 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 
18 namespace gr {
19 
20 /*!
21  * \brief Voltage Controlled Oscillator (VCO)
22  * \ingroup misc
23  */
24 class /*GR_RUNTIME_API*/ fxpt_vco
25 {
26  int32_t d_phase;
27 
28 public:
29  fxpt_vco() : d_phase(0) {}
30 
31  ~fxpt_vco() {}
32 
33  // radians
34  void set_phase(float angle) { d_phase = fxpt::float_to_fixed(angle); }
35 
36  void adjust_phase(float delta_phase) { d_phase += fxpt::float_to_fixed(delta_phase); }
37 
38  float get_phase() const { return fxpt::fixed_to_float(d_phase); }
39 
40  // compute sin and cos for current phase angle
41  void sincos(float* sinx, float* cosx) const
42  {
43  *sinx = fxpt::sin(d_phase);
44  *cosx = fxpt::cos(d_phase);
45  }
46 
47  // compute complex sine a block at a time
48  void sincos(gr_complex* output,
49  const float* input,
50  int noutput_items,
51  float k,
52  float ampl = 1.0)
53  {
54  for (int i = 0; i < noutput_items; i++) {
55  output[i] = gr_complex((float)(fxpt::cos(d_phase) * ampl),
56  (float)(fxpt::sin(d_phase) * ampl));
57  adjust_phase(input[i] * k);
58  }
59  }
60 
61  // compute a block at a time
62  void
63  cos(float* output, const float* input, int noutput_items, float k, float ampl = 1.0)
64  {
65  for (int i = 0; i < noutput_items; i++) {
66  output[i] = (float)(fxpt::cos(d_phase) * ampl);
67  adjust_phase(input[i] * k);
68  }
69  }
70 
71  // compute cos or sin for current phase angle
72  float cos() const { return fxpt::cos(d_phase); }
73  float sin() const { return fxpt::sin(d_phase); }
74 };
75 
76 } /* namespace gr */
77 
78 #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:48
void cos(float *output, const float *input, int noutput_items, float k, float ampl=1.0)
Definition: fxpt_vco.h:63
fxpt_vco()
Definition: fxpt_vco.h:29
void set_phase(float angle)
Definition: fxpt_vco.h:34
float sin() const
Definition: fxpt_vco.h:73
~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:72
void sincos(float *sinx, float *cosx) const
Definition: fxpt_vco.h:41
float get_phase() const
Definition: fxpt_vco.h:38
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