GNU Radio 2.x: gr_vco.h Source File

Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

# gr_vco.h

Go to the documentation of this file.

    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 2, 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., 59 Temple Place - Suite 330,
    00020  * Boston, MA 02111-1307, 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
    00035 //FIXME  Eventually generalize this to fixed point
    00036
    00037 template<class o_type, class i_type>
    00038 class gr_vco {
    00039 public:
    00040   gr_vco () : d_phase (0) {}
    00041
    00042   virtual ~gr_vco () {}
    00043
    00044   // radians
    00045   void set_phase (double angle) {
    00046     d_phase = angle;
    00047   }
    00048
    00049   void adjust_phase (double delta_phase) {
    00050     d_phase += delta_phase;
    00051     if (fabs (d_phase) > M_PI){
    00052
    00053       while (d_phase > M_PI)
    00054         d_phase -= 2*M_PI;
    00055
    00056       while (d_phase < -M_PI)
    00057         d_phase += 2*M_PI;
    00058     }
    00059   }
    00060
    00061   double get_phase () const { return d_phase; }
    00062
    00063   // compute sin and cos for current phase angle
    00064   void sincos (float *sinx, float *cosx) const;
    00065
    00066   // compute cos or sin for current phase angle
    00067   float cos () const { return std::cos (d_phase); }
    00068   float sin () const { return std::sin (d_phase); }
    00069
    00070   // compute a block at a time
    00071   void cos (float *output, const float *input, int noutput_items, double k, double ampl = 1.0);
    00072
    00073 protected:
    00074   double d_phase;
    00075 };
    00076
    00077 template<class o_type, class i_type>
    00078 void
    00079 gr_vco<o_type,i_type>::sincos (float *sinx, float *cosx) const
    00080 {
    00081   gr_sincosf (d_phase, sinx, cosx);
    00082 }
    00083
    00084 template<class o_type, class i_type>
    00085 void
    00086 gr_vco<o_type,i_type>::cos (float *output, const float *input, int noutput_items, double k, double ampl)
    00087 {
    00088   for (int i = 0; i < noutput_items; i++){
    00089     output[i] = cos() * ampl;
    00090     adjust_phase(input[i] * k);
    00091   }
    00092 }
    00093 #endif /* _GR_VCO_H_ */