RTXI  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
dir1_iir.cpp
Go to the documentation of this file.
1 //
2 // File = dir1_iir.cpp
3 //
4 
5 #include "dir1_iir.h"
6 #include <fstream>
7 #include <stdlib.h>
8 #ifdef _DEBUG
9 extern std::ofstream DebugFile;
10 #endif
11 
12 DirectFormIir::DirectFormIir(int num_numer_coeff, int num_denom_coeff,
13  double* numer_coeff, double* denom_coeff,
14  long coeff_quan_factor, long input_quan_factor)
15 {
16  int n;
17  Num_Numer_Coeff = num_numer_coeff;
18  Num_Denom_Coeff = num_denom_coeff;
19  Input_Buffer = new long[num_numer_coeff];
20  Output_Buffer = new long[num_denom_coeff + 1];
21  Quan_Numer_Coeff = new long[num_numer_coeff];
22  Quan_Denom_Coeff = new long[num_denom_coeff + 1];
23  Input_Write_Indx = 0;
25  Input_Quan_Factor = input_quan_factor;
26  Coeff_Quan_Factor = coeff_quan_factor;
27  Output_Quan_Factor = double(coeff_quan_factor * input_quan_factor);
28 
29 #ifdef _DEBUG
30  DebugFile << "In DirectFormIir" << std::endl;
31 #endif
32 
33  for (n = 0; n < num_numer_coeff; n++) {
34  Quan_Numer_Coeff[n] = long((coeff_quan_factor * numer_coeff[n]) + 0.5);
35 #ifdef _DEBUG
36  DebugFile << numer_coeff[n] << " quantized to " << Quan_Numer_Coeff[n]
37  << std::endl;
38 #endif
39  Input_Buffer[n] = 0;
40  }
41  for (n = 1; n <= num_denom_coeff; n++) {
42  Quan_Denom_Coeff[n] = long((coeff_quan_factor * denom_coeff[n]) + 0.5);
43 #ifdef _DEBUG
44  DebugFile << denom_coeff[n] << " quantized to " << Quan_Denom_Coeff[n]
45  << std::endl;
46 #endif
47  Output_Buffer[n] = 0;
48  }
49  return;
50 }
51 
52 long
54 {
55  return (input_val);
56 }
57 double
59 {
60  double output_val;
61  long term, sum;
62  int input_read_indx, output_read_indx, tap_indx;
63 
64  Input_Buffer[Input_Write_Indx] = long(Input_Quan_Factor * input_val);
65  input_read_indx = Input_Write_Indx;
68  Input_Write_Indx = 0;
69 
70  sum = 0;
71 
72  for (tap_indx = 0; tap_indx < Num_Numer_Coeff; tap_indx++) {
73  term = Quan_Numer_Coeff[tap_indx] * Input_Buffer[input_read_indx];
74  sum += term;
75  input_read_indx--;
76  if (input_read_indx < 0)
77  input_read_indx = Num_Numer_Coeff - 1;
78  }
79 
80  output_read_indx = Output_Write_Indx;
81  for (tap_indx = 1; tap_indx <= Num_Denom_Coeff; tap_indx++) {
82  term = Quan_Denom_Coeff[tap_indx] * Output_Buffer[output_read_indx];
83  sum += term;
84  output_read_indx--;
85  if (output_read_indx < 1)
86  output_read_indx = Num_Denom_Coeff;
87  }
88 
93 
94  output_val = double(sum) / Output_Quan_Factor;
95  return (output_val);
96 }
97 
98 int
100 {
101  return (Num_Numer_Coeff);
102 }
103 
104 int
106 {
107  return (Num_Numer_Coeff);
108 }
109 
110 int
112 {
113  return (Num_Denom_Coeff);
114 }
int GetNumDenomCoeff(void)
Definition: dir1_iir.cpp:111
int GetNumTaps(void)
Definition: dir1_iir.cpp:105
DirectFormIir(int num_numer_coeff, int num_denom_coeff, double *numer_coeff, double *denom_coeff, long coeff_quan_factor, long input_quan_factor)
Definition: dir1_iir.cpp:12
double Output_Quan_Factor
Definition: dir1_iir.h:32
long Input_Quan_Factor
Definition: dir1_iir.h:30
int Num_Numer_Coeff
Definition: dir1_iir.h:22
long Coeff_Quan_Factor
Definition: dir1_iir.h:31
int Output_Write_Indx
Definition: dir1_iir.h:28
int Input_Write_Indx
Definition: dir1_iir.h:29
long * Output_Buffer
Definition: dir1_iir.h:25
double ProcessSample(double input_val)
Definition: dir1_iir.cpp:58
long * Quan_Numer_Coeff
Definition: dir1_iir.h:26
long * Quan_Denom_Coeff
Definition: dir1_iir.h:27
int Num_Denom_Coeff
Definition: dir1_iir.h:23
std::ofstream DebugFile
long * Input_Buffer
Definition: dir1_iir.h:24
int GetNumNumerCoeff(void)
Definition: dir1_iir.cpp:99