00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef INCLUDED_GR_FXPT_NCO_H
00023 #define INCLUDED_GR_FXPT_NCO_H
00024
00025 #include <gr_fxpt.h>
00026 #include <gr_complex.h>
00027
00031 class gr_fxpt_nco {
00032 gr_int32 d_phase;
00033 gr_int32 d_phase_inc;
00034
00035 public:
00036 gr_fxpt_nco () : d_phase (0), d_phase_inc (0) {}
00037
00038 ~gr_fxpt_nco () {}
00039
00040
00041 void set_phase (float angle) {
00042 d_phase = gr_fxpt::float_to_fixed (angle);
00043 }
00044
00045 void adjust_phase (float delta_phase) {
00046 d_phase += gr_fxpt::float_to_fixed (delta_phase);
00047 }
00048
00049
00050 void set_freq (float angle_rate){
00051 d_phase_inc = gr_fxpt::float_to_fixed (angle_rate);
00052 }
00053
00054
00055 void adjust_freq (float delta_angle_rate)
00056 {
00057 d_phase_inc += gr_fxpt::float_to_fixed (delta_angle_rate);
00058 }
00059
00060
00061
00062 void step ()
00063 {
00064 d_phase += d_phase_inc;
00065 }
00066
00067 void step (int n)
00068 {
00069 d_phase += d_phase_inc * n;
00070 }
00071
00072
00073 float get_phase () const { return gr_fxpt::fixed_to_float (d_phase); }
00074 float get_freq () const { return gr_fxpt::fixed_to_float (d_phase_inc); }
00075
00076
00077 void sincos (float *sinx, float *cosx) const
00078 {
00079 *sinx = gr_fxpt::sin (d_phase);
00080 *cosx = gr_fxpt::cos (d_phase);
00081 }
00082
00083
00084 void sincos (gr_complex *output, int noutput_items, double ampl=1.0)
00085 {
00086 for (int i = 0; i < noutput_items; i++){
00087 output[i] = gr_complex(gr_fxpt::cos (d_phase) * ampl, gr_fxpt::sin (d_phase) * ampl);
00088 step ();
00089 }
00090 }
00091
00092
00093 void sin (float *output, int noutput_items, double ampl=1.0)
00094 {
00095 for (int i = 0; i < noutput_items; i++){
00096 output[i] = (float)(gr_fxpt::sin (d_phase) * ampl);
00097 step ();
00098 }
00099 }
00100
00101
00102 void cos (float *output, int noutput_items, double ampl=1.0)
00103 {
00104 for (int i = 0; i < noutput_items; i++){
00105 output[i] = (float)(gr_fxpt::cos (d_phase) * ampl);
00106 step ();
00107 }
00108 }
00109
00110
00111 void sin (short *output, int noutput_items, double ampl=1.0)
00112 {
00113 for (int i = 0; i < noutput_items; i++){
00114 output[i] = (short)(gr_fxpt::sin (d_phase) * ampl);
00115 step ();
00116 }
00117 }
00118
00119
00120 void cos (short *output, int noutput_items, double ampl=1.0)
00121 {
00122 for (int i = 0; i < noutput_items; i++){
00123 output[i] = (short)(gr_fxpt::cos (d_phase) * ampl);
00124 step ();
00125 }
00126 }
00127
00128
00129 void sin (int *output, int noutput_items, double ampl=1.0)
00130 {
00131 for (int i = 0; i < noutput_items; i++){
00132 output[i] = (int)(gr_fxpt::sin (d_phase) * ampl);
00133 step ();
00134 }
00135 }
00136
00137
00138 void cos (int *output, int noutput_items, double ampl=1.0)
00139 {
00140 for (int i = 0; i < noutput_items; i++){
00141 output[i] = (int)(gr_fxpt::cos (d_phase) * ampl);
00142 step ();
00143 }
00144 }
00145
00146
00147 float cos () const { return gr_fxpt::cos (d_phase); }
00148 float sin () const { return gr_fxpt::sin (d_phase); }
00149 };
00150
00151 #endif