root / gnuradio-core / src / lib / general / gr_vco.h @ f3ce47cd
History | View | Annotate | Download (2.3 kB)
| 1 | /* -*- c++ -*- */
|
|---|---|
| 2 | /*
|
| 3 | * Copyright 2005 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 | #ifndef _GR_VCO_H_
|
| 23 | #define _GR_VCO_H_
|
| 24 | |
| 25 | |
| 26 | #include <vector> |
| 27 | #include <gr_sincos.h> |
| 28 | #include <cmath> |
| 29 | #include <gr_complex.h> |
| 30 | |
| 31 | /*!
|
| 32 | * \brief base class template for Voltage Controlled Oscillator (VCO) |
| 33 | * \ingroup misc |
| 34 | */ |
| 35 | |
| 36 | //FIXME Eventually generalize this to fixed point
|
| 37 | |
| 38 | template<class o_type, class i_type> |
| 39 | class gr_vco {
|
| 40 | public:
|
| 41 | gr_vco () : d_phase (0) {}
|
| 42 | |
| 43 | virtual ~gr_vco () {}
|
| 44 | |
| 45 | // radians
|
| 46 | void set_phase (double angle) { |
| 47 | d_phase = angle; |
| 48 | } |
| 49 | |
| 50 | void adjust_phase (double delta_phase) { |
| 51 | d_phase += delta_phase; |
| 52 | if (fabs (d_phase) > M_PI){
|
| 53 | |
| 54 | while (d_phase > M_PI)
|
| 55 | d_phase -= 2*M_PI;
|
| 56 | |
| 57 | while (d_phase < -M_PI)
|
| 58 | d_phase += 2*M_PI;
|
| 59 | } |
| 60 | } |
| 61 | |
| 62 | double get_phase () const { return d_phase; } |
| 63 | |
| 64 | // compute sin and cos for current phase angle
|
| 65 | void sincos (float *sinx, float *cosx) const; |
| 66 | |
| 67 | // compute cos or sin for current phase angle
|
| 68 | float cos () const { return std::cos (d_phase); } |
| 69 | float sin () const { return std::sin (d_phase); } |
| 70 | |
| 71 | // compute a block at a time
|
| 72 | void cos (float *output, const float *input, int noutput_items, double k, double ampl = 1.0); |
| 73 | |
| 74 | protected:
|
| 75 | double d_phase;
|
| 76 | }; |
| 77 | |
| 78 | template<class o_type, class i_type> |
| 79 | void
|
| 80 | gr_vco<o_type,i_type>::sincos (float *sinx, float *cosx) const |
| 81 | {
|
| 82 | gr_sincosf (d_phase, sinx, cosx); |
| 83 | } |
| 84 | |
| 85 | template<class o_type, class i_type> |
| 86 | void
|
| 87 | gr_vco<o_type,i_type>::cos (float *output, const float *input, int noutput_items, double k, double ampl) |
| 88 | {
|
| 89 | for (int i = 0; i < noutput_items; i++){ |
| 90 | output[i] = cos() * ampl; |
| 91 | adjust_phase(input[i] * k); |
| 92 | } |
| 93 | } |
| 94 | #endif /* _GR_VCO_H_ */ |