Main Page | Namespace List | Class Hierarchy | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages

GrFractionalInterpolatingSigProc.h

Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2002 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 
00023 #ifndef _GRFRACTIONALINTERPOLATINGSIGPROC_H_
00024 #define _GRFRACTIONALINTERPOLATINGSIGPROC_H_
00025 
00026 #include <VrHistoryProc.h>
00027 #include <stdlib.h>
00028 #include <gr_math.h>
00029 #include <gr_mmse_fir_interpolator.h>
00030 
00035 template<class iType, class oType>
00036 class GrFractionalInterpolatingSigProc : public VrHistoryProc<iType,oType>
00037 {
00038  public:
00039   GrFractionalInterpolatingSigProc (int outputs, int arg_N, int arg_M)
00040     : VrHistoryProc<iType,oType>(outputs), N(arg_N), M(arg_M) {}
00041 
00042   GrFractionalInterpolatingSigProc (int arg_N, int arg_M)
00043     : VrHistoryProc<iType,oType>(1), N(arg_N), M(arg_M) {}
00044 
00045   ~GrFractionalInterpolatingSigProc () {};
00046 
00047   void pre_initialize ();
00048   int forecast (VrSampleRange output, VrSampleRange inputs[]);
00049 
00050 protected:
00051   int           N;      // numerator of ratio
00052   int           M;      // denominator of ratio
00053   int           iratio; // smallest integer multiple of N/M
00054 };
00055 
00056 template<class iType,class oType> int
00057 GrFractionalInterpolatingSigProc<iType,oType>::forecast(VrSampleRange output,
00058                                                         VrSampleRange inputs[]) {
00059   /* 1:iratio ratio */
00060   /*
00061    * Note that this code only works correctly if output size of the
00062    * module (set using setOutputSize(n) in pre_initialize() ) is a multiple
00063    * of iratio.
00064    */
00065   assert ((output.size % iratio) == 0);
00066   
00067   for(unsigned int i=0;i<numberInputs;i++) {
00068     inputs[i].index=output.index/iratio; /* ! do not subtract history ! */
00069     inputs[i].size=output.size/iratio + history-1;
00070   }
00071   return 0;
00072 }  
00073 
00074 
00075 template<class iType,class oType> void 
00076 GrFractionalInterpolatingSigProc<iType,oType>::pre_initialize ()
00077 {
00078   if (getSamplingFrequency () == 0.0)
00079     setSamplingFrequency ((getInputSamplingFrequencyN (0) * N) / M);
00080 
00081   // reduce N/M to lowest terms and then use N*M as the size
00082 
00083   int d = gr_gcd (N, M);
00084   iratio = (N * M) / (d * d);
00085   
00086   setOutputSize(iratio);
00087 }
00088 
00089 #endif /* _GRFRACTIONALINTERPOLATINGSIGPROC_H_ */

Generated on Tue Mar 30 21:31:48 2004 for GNU Radio by doxygen 1.3.2