RTXI  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
impinvar.cpp
Go to the documentation of this file.
1 //
2 // file = impinvar.cpp
3 //
4 
5 #include "impinvar.h"
6 
7 void
8 ImpulseInvar(complex* pole, int num_poles, complex* zero, int num_zeros,
9  double h_sub_zero, double big_t, complex* a, complex* b)
10 {
11  int k, n, j, maxCoef;
12  complex *delta, *big_a;
13  complex beta, denom, numer, work2;
14 
15  delta = new complex[num_poles + 1];
16  big_a = new complex[num_poles + 1];
17 
18  for (j = 0; j < num_poles + 1; j++) {
19  delta[j] = complex(0.0, 0.0);
20  a[j] = complex(0.0, 0.0);
21  b[j] = complex(0.0, 0.0);
22  }
23  //---------------------------------------------------
24  // compute partial fraction expansion coefficients
25 
26  for (k = 1; k <= num_poles; k++) {
27  numer = complex(h_sub_zero, 0.0);
28  for (n = 1; n <= num_zeros; n++) {
29  numer = numer * (pole[n] - zero[n]);
30  }
31  denom = complex(1.0, 0.0);
32  for (n = 1; n <= num_poles; n++) {
33  if (n == k)
34  continue;
35  denom = denom * (pole[k] - pole[n]);
36  }
37  big_a[k] = numer / denom;
38  }
39 
40  //-------------------------------------
41  // compute numerator coefficients
42 
43  for (k = 1; k <= num_poles; k++) {
44  delta[0] = complex(1.0, 0.0);
45  for (n = 1; n <= num_poles; n++) {
46  delta[n] = complex(0.0, 0.0);
47  }
48  maxCoef = 0;
49  for (n = 1; n <= num_poles; n++) {
50  if (n == k)
51  continue;
52  maxCoef++;
53  beta = -cexp(big_t * pole[n]);
54  for (j = maxCoef; j >= 1; j--) {
55  delta[j] += (beta * delta[j - 1]);
56  }
57  }
58  for (j = 0; j < num_poles; j++) {
59  b[j] += (big_a[k] * delta[j]);
60  }
61  }
62 
63  //-------------------------------------
64  // compute denominator coefficients
65 
66  a[0] = complex(1.0, 0.0);
67  for (n = 1; n <= num_poles; n++) {
68  beta = -cexp(big_t * pole[n]);
69 
70  for (j = n; j >= 1; j--) {
71  a[j] += (beta * a[j - 1]);
72  }
73  }
74  for (j = 1; j <= num_poles; j++) {
75  a[j] = -a[j];
76  }
77 
78  delete[] delta;
79  delete[] big_a;
80 
81  return;
82 }
complex cexp(const complex _z)
Definition: complex.h:139
void ImpulseInvar(complex *pole, int num_poles, complex *zero, int num_zeros, double h_sub_zero, double big_t, complex *a, complex *b)
Definition: impinvar.cpp:8