3 * Copyright 2002,2004 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Radio; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
22 #ifndef INCLUDED_GR_FXPT_NCO_H
23 #define INCLUDED_GR_FXPT_NCO_H
26 #include <gr_complex.h>
29 * \brief Numerically Controlled Oscillator (NCO)
37 gr_fxpt_nco () : d_phase (0), d_phase_inc (0) {}
42 void set_phase (float angle) {
43 d_phase = gr_fxpt::float_to_fixed (angle);
46 void adjust_phase (float delta_phase) {
47 d_phase += gr_fxpt::float_to_fixed (delta_phase);
50 // angle_rate is in radians / step
51 void set_freq (float angle_rate){
52 d_phase_inc = gr_fxpt::float_to_fixed (angle_rate);
55 // angle_rate is a delta in radians / step
56 void adjust_freq (float delta_angle_rate)
58 d_phase_inc += gr_fxpt::float_to_fixed (delta_angle_rate);
61 // increment current phase angle
65 d_phase += d_phase_inc;
70 d_phase += d_phase_inc * n;
73 // units are radians / step
74 float get_phase () const { return gr_fxpt::fixed_to_float (d_phase); }
75 float get_freq () const { return gr_fxpt::fixed_to_float (d_phase_inc); }
77 // compute sin and cos for current phase angle
78 void sincos (float *sinx, float *cosx) const
80 *sinx = gr_fxpt::sin (d_phase);
81 *cosx = gr_fxpt::cos (d_phase);
84 // compute cos and sin for a block of phase angles
85 void sincos (gr_complex *output, int noutput_items, double ampl=1.0)
87 for (int i = 0; i < noutput_items; i++){
88 output[i] = gr_complex(gr_fxpt::cos (d_phase) * ampl, gr_fxpt::sin (d_phase) * ampl);
93 // compute sin for a block of phase angles
94 void sin (float *output, int noutput_items, double ampl=1.0)
96 for (int i = 0; i < noutput_items; i++){
97 output[i] = (float)(gr_fxpt::sin (d_phase) * ampl);
102 // compute cos for a block of phase angles
103 void cos (float *output, int noutput_items, double ampl=1.0)
105 for (int i = 0; i < noutput_items; i++){
106 output[i] = (float)(gr_fxpt::cos (d_phase) * ampl);
111 // compute sin for a block of phase angles
112 void sin (short *output, int noutput_items, double ampl=1.0)
114 for (int i = 0; i < noutput_items; i++){
115 output[i] = (short)(gr_fxpt::sin (d_phase) * ampl);
120 // compute cos for a block of phase angles
121 void cos (short *output, int noutput_items, double ampl=1.0)
123 for (int i = 0; i < noutput_items; i++){
124 output[i] = (short)(gr_fxpt::cos (d_phase) * ampl);
129 // compute sin for a block of phase angles
130 void sin (int *output, int noutput_items, double ampl=1.0)
132 for (int i = 0; i < noutput_items; i++){
133 output[i] = (int)(gr_fxpt::sin (d_phase) * ampl);
138 // compute cos for a block of phase angles
139 void cos (int *output, int noutput_items, double ampl=1.0)
141 for (int i = 0; i < noutput_items; i++){
142 output[i] = (int)(gr_fxpt::cos (d_phase) * ampl);
147 // compute cos or sin for current phase angle
148 float cos () const { return gr_fxpt::cos (d_phase); }
149 float sin () const { return gr_fxpt::sin (d_phase); }
152 #endif /* INCLUDED_GR_FXPT_NCO_H */