/Users/lyon/j4p/src/sound/filterDesign/Polynom.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: Polynom.java
7
8 import java.io.Serializable;
9
10 public class Polynom
11 implements Serializable {
12
13 public Polynom() {
14 p1 = null;
15 p2 = null;
16 c1 = null;
17 c2 = null;
18 }
19
20 public double[] getQuotient() {
21 if (p1 != null) {
22 return p1;
23 } else {
24 double ad[] = new double[1];
25 ad[0] = 0.0D;
26 return ad;
27 }
28 }
29
30 public double[] getRest() {
31 if (p2 != null) {
32 return p2;
33 } else {
34 double ad[] = new double[1];
35 ad[0] = 0.0D;
36 return ad;
37 }
38 }
39
40 public Complex[] getQuotientCmpl() {
41 if (c1 != null) {
42 return c1;
43 } else {
44 Complex acomplex[] = new Complex[1];
45 acomplex[0] = new Complex();
46 return acomplex;
47 }
48 }
49
50 public Complex[] getRestCmpl() {
51 if (c2 != null) {
52 return c2;
53 } else {
54 Complex acomplex[] = new Complex[1];
55 acomplex[0] = new Complex();
56 return acomplex;
57 }
58 }
59
60 public double[] getNumerator() {
61 return getQuotient();
62 }
63
64 public double[] getDenominator() {
65 return getRest();
66 }
67
68 public Complex[] getNumeratorCmpl() {
69 return getQuotientCmpl();
70 }
71
72 public Complex[] getDenominatorCmpl() {
73 return getRestCmpl();
74 }
75
76 public void divide(double ad[], double ad1[]) {
77 if (ad.length >= ad1.length) {
78 int i = (ad.length - ad1.length) + 1;
79 p1 = new double[i];
80 p2 = new double[ad.length];
81 System.arraycopy(ad, 0, p2, 0, ad.length);
82 for (int j = 0; j < i; j++) {
83 p1[j] = p2[j] / ad1[0];
84 for (int k = 0; k < ad1.length; k++)
85 p2[j + k] -= p1[j] * ad1[k];
86
87 }
88
89 return;
90 } else {
91 p1 = new double[1];
92 p1[0] = 0.0D;
93 p2 = new double[ad.length];
94 System.arraycopy(ad, 0, p2, 0, ad.length);
95 return;
96 }
97 }
98
99 public void divide(Complex acomplex[], Complex acomplex1[]) {
100 if (acomplex.length >= acomplex1.length) {
101 int i = (acomplex.length - acomplex1.length) + 1;
102 c1 = new Complex[i];
103 c2 = new Complex[acomplex.length];
104 System.arraycopy(acomplex, 0, c2, 0, acomplex.length);
105 for (int j = 0; j < i; j++) {
106 c1[j] = c2[j].div(acomplex1[0]);
107 for (int k = 0; k < acomplex1.length; k++)
108 c2[j + k] = c2[j + k].sub(c1[j].mul(acomplex1[k]));
109
110 }
111
112 return;
113 } else {
114 c1 = new Complex[1];
115 c1[0] = new Complex();
116 c2 = new Complex[acomplex.length];
117 System.arraycopy(acomplex, 0, c2, 0, acomplex.length);
118 return;
119 }
120 }
121
122 public double[] multiply(double ad[], double ad1[]) {
123 if (ad.length != 0 && ad1.length != 0) {
124 double ad2[] = new double[(ad.length + ad1.length) - 1];
125 for (int i = 0; i < ad2.length; i++)
126 ad2[i] = 0.0D;
127
128 if (ad.length > ad1.length) {
129 for (int j = 0; j < ad1.length; j++) {
130 for (int l = 0; l < ad.length; l++)
131 ad2[l + j] += ad1[j] * ad[l];
132
133 }
134
135 } else {
136 for (int k = 0; k < ad.length; k++) {
137 for (int i1 = 0; i1 < ad1.length; i1++)
138 ad2[i1 + k] += ad1[i1] * ad[k];
139
140 }
141
142 }
143 return ad2;
144 } else {
145 double ad3[] = new double[1];
146 ad3[0] = 0.0D;
147 return ad3;
148 }
149 }
150
151 public Complex[] multiply(Complex acomplex[], Complex acomplex1[]) {
152 if (acomplex.length != 0 && acomplex1.length != 0) {
153 Complex acomplex2[] = new Complex[(acomplex.length +
154 acomplex1.length) -
155 1];
156 for (int i = 0; i < acomplex2.length; i++)
157 acomplex2[i] = new Complex();
158
159 if (acomplex.length > acomplex1.length) {
160 for (int j = 0; j < acomplex1.length; j++) {
161 for (int l = 0; l < acomplex.length; l++)
162 acomplex2[l + j] =
163 acomplex2[l + j].add(
164 acomplex1[j].mul(acomplex[l]));
165
166 }
167
168 } else {
169 for (int k = 0; k < acomplex.length; k++) {
170 for (int i1 = 0; i1 < acomplex1.length; i1++)
171 acomplex2[i1 + k] =
172 acomplex2[i1 + k].add(
173 acomplex1[i1].mul(acomplex[k]));
174
175 }
176
177 }
178 return acomplex2;
179 } else {
180 Complex acomplex3[] = new Complex[1];
181 acomplex3[0] = new Complex();
182 return acomplex3;
183 }
184 }
185
186 public double[] add(double ad[], double ad1[]) {
187 if (ad.length != 0 && ad1.length != 0) {
188 double ad2[];
189 if (ad.length > ad1.length) {
190 ad2 = new double[ad.length];
191 System.arraycopy(ad, 0, ad2, 0, ad.length);
192 for (int i = 0; i < ad1.length; i++)
193 ad2[ad.length - i - 1] += ad1[ad1.length - i - 1];
194
195 } else {
196 ad2 = new double[ad1.length];
197 System.arraycopy(ad1, 0, ad2, 0, ad1.length);
198 for (int j = 0; j < ad.length; j++)
199 ad2[ad1.length - j - 1] += ad[ad.length - j - 1];
200
201 }
202 return ad2;
203 } else {
204 double ad3[] = new double[1];
205 ad3[0] = 0.0D;
206 return ad3;
207 }
208 }
209
210 public Complex[] add(Complex acomplex[], Complex acomplex1[]) {
211 if (acomplex.length != 0 && acomplex1.length != 0) {
212 Complex acomplex2[];
213 if (acomplex.length > acomplex1.length) {
214 acomplex2 = new Complex[acomplex.length];
215 System.arraycopy(acomplex,
216 0,
217 acomplex2,
218 0,
219 acomplex.length);
220 for (int i = 0; i < acomplex1.length; i++)
221 acomplex2[acomplex.length - i - 1] =
222 acomplex2[acomplex.length - i - 1].add(
223 acomplex1[acomplex1.length - i - 1]);
224
225 } else {
226 acomplex2 = new Complex[acomplex1.length];
227 System.arraycopy(acomplex1,
228 0,
229 acomplex2,
230 0,
231 acomplex1.length);
232 for (int j = 0; j < acomplex.length; j++)
233 acomplex2[acomplex.length - j - 1] =
234 acomplex2[acomplex1.length - j - 1].add(
235 acomplex1[acomplex.length - j - 1]);
236
237 }
238 return acomplex2;
239 } else {
240 Complex acomplex3[] = new Complex[1];
241 acomplex3[0] = new Complex();
242 return acomplex3;
243 }
244 }
245
246 public double[] sub(double ad[], double ad1[]) {
247 if (ad.length != 0 && ad1.length != 0) {
248 double ad2[];
249 if (ad.length > ad1.length) {
250 ad2 = new double[ad.length];
251 System.arraycopy(ad, 0, ad2, 0, ad.length);
252 for (int i = 0; i < ad1.length; i++)
253 ad2[ad.length - i - 1] -= ad1[ad1.length - i - 1];
254
255 } else {
256 ad2 = new double[ad1.length];
257 System.arraycopy(ad1, 0, ad2, 0, ad1.length);
258 for (int j = 0; j < ad.length; j++)
259 ad2[ad1.length - j - 1] -= ad[ad.length - j - 1];
260
261 for (int k = 0; k < ad1.length; k++)
262 ad2[k] = -ad2[k];
263
264 }
265 return ad2;
266 } else {
267 double ad3[] = new double[1];
268 ad3[0] = 0.0D;
269 return ad3;
270 }
271 }
272
273 public Complex[] sub(Complex acomplex[], Complex acomplex1[]) {
274 if (acomplex.length != 0 && acomplex1.length != 0) {
275 Complex acomplex2[];
276 if (acomplex.length > acomplex1.length) {
277 acomplex2 = new Complex[acomplex.length];
278 System.arraycopy(acomplex,
279 0,
280 acomplex2,
281 0,
282 acomplex.length);
283 for (int i = 0; i < acomplex1.length; i++)
284 acomplex2[acomplex.length - i - 1] =
285 acomplex2[acomplex.length - i - 1].sub(
286 acomplex1[acomplex1.length - i - 1]);
287
288 } else {
289 acomplex2 = new Complex[acomplex1.length];
290 System.arraycopy(acomplex1,
291 0,
292 acomplex2,
293 0,
294 acomplex1.length);
295 for (int j = 0; j < acomplex.length; j++)
296 acomplex2[acomplex1.length - j - 1] =
297 acomplex2[acomplex1.length - j - 1].sub(
298 acomplex[acomplex.length - j - 1]);
299
300 for (int k = 0; k < acomplex1.length; k++)
301 acomplex2[k] = acomplex2[k].neg();
302
303 }
304 return acomplex2;
305 } else {
306 Complex acomplex3[] = new Complex[1];
307 acomplex3[0] = new Complex();
308 return acomplex3;
309 }
310 }
311
312 public double[] derive(double ad[], int i) {
313 int j = ad.length;
314 i = Math.abs(i);
315 if (j <= i) {
316 double ad1[] = new double[1];
317 ad1[0] = 0.0D;
318 return ad1;
319 }
320 double ad2[] = new double[j - i];
321 for (int k = 0; k < ad2.length; k++)
322 ad2[k] = ad[k] * (double) factorial2(j - k - 1, i);
323
324 return ad2;
325 }
326
327 public Complex[] derive(Complex acomplex[], int i) {
328 int j = acomplex.length;
329 i = Math.abs(i);
330 if (j <= i) {
331 Complex acomplex1[] = new Complex[1];
332 acomplex1[0] = new Complex();
333 return acomplex1;
334 }
335 Complex acomplex2[] = new Complex[j - i];
336 for (int k = 0; k < acomplex2.length; k++)
337 acomplex2[k] = acomplex[k].scale(factorial2(j - k - 1, i));
338
339 return acomplex2;
340 }
341
342 public int factorial(int i) {
343 int j = 1;
344 if (i < 1)
345 return j;
346 for (int k = 2; k < i + 1; k++)
347 j *= k;
348
349 return j;
350 }
351
352 public int factorial2(int i, int j) {
353 int k = 1;
354 if (i < 1)
355 return k;
356 for (int l = i; l > i - j; l--)
357 k *= l;
358
359 return k;
360 }
361
362 public void derive(double ad[], double ad1[]) {
363 int i = ad1.length;
364 int j = ad.length;
365 int k = (j + i) - 2;
366 if (k <= 0) {
367 p1 = new double[1];
368 p1[0] = 0.0D;
369 return;
370 } else {
371 p2 = multiply(ad1, ad1);
372 p1 =
373 sub(multiply(derive(ad, 1), ad1),
374 multiply(ad, derive(ad1, 1)));
375 return;
376 }
377 }
378
379 public void derive(Complex acomplex[], Complex acomplex1[]) {
380 int i = acomplex1.length;
381 int j = acomplex.length;
382 int k = (j + i) - 2;
383 if (k <= 0) {
384 c1 = new Complex[1];
385 c1[0] = new Complex();
386 return;
387 } else {
388 c2 = multiply(acomplex1, acomplex1);
389 c1 =
390 sub(multiply(derive(acomplex, 1), acomplex1),
391 multiply(acomplex, derive(acomplex1, 1)));
392 return;
393 }
394 }
395
396 public double evaluate(double ad[], double d) {
397 double d1 = 0.0D;
398 if (ad.length < 1)
399 return 0.0D;
400 for (int i = 0; i < ad.length; i++)
401 d1 += ad[i] * Math.pow(d, ad.length - i - 1);
402
403 return d1;
404 }
405
406 public Complex evaluate(Complex acomplex[], Complex complex) {
407 Complex complex1 = new Complex();
408 if (acomplex.length < 1)
409 return new Complex();
410 for (int i = 0; i < acomplex.length; i++)
411 complex1 =
412 complex1.add(
413 acomplex[i].mul(
414 complex.pow(acomplex.length - i - 1)));
415
416 return complex1;
417 }
418
419 public double evaluate(double ad[], double ad1[], double d) {
420 return evaluate(ad, d) / evaluate(ad1, d);
421 }
422
423 public Complex evaluate(Complex acomplex[],
424 Complex acomplex1[],
425 Complex complex) {
426 return evaluate(acomplex, complex).div(
427 evaluate(acomplex1, complex));
428 }
429
430 public double evaluate(double d) {
431 return evaluate(p1, d) / evaluate(p2, d);
432 }
433
434 public Complex evaluate(Complex complex) {
435 return evaluate(c1, complex).div(evaluate(c2, complex));
436 }
437
438 public double[] integrate(double ad[], double d) {
439 double ad1[] = new double[ad.length + 1];
440 System.arraycopy(ad, 0, ad1, 0, ad.length);
441 for (int i = 0; i < ad.length; i++)
442 ad1[i] /= ad.length - i;
443
444 ad1[ad.length] = d;
445 return ad1;
446 }
447
448 public Complex[] integrate(Complex acomplex[], Complex complex) {
449 Complex acomplex1[] = new Complex[acomplex.length + 1];
450 System.arraycopy(acomplex, 0, acomplex1, 0, acomplex.length);
451 for (int i = 0; i < acomplex.length; i++)
452 acomplex1[i] = acomplex1[i].div(acomplex.length - i);
453
454 acomplex1[acomplex.length] = complex;
455 return acomplex1;
456 }
457
458 protected double p1[];
459 protected double p2[];
460 protected Complex c1[];
461 protected Complex c2[];
462 }
463