gr_fxpt_nco.h
Go to the documentation of this file.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
00032 class gr_fxpt_nco {
00033 gr_uint32 d_phase;
00034 gr_int32 d_phase_inc;
00035
00036 public:
00037 gr_fxpt_nco () : d_phase (0), d_phase_inc (0) {}
00038
00039 ~gr_fxpt_nco () {}
00040
00041
00042 void set_phase (float angle) {
00043 d_phase = gr_fxpt::float_to_fixed (angle);
00044 }
00045
00046 void adjust_phase (float delta_phase) {
00047 d_phase += gr_fxpt::float_to_fixed (delta_phase);
00048 }
00049
00050
00051 void set_freq (float angle_rate){
00052 d_phase_inc = gr_fxpt::float_to_fixed (angle_rate);
00053 }
00054
00055
00056 void adjust_freq (float delta_angle_rate)
00057 {
00058 d_phase_inc += gr_fxpt::float_to_fixed (delta_angle_rate);
00059 }
00060
00061
00062
00063 void step ()
00064 {
00065 d_phase += d_phase_inc;
00066 }
00067
00068 void step (int n)
00069 {
00070 d_phase += d_phase_inc * n;
00071 }
00072
00073
00074 float get_phase () const { return gr_fxpt::fixed_to_float (d_phase); }
00075 float get_freq () const { return gr_fxpt::fixed_to_float (d_phase_inc); }
00076
00077
00078 void sincos (float *sinx, float *cosx) const
00079 {
00080 *sinx = gr_fxpt::sin (d_phase);
00081 *cosx = gr_fxpt::cos (d_phase);
00082 }
00083
00084
00085 void sincos (gr_complex *output, int noutput_items, double ampl=1.0)
00086 {
00087 for (int i = 0; i < noutput_items; i++){
00088 output[i] = gr_complex(gr_fxpt::cos (d_phase) * ampl, gr_fxpt::sin (d_phase) * ampl);
00089 step ();
00090 }
00091 }
00092
00093
00094 void sin (float *output, int noutput_items, double ampl=1.0)
00095 {
00096 for (int i = 0; i < noutput_items; i++){
00097 output[i] = (float)(gr_fxpt::sin (d_phase) * ampl);
00098 step ();
00099 }
00100 }
00101
00102
00103 void cos (float *output, int noutput_items, double ampl=1.0)
00104 {
00105 for (int i = 0; i < noutput_items; i++){
00106 output[i] = (float)(gr_fxpt::cos (d_phase) * ampl);
00107 step ();
00108 }
00109 }
00110
00111
00112 void sin (short *output, int noutput_items, double ampl=1.0)
00113 {
00114 for (int i = 0; i < noutput_items; i++){
00115 output[i] = (short)(gr_fxpt::sin (d_phase) * ampl);
00116 step ();
00117 }
00118 }
00119
00120
00121 void cos (short *output, int noutput_items, double ampl=1.0)
00122 {
00123 for (int i = 0; i < noutput_items; i++){
00124 output[i] = (short)(gr_fxpt::cos (d_phase) * ampl);
00125 step ();
00126 }
00127 }
00128
00129
00130 void sin (int *output, int noutput_items, double ampl=1.0)
00131 {
00132 for (int i = 0; i < noutput_items; i++){
00133 output[i] = (int)(gr_fxpt::sin (d_phase) * ampl);
00134 step ();
00135 }
00136 }
00137
00138
00139 void cos (int *output, int noutput_items, double ampl=1.0)
00140 {
00141 for (int i = 0; i < noutput_items; i++){
00142 output[i] = (int)(gr_fxpt::cos (d_phase) * ampl);
00143 step ();
00144 }
00145 }
00146
00147
00148 float cos () const { return gr_fxpt::cos (d_phase); }
00149 float sin () const { return gr_fxpt::sin (d_phase); }
00150 };
00151
00152 #endif