26 #define M_1_PI 0.3183098861837906715377675267450287
29 #define M_LN2 0.6931471805599453094172321214581766
32 #define M_PI 3.1415926535897932384626433832795029
35 #undef _QF_CAUER_DEBUG
59 if (amin > 3 || amax < 3)
66 fabs (fs - (fc * fc) / fs) <
bw)
81 return ((x > y) ? x : y);
91 while (fabs (a -
b) >
K_ERR) {
96 return M_PI / (2 * a);
104 return sin (u) - 0.25 * m *
cos (u) * (u - 0.5 *
sin (2 * u));
111 return (1 + smu) * sn1 / (1 + smu * sn1 * sn1);
137 alamb = sqrtx * (sqrty + sqrtz) + sqrty * sqrtz;
138 xt = 0.25 * (xt + alamb);
139 yt = 0.25 * (yt + alamb);
140 zt = 0.25 * (zt + alamb);
141 ave = THIRD * (xt + yt + zt);
142 delx = (ave - xt) / ave;
143 dely = (ave - yt) / ave;
144 delz = (ave - zt) / ave;
146 while (FMAX (FMAX (fabs (delx), fabs (dely)), fabs (delz)) >
K_ERR1);
148 e2 = delx * dely - delz * delz;
149 e3 = delx * dely * delz;
150 return (1 + (C1 * e2 - C2 - C3 * e3) * e2 + C4 * e3) /
sqrt (ave);
168 f2 -= 2 / (w * (w + 1));
197 for (i = 1; i < 14; i++) {
200 en[
i] = (emc =
sqrt (emc));
202 if (fabs (a - emc) <=
SN_ACC * a)
215 for (ii = l; ii > 0; ii--) {
219 dn = (en[ii] + a) / (b + a);
222 a = 1 /
sqrt (c * c + 1);
223 sn = (sn >= 0 ? a : -a);
263 #ifdef _QF_CAUER_DEBUG
264 std::cout <<
"amin + aemin = " << sAmin <<
" dB\n";
265 std::cout <<
"amax + aemax = " << sAmax <<
" dB\n";
266 std::cout <<
"D(a) = " << sdiff <<
" dB\n";
273 KA =
Kp (kA) /
K (kA);
275 KA =
K (
sqrt (1 - kA * kA)) /
K (kA);
287 th =
bw / fabs (fs - (
fc *
fc) / fs);
290 th = fabs (fs *
bw / (fs * fs - fc * fc));
291 bw = fabs (fs - (fc * fc) / fs);
297 ord = (unsigned)
ceil (Kth * KA);
301 #ifdef _QF_CAUER_DEBUG
302 std::cout <<
"K'/K = " << Kth <<
", K1/K'1 = " << KA <<
'\n';
303 std::cout <<
"Order = " <<
ord <<
'\n';
313 int m = (
ord - 1) / 2;
318 #ifdef _QF_CAUER_DEBUG
319 std::cerr <<
"Computing filter of order " <<
ord <<
" with ";
320 std::cerr <<
"rho = " << rho <<
" and theta = " << ASIND (th) <<
"°\n";
321 std::cerr <<
"k = " << k <<
'\n';
324 for (
unsigned i = 1;
i <
ord;
i++) {
326 a[
i] = Ws *
sn (j * k, th);
327 #ifdef _QF_CAUER_DEBUG
328 std::cerr <<
"a(" <<
i <<
") = " << a[
i] <<
'\n';
332 #ifdef _QF_CAUER_DEBUG
333 std::cerr <<
"Norm. puls. (Ws) = " << Ws <<
'\n';
337 for (u = 1; u < m + 2; u++)
338 delta *= a[2 * u - 1] * a[2 * u - 1];
342 #ifdef _QF_CAUER_DEBUG
343 std::cerr <<
"D = " << delta <<
'\n';
344 std::cerr <<
"c = " << c <<
'\n';
351 for (u = 1; u < m + 1; u++) {
352 qf_poly MF (1, 0, a[2 * u] * a[2 * u], 2);
353 qf_poly MP (a[2 * u] * a[2 * u], 0, 1, 2);
383 for (
unsigned k = 0, l = 2; k < (
ncomp - 1); k += 3) {
384 #ifdef _QF_CAUER_DEBUG
385 std::cerr <<
"Pole (" << l <<
") = " << (1 / (a[l] * Ws)) <<
"\n";
391 if (l < (
ord + 1) / 2)
406 for (i = 0, node = 1;;) {
432 for (i = 1, node = 2; i <
ncomp;) {
459 for (
unsigned i = 0, j = 0, node = 1;;) {
461 Comp2[j].
node1 = node;
466 Comp2[j].
node1 = node;
475 #ifdef _QF_CAUER_DEBUG
476 std::cout <<
"O(inf) = " <<
sqrt (1 / iw2) <<
'\n';
480 #ifdef _QF_CAUER_DEBUG
481 std::cout <<
"b = " << b <<
'\n';
485 Comp2[j + 1].
node1 = node;
486 Comp2[j + 1].
node2 = node + 1;
487 Comp2[j + 1].
val = (b - 1) / (q * c * 2 * b);
490 Comp2[j + 3].
node1 = node + 1;
491 Comp2[j + 3].
node2 = node + 2;
492 Comp2[j + 3].
val = (b + 1) / (q * c * 2 * b);
495 Comp2[j].
node1 = node;
496 Comp2[j].
node2 = node + 1;
497 Comp2[j].
val = 1 / Comp2[j + 3].
val;
500 Comp2[j + 2].
node1 = node + 1;
501 Comp2[j + 2].
node2 = node + 2;
502 Comp2[j + 2].
val = 1 / Comp2[j + 1].
val;
503 Comp2[j].
val *= cnrm;
504 Comp2[j + 2].
val *= cnrm;
505 Comp2[j + 1].
val *= lnrm;
506 Comp2[j + 3].
val *= lnrm;
521 for (
unsigned i = 0, j = 0, node = 1;;) {
523 Comp2[j].
node1 = node;
524 Comp2[j].
node2 = node + 1;
528 Comp2[j].
node1 = node + 1;
537 #ifdef _QF_CAUER_DEBUG
538 std::cout <<
"O(inf) = " <<
sqrt (w2) <<
"; q = " << q <<
'\n';
542 #ifdef _QF_CAUER_DEBUG
543 std::cout <<
"b = " << b <<
'\n';
546 Comp2[j + 1].
node1 = node;
547 Comp2[j + 1].
node2 = node + 2;
548 Comp2[j + 1].
val = l * (b - 1) / (2 * b * q);
551 Comp2[j + 3].
node1 = node + 2;
552 Comp2[j + 3].
node2 = node + 3;
553 Comp2[j + 3].
val = l * (b + 1) / (2 * b * q);
556 Comp2[j].
node1 = node;
557 Comp2[j].
node2 = node + 2;
558 Comp2[j].
val = 1 / Comp2[j + 3].
val;
561 Comp2[j + 2].
node1 = node + 2;
562 Comp2[j + 2].
node2 = node + 3;
563 Comp2[j + 2].
val = 1 / Comp2[j + 1].
val;
564 Comp2[j].
val *= cnrm;
565 Comp2[j + 2].
val *= cnrm;
566 Comp2[j + 1].
val *= lnrm;
567 Comp2[j + 3].
val *= lnrm;
584 std::cout <<
"qf_cauer::dump ()\n";
588 std::cout <<
"Lowpass ";
591 std::cout <<
"Highpass ";
594 std::cout <<
"Bandpass ";
597 std::cout <<
"Bandstop ";
600 std::cout <<
"of order " <<
ord <<
", theta = "
601 << ASIND (th) <<
"°, rho = " << rho <<
'\n';
610 std::cout <<
"Order : ";
614 std::cout <<
"Reflexion (%) : ";
617 std::cout <<
"Angle (°) : ";
619 t =
M_PI * t / 180.0;
631 std::cout <<
"Enter cutoff (Hz) [0 to end]: ";
635 std::cout <<
"Enter ripple in passband (dB): ";
637 std::cout <<
"Enter stopband frequency (Hz): ";
639 std::cout <<
"Enter minimal attenuation in stopband (dB): ";
641 std::cout <<
"Enter bandwith (0 for high- or low-pass) (Hz): ";
643 std::cout <<
"Enter reference impedance (Ohm): ";