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

VrIIRfilter.h

Go to the documentation of this file.
00001 /* -*- Mode: c++ -*- */ 00002 /* 00003 * Copyright 2001 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 /* -*- Mode: c++ -*- 00023 * 00024 * Copyright 1997 Massachusetts Institute of Technology 00025 * 00026 * Permission to use, copy, modify, distribute, and sell this software and its 00027 * documentation for any purpose is hereby granted without fee, provided that 00028 * the above copyright notice appear in all copies and that both that 00029 * copyright notice and this permission notice appear in supporting 00030 * documentation, and that the name of M.I.T. not be used in advertising or 00031 * publicity pertaining to distribution of the software without specific, 00032 * written prior permission. M.I.T. makes no representations about the 00033 * suitability of this software for any purpose. It is provided "as is" 00034 * without express or implied warranty. 00035 * 00036 */ 00037 00038 00039 #ifndef _VrIIRFILTER_H_ 00040 #define _VrIIRFILTER_H_ 00041 00042 #include <VrSigProc.h> 00043 00044 template<class iType,class oType> 00045 class VrIIRfilter : public VrSigProc { 00046 protected: 00047 int order,offset; 00048 double *Btaps, *Ataps; 00049 iType *input_hist; 00050 oType *output_hist; 00051 float gain; 00052 00053 public: 00054 virtual int work(VrSampleRange output, void *ao[], 00055 VrSampleRange inputs[], void *ai[]); 00056 virtual void initialize(); 00057 VrIIRfilter(int,double *, double *, float); 00058 ~VrIIRfilter(); 00059 }; 00060 00061 template<class iType,class oType> int 00062 VrIIRfilter<iType,oType>::work(VrSampleRange output, void *ao[], 00063 VrSampleRange inputs[], void *ai[]) 00064 { 00065 oType result; 00066 for (unsigned int sample=0;sample<output.size;sample++) 00067 { 00068 input_hist[(sample + offset)% order] = ((iType **)ai)[0][sample]; 00069 result = Btaps[0] * ((iType **)ai)[0][sample]; 00070 00071 for (int tap=1; tap < order; tap++) 00072 result += (Btaps[tap] * input_hist[(sample + offset + order - tap)%order]) 00073 + (Ataps[tap] * output_hist[(sample + offset + order - tap)%order]); 00074 ((oType **)ao)[0][sample] = gain * result; 00075 output_hist[(sample + offset) % order] = result; 00076 } 00077 offset = (offset + output.size) % order; 00078 return output.size; 00079 } 00080 00081 00082 template<class iType,class oType> 00083 VrIIRfilter<iType,oType>::VrIIRfilter(int ord, double *intaps, double *outtaps, float gain) 00084 :VrSigProc(1, sizeof(iType), sizeof(oType)), order(ord),offset(0),gain(gain) 00085 { 00086 Ataps = new double[order]; 00087 Btaps = new double[order]; 00088 input_hist = new iType[order]; 00089 output_hist = new oType[order]; 00090 00091 for(int i = 0; i<order; i++) 00092 { 00093 input_hist[i] = 0; output_hist[i] = 0; 00094 Btaps[i] = intaps[i]; 00095 Ataps[i] = outtaps[i]; 00096 } 00097 } 00098 00099 template<class iType,class oType> 00100 void VrIIRfilter<iType,oType>::initialize() 00101 { 00102 //setOutputHistory(order); 00103 //setHistory(order); 00104 } 00105 00106 template<class iType,class oType> 00107 VrIIRfilter<iType,oType>::~VrIIRfilter() 00108 { 00109 delete Ataps; 00110 delete Btaps; 00111 delete input_hist; 00112 delete output_hist; 00113 } 00114 00115 #endif 00116 00117 00118 00119 00120 00121 00122 00123

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