-
Notifications
You must be signed in to change notification settings - Fork 0
/
bw.c
49 lines (44 loc) · 1.23 KB
/
bw.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
* RF low-pass filter - Butterworth
*/
#include <math.h>
#include <complex.h>
#include "model.h"
struct Model { void *_; };
model *model_init (int n) { (void)n;
return NULL;
}
minima *get_known_minima (int n) { (void)n;
real PI = acosl(-1.0L);
minima *o = malloc(sizeof (minima)); CHECK(o);
o->n_minima = 1;
o->min = get_point(n); CHECK(o->min);
for (int r = 0; r < n; r++) {
o->min->x[r] = 2.0L * sinl((2.0L * (r + 1.0L) - 1.0L) * PI / (2 * (2 * n - 1)));
}
o->min->f = 0.0L;
return o;
}
static real tx (int n, real *x, real w) {
long double complex g = 1.0L + I * w * x[0];
for (int r = 1; r < n; r++) {
g = 1.0L / g + I * w * x[r];
}
for (int r = n - 2; r >= 0; r--) {
g = 1.0L / g + I * w * x[r];
}
return 1.0L - SQR(cabsl((g - 1.0L) / (g + 1.0L)));
}
void cost (int n, point *p, const model *m) { (void)m;
for (int i = 0; i < n; i++) {
if (p->x[i] <= 0.0L) { // positive component values!
p->f = INFINITY;
return;
}
}
p->f = 0.0L;
for (int i = 0; i <= 100; i++) {
real w = powl(10.0L, 0.02L * i - 1.0L);
p->f += SQR(1.0L / (1.0L + powl(w, 2 * (2 * n - 1))) - tx(n, p->x, w));
}
}