RTXI  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
chebfunc.cpp
Go to the documentation of this file.
1 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 //
3 // File = chebfunc.cpp
4 //
5 // Chebyshev Filter Function
6 //
7 
8 #include "chebfunc.h"
9 #include "complex.h"
10 #include "misdefs.h"
11 #include <math.h>
12 
13 //======================================================
14 // constructor
15 
16 ChebyshevTransFunc::ChebyshevTransFunc(int order, double ripple,
17  int ripple_bw_norm)
18  : FilterTransFunc(order)
19 {
20  double x;
21  int k;
22  double epsilon, gamma;
23  double big_r, big_a;
24  double sigma_mult, omega_mult;
25  complex work;
26 
27  Prototype_Pole_Locs = new complex[order + 1];
28  Num_Prototype_Poles = order;
31 
32  epsilon = sqrt(pow(10.0, (double)(ripple / 10.0)) - 1.0);
33  gamma =
34  pow((1 + sqrt(1.0 + epsilon * epsilon)) / epsilon, 1.0 / (double)order);
35  if (ripple_bw_norm) {
36  big_r = 1.0;
37  } else {
38  big_a = log((1.0 + sqrt(1.0 - epsilon * epsilon)) / epsilon) / order;
39  big_r = (exp(big_a) + exp(-big_a)) / 2.0;
40  std::cout << "big_r = " << big_r << std::endl;
41  }
42 
43  sigma_mult = ((1.0 / gamma) - gamma) / (2.0 * big_r);
44 
45  omega_mult = ((1.0 / gamma) + gamma) / (2.0 * big_r);
46 
47  for (k = 1; k <= order; k++) {
48  x = PI * ((2 * k) - 1) / (2 * order);
49 
50  Prototype_Pole_Locs[k] = complex(sigma_mult * sin(x), omega_mult * cos(x));
51  }
52  //------------------------------------------------
53  // compute gain factor Ho
54 
55  work = complex(1.0, 0.0);
56  for (k = 1; k <= order; k++) {
57  work *= (-Prototype_Pole_Locs[k]);
58  }
59 
60  H_Sub_Zero = real(work);
61 
62  if (order % 2 == 0) // if order is even
63  {
64  H_Sub_Zero /= sqrt(1.0 + epsilon * epsilon);
65  }
66 
67  return;
68 };
#define PI
Definition: misdefs.h:9
complex sqrt(const complex _z)
Definition: complex.h:148
double H_Sub_Zero
Definition: filtfunc.h:66
int Num_Prototype_Zeros
Definition: filtfunc.h:58
complex * Prototype_Pole_Locs
Definition: filtfunc.h:67
double real(const complex &_z)
Definition: complex.h:98
int Num_Prototype_Poles
Definition: filtfunc.h:57
ChebyshevTransFunc(int order, double ripple, int ripple_bw_norm)
Definition: chebfunc.cpp:16
complex * Prototype_Zero_Locs
Definition: filtfunc.h:68