GNU Radio 3.5.3.2 C++ API
|
00001 /* -*- c++ -*- */ 00002 /* 00003 * Copyright 2005 Free Software Foundation, Inc. 00004 * 00005 * This file is part of GNU Radio 00006 * 00007 * GNU Radio is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 3, or (at your option) 00010 * any later version. 00011 * 00012 * GNU Radio is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with GNU Radio; see the file COPYING. If not, write to 00019 * the Free Software Foundation, Inc., 51 Franklin Street, 00020 * Boston, MA 02110-1301, USA. 00021 */ 00022 #ifndef _GR_VCO_H_ 00023 #define _GR_VCO_H_ 00024 00025 00026 #include <vector> 00027 #include <gr_sincos.h> 00028 #include <cmath> 00029 #include <gr_complex.h> 00030 00031 /*! 00032 * \brief base class template for Voltage Controlled Oscillator (VCO) 00033 * \ingroup misc 00034 */ 00035 00036 //FIXME Eventually generalize this to fixed point 00037 00038 template<class o_type, class i_type> 00039 class gr_vco { 00040 public: 00041 gr_vco () : d_phase (0) {} 00042 00043 virtual ~gr_vco () {} 00044 00045 // radians 00046 void set_phase (double angle) { 00047 d_phase = angle; 00048 } 00049 00050 void adjust_phase (double delta_phase) { 00051 d_phase += delta_phase; 00052 if (fabs (d_phase) > M_PI){ 00053 00054 while (d_phase > M_PI) 00055 d_phase -= 2*M_PI; 00056 00057 while (d_phase < -M_PI) 00058 d_phase += 2*M_PI; 00059 } 00060 } 00061 00062 double get_phase () const { return d_phase; } 00063 00064 // compute sin and cos for current phase angle 00065 void sincos (float *sinx, float *cosx) const; 00066 00067 // compute cos or sin for current phase angle 00068 float cos () const { return std::cos (d_phase); } 00069 float sin () const { return std::sin (d_phase); } 00070 00071 // compute a block at a time 00072 void cos (float *output, const float *input, int noutput_items, double k, double ampl = 1.0); 00073 00074 protected: 00075 double d_phase; 00076 }; 00077 00078 template<class o_type, class i_type> 00079 void 00080 gr_vco<o_type,i_type>::sincos (float *sinx, float *cosx) const 00081 { 00082 gr_sincosf (d_phase, sinx, cosx); 00083 } 00084 00085 template<class o_type, class i_type> 00086 void 00087 gr_vco<o_type,i_type>::cos (float *output, const float *input, int noutput_items, double k, double ampl) 00088 { 00089 for (int i = 0; i < noutput_items; i++){ 00090 output[i] = cos() * ampl; 00091 adjust_phase(input[i] * k); 00092 } 00093 } 00094 #endif /* _GR_VCO_H_ */