00001 /* -*- c++ -*- */ 00002 /* 00003 * Copyright 2002,2004 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 INCLUDED_GR_FXPT_NCO_H 00023 #define INCLUDED_GR_FXPT_NCO_H 00024 00025 #include <gr_fxpt.h> 00026 00030 class gr_fxpt_nco { 00031 gr_int32 d_phase; 00032 gr_int32 d_phase_inc; 00033 00034 public: 00035 gr_fxpt_nco () : d_phase (0), d_phase_inc (0) {} 00036 00037 ~gr_fxpt_nco () {} 00038 00039 // radians 00040 void set_phase (float angle) { 00041 d_phase = gr_fxpt::float_to_fixed (angle); 00042 } 00043 00044 void adjust_phase (float delta_phase) { 00045 d_phase += gr_fxpt::float_to_fixed (delta_phase); 00046 } 00047 00048 // angle_rate is in radians / step 00049 void set_freq (float angle_rate){ 00050 d_phase_inc = gr_fxpt::float_to_fixed (angle_rate); 00051 } 00052 00053 // angle_rate is a delta in radians / step 00054 void adjust_freq (float delta_angle_rate) 00055 { 00056 d_phase_inc += gr_fxpt::float_to_fixed (delta_angle_rate); 00057 } 00058 00059 // increment current phase angle 00060 00061 void step () 00062 { 00063 d_phase += d_phase_inc; 00064 } 00065 00066 void step (int n) 00067 { 00068 d_phase += d_phase_inc * n; 00069 } 00070 00071 // units are radians / step 00072 float get_phase () const { return gr_fxpt::fixed_to_float (d_phase); } 00073 float get_freq () const { return gr_fxpt::fixed_to_float (d_phase_inc); } 00074 00075 // compute sin and cos for current phase angle 00076 void sincos (float *sinx, float *cosx) const 00077 { 00078 *sinx = gr_fxpt::sin (d_phase); 00079 *cosx = gr_fxpt::cos (d_phase); 00080 } 00081 00082 // compute cos or sin for current phase angle 00083 float cos () const { return gr_fxpt::cos (d_phase); } 00084 float sin () const { return gr_fxpt::sin (d_phase); } 00085 }; 00086 00087 #endif /* INCLUDED_GR_FXPT_NCO_H */