/Users/lyon/j4p/src/sound/filterDesign/Residue.java
|
1 package sound.filterDesign;
2
3 // Decompiled by Jad v1.5.8c. Copyright 2001 Pavel Kouznetsov.
4 // Jad home page: http://www.geocities.com/kpdus/jad.html
5 // Decompiler options: packimports(3)
6 // Source File Name: Residue.java
7
8 import java.io.Serializable;
9 import java.util.Vector;
10
11 public class Residue
12 implements Serializable {
13
14 public Residue() {
15 polynom = new Polynom();
16 ready = false;
17 }
18
19 public double[] getQuotient() {
20 return quotient;
21 }
22
23 public boolean getReadiness() {
24 return ready;
25 }
26
27 public double getDelta() {
28 return delta;
29 }
30
31 public Complex[] rootsToPoly(int i) {
32 Vector vector = new Vector();
33 for (int j = 0; j < roots.length; j++)
34 if (j != i) {
35 Complex complex = roots[j];
36 for (int k = 0; k < repeat[j]; k++)
37 vector.addElement(new Complex(complex, 1));
38
39 }
40
41 Complex acomplex[];
42 if (vector.size() == 0) {
43 acomplex = new Complex[1];
44 acomplex[0] = new Complex(1.0D, 0.0D);
45 } else {
46 acomplex = new Complex[vector.size() + 1];
47 for (int l = 0; l < acomplex.length; l++)
48 acomplex[l] = new Complex();
49
50 acomplex[0] = new Complex(1.0D);
51 acomplex[1] = new Complex((Complex) vector.elementAt(0));
52 for (int i1 = 1; i1 < vector.size(); i1++) {
53 Complex complex1 = new Complex(
54 (Complex) vector.elementAt(i1));
55 for (int j1 = i1 + 1; j1 > 0; j1--)
56 acomplex[j1] =
57 acomplex[j1 - 1].mul(complex1).add(
58 acomplex[j1]);
59
60 }
61
62 }
63 return acomplex;
64 }
65
66 public void purgeRoot(Vector vector) {
67 Vector vector1 = new Vector();
68 repeat = new int[vector.size()];
69 for (int i = 0; i < vector.size(); i++) {
70 Complex complex = (Complex) vector.elementAt(i);
71 vector1.addElement(new Complex(complex.real, complex.imag));
72 repeat[i] = 1;
73 for (int j = i + 1; j < vector.size(); j++)
74 if (complex.equals((Complex) vector.elementAt(j))) {
75 vector.removeElementAt(j);
76 j--;
77 repeat[i]++;
78 }
79
80 }
81
82 roots = new Complex[vector1.size()];
83 for (int k = 0; k < vector1.size(); k++)
84 roots[k] = (Complex) vector1.elementAt(k);
85
86 vector1 = null;
87 Object obj = null;
88 }
89
90 public void partial(double ad[], double ad1[], Vector vector) {
91 purgeRoot(vector);
92 polynom.divide(ad, ad1);
93 double ad2[] = polynom.getQuotient();
94 quotient = new double[ad2.length];
95 System.arraycopy(ad2, 0, quotient, 0, ad2.length);
96 ad2 = polynom.getRest();
97 rest = new double[ad2.length];
98 System.arraycopy(ad2, 0, rest, 0, ad2.length);
99 coeffs = new Complex[roots.length][];
100 for (int i = 0; i < roots.length; i++) {
101 Complex acomplex1[] = new Complex[rest.length];
102 for (int j = 0; j < rest.length; j++)
103 acomplex1[j] = new Complex(rest[j], 0.0D);
104
105 Complex acomplex[] = rootsToPoly(i);
106 coeffs[i] = new Complex[repeat[i]];
107 for (int k = 0; k < coeffs[i].length; k++) {
108 if (k > 0) {
109 polynom.derive(acomplex1, acomplex);
110 acomplex1 = polynom.getNumeratorCmpl();
111 acomplex = polynom.getDenominatorCmpl();
112 }
113 coeffs[i][repeat[i] - k - 1] =
114 polynom.evaluate(acomplex1, acomplex, roots[i])
115 .div(polynom.factorial(k));
116 coeffs[i][repeat[i] - k - 1].cleanMe();
117 }
118
119 }
120
121 if (quotient.length > 0)
122 delta = quotient[quotient.length - 1];
123 else
124 delta = 0.0D;
125 ready = true;
126 }
127
128 public static void main(String args[]) {
129 Residue residue = new Residue();
130 double ad[] = {
131 1.0D, 2D, -3D
132 };
133 double ad1[] = {
134 1.0D, 2D
135 };
136 Vector vector = new Vector();
137 vector.addElement(new Complex(-2D, 0.0D));
138 residue.partial(ad, ad1, vector);
139 for (int i = 0; i < residue.coeffs.length; i++) {
140 for (int j = 0; j < residue.coeffs[i].length; j++)
141 System.out.println(
142 "\n Root = " +
143 roots[i] +
144 " " +
145 residue.coeffs[i][j]);
146
147 }
148
149 System.out.println(String.valueOf(residue.getDelta()));
150 }
151
152 double quotient[];
153 double rest[];
154 public static Complex roots[];
155 public Complex coeffs[][];
156 Polynom polynom;
157 private int repeat[];
158 boolean ready;
159 double delta;
160 }
161