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

GrInterpolator.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 _GRINTERPOLATOR_H_ 00024 #define _GRINTERPOLATOR_H_ 00025 00026 #include <GrFractionalInterpolatingSigProc.h> 00027 #include <stdlib.h> 00028 #include <gr_mmse_fir_interpolator.h> 00029 00038 template<class iType, class oType> 00039 class GrInterpolator : public GrFractionalInterpolatingSigProc<iType,oType> 00040 { 00041 public: 00043 GrInterpolator (int N, int M, int phase = 0); 00044 ~GrInterpolator () {}; 00045 00046 const char *name () { return "GrInterpolator"; } 00047 int work (VrSampleRange output, void *ao[], VrSampleRange inputs[], void *ai[]); 00048 00049 protected: 00050 int phase; 00051 gr_mmse_fir_interpolator intr; 00052 }; 00053 00054 template<class iType,class oType> 00055 GrInterpolator<iType,oType>::GrInterpolator (int N, int M, int _phase = 0) 00056 : GrFractionalInterpolatingSigProc<iType,oType>(N, M), phase (_phase) 00057 { 00058 if (N != 10){ 00059 cerr << "GrInterpolator: N must be 10\n"; 00060 exit (1); 00061 } 00062 if (M < 0 || M > 10){ 00063 cerr << "GrInterpolator: M must be in [1, 10]\n"; 00064 exit (1); 00065 } 00066 if (phase < 0 || phase > N){ 00067 cerr << "GrInterpolator: phase must be in [0, N]\n"; 00068 exit (1); 00069 } 00070 00071 history = intr.ntaps () + 1; 00072 } 00073 00074 template<class iType,class oType> 00075 int 00076 GrInterpolator<iType,oType>::work (VrSampleRange output, void *ao[], 00077 VrSampleRange inputs[], void *ai[]) 00078 { 00079 iType *in = ((iType **) ai)[0]; 00080 oType *out = ((oType **) ao)[0]; 00081 00082 assert ((output.size % iratio) == 0); 00083 00084 float mu = (float) phase / N; // fractional delay 00085 float mu_inc = (float) M / N; 00086 00087 unsigned ii = 0; // input index 00088 unsigned oo = 0; // output index 00089 00090 while (oo < output.size){ 00091 out[oo++] = intr.interpolate (&in[ii], 1.0 - mu); 00092 00093 // printf ("%4d %9.6f\n", ii, mu); 00094 00095 float s = mu + mu_inc; 00096 float f = floor (s); 00097 int incr = (int) f; 00098 mu = s - f; 00099 ii += incr; 00100 } 00101 00102 assert (mu == ((float) phase / N)); 00103 00104 return output.size; 00105 } 00106 00107 00108 #endif /* _GRINTERPOLATOR_H_ */

Generated on Wed Aug 4 02:22:04 2004 for GNU Radio by doxygen 1.3.8