00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
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
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
00064 void sincos (float *sinx, float *cosx) const;
00065
00066
00067 float cos () const { return std::cos (d_phase); }
00068 float sin () const { return std::sin (d_phase); }
00069
00070
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