Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

gr_fxpt.h

Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 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_H
00023 #define INCLUDED_GR_FXPT_H
00024 
00025 #include <gr_types.h>
00026 
00037 class gr_fxpt
00038 {
00039   static const int WORDBITS = 32;
00040   static const int NBITS = 10;
00041   static const float s_sine_table[1 << NBITS][2];
00042   static const float PI = 3.14159265358979323846;
00043   static const float TWO_TO_THE_31 = 2147483648.0;
00044 public:
00045 
00046   static gr_int32
00047   float_to_fixed (float x)
00048   {
00049     return (gr_int32) ((float) x * TWO_TO_THE_31 / PI);
00050   }
00051 
00052   static float
00053   fixed_to_float (gr_int32 x)
00054   {
00055     return x * (PI / TWO_TO_THE_31);
00056   }
00057 
00061   static float
00062   sin (gr_int32 x)
00063   {
00064     gr_uint32 ux = x;
00065     int index = ux >> (WORDBITS - NBITS);
00066     return s_sine_table[index][0] * (ux >> 1) + s_sine_table[index][1];
00067   }
00068 
00069   /*
00070    * \brief Given a fixed point angle x, return float cosine (x)
00071    */
00072   static float
00073   cos (gr_int32 x)
00074   {
00075     gr_uint32 ux = x + 0x40000000;
00076     int index = ux >> (WORDBITS - NBITS);
00077     return s_sine_table[index][0] * (ux >> 1) + s_sine_table[index][1];
00078   }
00079 
00080 };
00081 
00082 #endif /* INCLUDED_GR_FXPT_H */

Generated on Sat Jul 8 17:04:51 2006 for GNU Radio 2.x by  doxygen 1.4.1