RTXI  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
mr_lpf.cpp
Go to the documentation of this file.
1 //
2 // File = mr_lpf.cpp
3 //
4 #include "mr_lpf.h"
5 #include "dirform1.h"
6 #include "fir_dsgn.h"
7 #include <fstream>
8 #include <stdlib.h>
9 
10 #ifdef _DEBUG
11 extern std::ofstream DebugFile;
12 #endif
13 
15  FirFilterDesign* int_proto_filt,
16  int decim_rate, logical quan_enab,
17  long input_quan_fact, long coef_quan_fact)
18 {
19  int poly_filt_len;
20  int proto_len;
21  int rho;
22 
23  Dec_Rate = decim_rate;
24  Int_Rate = decim_rate;
25  Quan_Enab = quan_enab;
26  Dec_Out = 0.0;
27  Int_In = 0.0;
28  // Dec_Rho = Dec_Rate - 1;
29  Dec_Rho = 0;
30  Int_Rho = 0;
31 
32  proto_len = dec_proto_filt->GetNumTaps();
33  Num_Taps = 2 * proto_len;
34 
35  //--------------------------------------------------
36  // Separate the prototype filter coefficients
37  // into M sets of N/M coefficients each for
38  // the M polyphase filters in the decimator
39  //
40  poly_filt_len = proto_len / decim_rate;
41  double* coef_subset = new double[poly_filt_len];
42  Dec_Filt = (FilterImplementation**)new long[Dec_Rate];
43 
44  for (rho = 0; rho < Dec_Rate; rho++) {
45  dec_proto_filt->ExtractPolyphaseSet(coef_subset, Dec_Rate, rho);
46  Dec_Filt[rho] = new DirectFormFir(poly_filt_len, coef_subset, quan_enab,
47  coef_quan_fact, input_quan_fact);
48  }
49  //--------------------------------------------------
50  // Separate the prototype filter coefficients
51  // into M sets of N/M coefficients each for
52  // the M polyphase filters in the interpolator
53  //
54  Int_Filt = (FilterImplementation**)new long[Int_Rate];
55 
56  for (rho = 0; rho < Int_Rate; rho++) {
57  int_proto_filt->ExtractPolyphaseSet(coef_subset, Int_Rate, rho);
58  Int_Filt[rho] = new DirectFormFir(poly_filt_len, coef_subset, quan_enab,
59  coef_quan_fact, input_quan_fact);
60  }
61  delete[] coef_subset;
62  return;
63 }
64 //==========================================================
66 {
67  int rho;
68  for (rho = 0; rho < Dec_Rate; rho++) {
69  delete Dec_Filt[rho];
70  }
71  for (rho = 0; rho < Int_Rate; rho++) {
72  delete Int_Filt[rho];
73  }
74 }
75 //----------------------------------------------------------
76 double
78 {
79  double output_val;
80  //-----------------------------------------------------
81  // Decimator section
82  //
83  Dec_Out += (Dec_Filt[Dec_Rho])->ProcessSample(input_val);
84  Dec_Rho--;
85  if (Dec_Rho < 0) {
86  Dec_Rho = Dec_Rate - 1;
87  Int_In = Dec_Out;
88  Dec_Out = 0.0;
89  }
90  //-----------------------------------------------
91  // Interpolator section
92  //
93  output_val = Int_Rate * (Int_Filt[Int_Rho])->ProcessSample(Int_In);
94  Int_Rho++;
95  if (Int_Rho >= Int_Rate) {
96  Int_Rho = 0;
97  }
98  return (output_val);
99 }
100 //----------------------------------------------------------
101 long
103 {
104  long output_val;
105  //-----------------------------------------------------
106  // Decimator section
107  //
108  Quan_Dec_Out += (Dec_Filt[Dec_Rho])->ProcessSample(input_val);
109  Dec_Rho--;
110  if (Dec_Rho < 0) {
111  Dec_Rho = Dec_Rate - 1;
113  Quan_Dec_Out = 0;
114  }
115  //-----------------------------------------------
116  // Interpolator section
117  //
118  output_val = Int_Rate * (Int_Filt[Int_Rho])->ProcessSample(Quan_Int_In);
119  Int_Rho++;
120  if (Int_Rho >= Int_Rate) {
121  Int_Rho = 0;
122  }
123  return (output_val);
124 }
125 //--------------------------------------------------
126 //
127 int
129 {
130  return (Num_Taps);
131 }
double ProcessSample(double input_val)
Definition: mr_lpf.cpp:77
long Quan_Int_In
Definition: mr_lpf.h:36
int logical
Definition: typedefs.h:4
MultirateLowpass(FirFilterDesign *dec_proto_filt, FirFilterDesign *int_proto_filt, int decim_rate, logical quan_enab, long input_quant_factor, long coeff_quant_factor)
Definition: mr_lpf.cpp:14
logical Quan_Enab
Definition: mr_lpf.h:37
FilterImplementation ** Int_Filt
Definition: mr_lpf.h:31
FilterImplementation ** Dec_Filt
Definition: mr_lpf.h:27
int GetNumTaps(void)
Definition: mr_lpf.cpp:128
long Quan_Dec_Out
Definition: mr_lpf.h:35
double Int_In
Definition: mr_lpf.h:34
std::ofstream DebugFile
int GetNumTaps(void)
Definition: fir_dsgn.cpp:124
void ExtractPolyphaseSet(double *coeff, int decim_rate, int rho)
Definition: fir_dsgn.cpp:147
double Dec_Out
Definition: mr_lpf.h:33