From 5d69a524f81f234b3fbc41d49ba18d6f6886baba Mon Sep 17 00:00:00 2001 From: jcorgan Date: Thu, 3 Aug 2006 04:51:51 +0000 Subject: Houston, we have a trunk. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@3122 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/general/gr_nco.h | 197 +++++++++++++++++++++++++++++++++ 1 file changed, 197 insertions(+) create mode 100644 gnuradio-core/src/lib/general/gr_nco.h (limited to 'gnuradio-core/src/lib/general/gr_nco.h') diff --git a/gnuradio-core/src/lib/general/gr_nco.h b/gnuradio-core/src/lib/general/gr_nco.h new file mode 100644 index 000000000..2cf41fd77 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_nco.h @@ -0,0 +1,197 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ +#ifndef _GR_NCO_H_ +#define _GR_NCO_H_ + + +#include +#include +#include +#include + +/*! + * \brief base class template for Numerically Controlled Oscillator (NCO) + */ + + +//FIXME Eventually generalize this to fixed point + +template +class gr_nco { +public: + gr_nco () : phase (0), phase_inc(0) {} + + virtual ~gr_nco () {} + + // radians + void set_phase (double angle) { + phase = angle; + } + + void adjust_phase (double delta_phase) { + phase += delta_phase; + } + + + // angle_rate is in radians / step + void set_freq (double angle_rate){ + phase_inc = angle_rate; + } + + // angle_rate is a delta in radians / step + void adjust_freq (double delta_angle_rate) + { + phase_inc += delta_angle_rate; + } + + // increment current phase angle + + void step () + { + phase += phase_inc; + if (fabs (phase) > M_PI){ + + while (phase > M_PI) + phase -= 2*M_PI; + + while (phase < -M_PI) + phase += 2*M_PI; + } + } + + void step (int n) + { + phase += phase_inc * n; + if (fabs (phase) > M_PI){ + + while (phase > M_PI) + phase -= 2*M_PI; + + while (phase < -M_PI) + phase += 2*M_PI; + } + } + + // units are radians / step + double get_phase () const { return phase; } + double get_freq () const { return phase_inc; } + + // compute sin and cos for current phase angle + void sincos (float *sinx, float *cosx) const; + + // compute cos or sin for current phase angle + float cos () const { return std::cos (phase); } + float sin () const { return std::sin (phase); } + + // compute a block at a time + void sin (float *output, int noutput_items, double ampl = 1.0); + void cos (float *output, int noutput_items, double ampl = 1.0); + void sincos (gr_complex *output, int noutput_items, double ampl = 1.0); + void sin (short *output, int noutput_items, double ampl = 1.0); + void cos (short *output, int noutput_items, double ampl = 1.0); + void sin (int *output, int noutput_items, double ampl = 1.0); + void cos (int *output, int noutput_items, double ampl = 1.0); + +protected: + double phase; + double phase_inc; +}; + +template +void +gr_nco::sincos (float *sinx, float *cosx) const +{ + gr_sincosf (phase, sinx, cosx); +} + +template +void +gr_nco::sin (float *output, int noutput_items, double ampl) +{ + for (int i = 0; i < noutput_items; i++){ + output[i] = (float)(sin () * ampl); + step (); + } +} + +template +void +gr_nco::cos (float *output, int noutput_items, double ampl) +{ + for (int i = 0; i < noutput_items; i++){ + output[i] = (float)(cos () * ampl); + step (); + } +} + +template +void +gr_nco::sin (short *output, int noutput_items, double ampl) +{ + for (int i = 0; i < noutput_items; i++){ + output[i] = (short)(sin() * ampl); + step (); + } +} + +template +void +gr_nco::cos (short *output, int noutput_items, double ampl) +{ + for (int i = 0; i < noutput_items; i++){ + output[i] = (short)(cos () * ampl); + step (); + } +} + +template +void +gr_nco::sin (int *output, int noutput_items, double ampl) +{ + for (int i = 0; i < noutput_items; i++){ + output[i] = (int)(sin () * ampl); + step (); + } +} + +template +void +gr_nco::cos (int *output, int noutput_items, double ampl) +{ + for (int i = 0; i < noutput_items; i++){ + output[i] = (int)(cos () * ampl); + step (); + } +} + +template +void +gr_nco::sincos (gr_complex *output, int noutput_items, double ampl) +{ + for (int i = 0; i < noutput_items; i++){ + float cosx, sinx; + sincos (&sinx, &cosx); + output[i] = gr_complex(cosx * ampl, sinx * ampl); + step (); + } +} +#endif /* _NCO_H_ */ -- cgit From 86f5c92427b3f4bb30536d76cf63c3fca388fb2f Mon Sep 17 00:00:00 2001 From: eb Date: Wed, 13 Sep 2006 21:30:04 +0000 Subject: Updated FSF address in all files. Fixes ticket:51 git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@3534 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/general/gr_nco.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gnuradio-core/src/lib/general/gr_nco.h') diff --git a/gnuradio-core/src/lib/general/gr_nco.h b/gnuradio-core/src/lib/general/gr_nco.h index 2cf41fd77..0891ef148 100644 --- a/gnuradio-core/src/lib/general/gr_nco.h +++ b/gnuradio-core/src/lib/general/gr_nco.h @@ -16,8 +16,8 @@ * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifndef _GR_NCO_H_ #define _GR_NCO_H_ -- cgit From 937b719d2e57d0497293d603da10cac2532346f6 Mon Sep 17 00:00:00 2001 From: eb Date: Sat, 21 Jul 2007 03:44:38 +0000 Subject: Updated license from GPL version 2 or later to GPL version 3 or later. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@6044 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/general/gr_nco.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib/general/gr_nco.h') diff --git a/gnuradio-core/src/lib/general/gr_nco.h b/gnuradio-core/src/lib/general/gr_nco.h index 0891ef148..b8da597c6 100644 --- a/gnuradio-core/src/lib/general/gr_nco.h +++ b/gnuradio-core/src/lib/general/gr_nco.h @@ -6,7 +6,7 @@ * * GNU Radio is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) + * the Free Software Foundation; either version 3, or (at your option) * any later version. * * GNU Radio is distributed in the hope that it will be useful, -- cgit From cda71d951ef0cb2126719fed029d459b23a02fe9 Mon Sep 17 00:00:00 2001 From: eb Date: Thu, 24 Jan 2008 16:29:09 +0000 Subject: Doc fixes from Firas. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@7504 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/lib/general/gr_nco.h | 1 + 1 file changed, 1 insertion(+) (limited to 'gnuradio-core/src/lib/general/gr_nco.h') diff --git a/gnuradio-core/src/lib/general/gr_nco.h b/gnuradio-core/src/lib/general/gr_nco.h index b8da597c6..0e740a317 100644 --- a/gnuradio-core/src/lib/general/gr_nco.h +++ b/gnuradio-core/src/lib/general/gr_nco.h @@ -30,6 +30,7 @@ /*! * \brief base class template for Numerically Controlled Oscillator (NCO) + * \ingroup misc */ -- cgit From f919f9dcbb54a08e6e26d6c229ce92fb784fa1b2 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Fri, 13 Apr 2012 18:36:53 -0400 Subject: Removed whitespace and added dtools/bin/remove-whitespace as a tool to do this in the future. The sed script was provided by Moritz Fischer. --- gnuradio-core/src/lib/general/gr_nco.h | 36 +++++++++++++++++----------------- 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'gnuradio-core/src/lib/general/gr_nco.h') diff --git a/gnuradio-core/src/lib/general/gr_nco.h b/gnuradio-core/src/lib/general/gr_nco.h index 0e740a317..fb51106aa 100644 --- a/gnuradio-core/src/lib/general/gr_nco.h +++ b/gnuradio-core/src/lib/general/gr_nco.h @@ -1,19 +1,19 @@ /* -*- c++ -*- */ /* * Copyright 2002 Free Software Foundation, Inc. - * + * * This file is part of GNU Radio - * + * * GNU Radio is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3, or (at your option) * any later version. - * + * * GNU Radio is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -36,7 +36,7 @@ //FIXME Eventually generalize this to fixed point -template +template class gr_nco { public: gr_nco () : phase (0), phase_inc(0) {} @@ -66,11 +66,11 @@ public: // increment current phase angle - void step () - { - phase += phase_inc; + void step () + { + phase += phase_inc; if (fabs (phase) > M_PI){ - + while (phase > M_PI) phase -= 2*M_PI; @@ -83,7 +83,7 @@ public: { phase += phase_inc * n; if (fabs (phase) > M_PI){ - + while (phase > M_PI) phase -= 2*M_PI; @@ -117,14 +117,14 @@ protected: double phase_inc; }; -template +template void gr_nco::sincos (float *sinx, float *cosx) const { gr_sincosf (phase, sinx, cosx); } -template +template void gr_nco::sin (float *output, int noutput_items, double ampl) { @@ -134,7 +134,7 @@ gr_nco::sin (float *output, int noutput_items, double ampl) } } -template +template void gr_nco::cos (float *output, int noutput_items, double ampl) { @@ -144,7 +144,7 @@ gr_nco::cos (float *output, int noutput_items, double ampl) } } -template +template void gr_nco::sin (short *output, int noutput_items, double ampl) { @@ -154,7 +154,7 @@ gr_nco::sin (short *output, int noutput_items, double ampl) } } -template +template void gr_nco::cos (short *output, int noutput_items, double ampl) { @@ -164,7 +164,7 @@ gr_nco::cos (short *output, int noutput_items, double ampl) } } -template +template void gr_nco::sin (int *output, int noutput_items, double ampl) { @@ -174,7 +174,7 @@ gr_nco::sin (int *output, int noutput_items, double ampl) } } -template +template void gr_nco::cos (int *output, int noutput_items, double ampl) { @@ -184,7 +184,7 @@ gr_nco::cos (int *output, int noutput_items, double ampl) } } -template +template void gr_nco::sincos (gr_complex *output, int noutput_items, double ampl) { -- cgit