static double kaiser(params *p, double x) { double a = p->params[0]; double epsilon = 1e-12; double i0a = 1 / bessel_i0(epsilon, a); return bessel_i0(epsilon, a * sqrt(1 - x * x)) * i0a; }
static double kaiser(kernel *k, double x) { double a = k->params[0]; double b = k->params[1]; double epsilon = 1e-12; double i0a = 1 / bessel_i0(epsilon, b); return bessel_i0(epsilon, a * sqrt(1 - x * x)) * i0a; }
/* * Returns the value of the Kaiser window at point n with shape alpha and * length M+1. */ double kaiser(double alpha, double M, double n) { if (n < 0 || n > M) return 0; return bessel_i0(alpha * sqrt(1.0 - pow(2.0 * n / M - 1.0, 2))) / bessel_i0(alpha); }
static double kaiser(double beta, int M, int n) { if (M == 1) return 1.; if (fabs((double)n / (double)M - 0.5) >= 0.5) return 0.; return bessel_i0(beta * sqrt(1. - pow(2. * (double)n / (double)M - 1., 2.))) / bessel_i0(beta); }
static void lfr_filter_calculate_s16(short *data, int nsamp, int nfilt, double offset, double cutoff, double beta) { double x, x0, t, y, z, xscale, yscale, err; int i, j; double *a, sum, fac, scale; a = malloc(nsamp * sizeof(double)); if (!a) abort(); /* FIXME: report an error */ if (nsamp <= 8) scale = 31500; else scale = 32767; yscale = 2.0 * cutoff / bessel_i0(beta); xscale = (8.0 * atan(1.0)) * cutoff; for (i = 0; i < nfilt; ++i) { x0 = (nsamp - 1) / 2 + offset * i; sum = 0.0; for (j = 0; j < nsamp; ++j) { x = j - x0; t = x * (2.0 / (nsamp - 2)); if (t <= -1.0 || t >= 1.0) { y = 0.0; } else { y = yscale * bessel_i0(beta * sqrt(1.0 - t * t)) * sinc(xscale * x); } a[j] = y; sum += y; } fac = scale / sum; err = 0.0; for (j = 0; j < nsamp; ++j) { y = a[j] * fac + err; z = floor(y + 0.5); err = z - y; data[i * nsamp + j] = (short) z; } } }
/* * modified bessel function */ double bessel_i0(double x) { if (x < 0.) return bessel_i0(-x); if (x < 8.) return exp(x) * chebeval(x / 4. - 1., ARRAY_SIZE(coeff_0to8), coeff_0to8); return exp(x) * chebeval(16. / x - 1., ARRAY_SIZE(coeff_8toinf), coeff_8toinf) / sqrt(x); }
static void lfr_filter_calculate_f32(float *data, int nsamp, int nfilt, double offset, double cutoff, double beta) { double x, x0, t, y, xscale, yscale; int i, j; yscale = 2.0 * cutoff / bessel_i0(beta); xscale = (8.0 * atan(1.0)) * cutoff; for (i = 0; i < nfilt; ++i) { x0 = (nsamp - 1) / 2 + offset * i; for (j = 0; j < nsamp; ++j) { x = j - x0; t = x * (2.0 / (nsamp - 2)); if (t <= -1.0 || t >= 1.0) { y = 0.0; } else { y = yscale * bessel_i0(beta * sqrt(1.0 - t * t)) * sinc(xscale * x); } data[i * nsamp + j] = (float) y; } } }