/* * resample.c * - a hacked version of * ipow.c, poly2d.c, and resampling.c * from version 3.6-0 of the Eclipse library (ESO) * by Nicolas Devillard * * see http://www.eso.org/eclipse for further details */ #include "resample.h" /*-------------------------------------------------------------------------*/ /** @name ipow @memo Same as pow(x,y) but for integer values of y only (faster). @param x A double number. @param p An integer power. @return x to the power p. @doc This is much faster than the math function due to the integer. Some compilers make this optimization already, some do not. p can be positive, negative or null. */ /*--------------------------------------------------------------------------*/ double ipow(double x, int p) { double r, recip ; /* Get rid of trivial cases */ switch (p) { case 0: return 1.00 ; case 1: return x ; case 2: return x*x ; case 3: return x*x*x ; case -1: return 1.00 / x ; case -2: return (1.00 / x) * (1.00 / x) ; } if (p>0) { r = x ; while (--p) r *= x ; } else { r = recip = 1.00 / x ; while (++p) r *= recip ; } return r; } /* * compute the value of a 2D polynomial at a point * - it assumes that ncoeff is a small number, so there's * little point in pre-calculating ipow(u,i) */ double poly2d_compute( int ncoeff, double *c, double u, double *vpow ) { double out; int i, j, k; out = 0.00; k = 0; for( j = 0; j < ncoeff; j++ ) { for( i = 0; i < ncoeff; i++ ) { out += c[k] * ipow( u, i ) * vpow[j]; k++; } } return out; } /*-------------------------------------------------------------------------*/ /** @name sinc @memo Cardinal sine. @param x double value. @return 1 double. @doc Compute the value of the function sinc(x)=sin(pi*x)/(pi*x) at the requested x. */ /*--------------------------------------------------------------------------*/ double sinc(double x) { if (fabs(x)<1e-4) return (double)1.00 ; else return ((sin(x * (double)PI_NUMB)) / (x * (double)PI_NUMB)) ; } /* sinc() */ /** @name reverse_tanh_kernel @memo Bring a hyperbolic tangent kernel from Fourier to normal space. @param data Kernel samples in Fourier space. @param nn Number of samples in the input kernel. @return void @doc Bring back a hyperbolic tangent kernel from Fourier to normal space. Do not try to understand the implementation and DO NOT MODIFY THIS FUNCTION. */ /*--------------------------------------------------------------------------*/ #define KERNEL_SW(a,b) tempr=(a);(a)=(b);(b)=tempr static void reverse_tanh_kernel(double * data, int nn) { unsigned long n, mmax, m, i, j, istep ; double wtemp, wr, wpr, wpi, wi, theta; double tempr, tempi; n = (unsigned long)nn << 1; j = 1; for (i=1 ; i i) { KERNEL_SW(data[j-1],data[i-1]); KERNEL_SW(data[j],data[i]); } m = n >> 1; while (m>=2 && j>m) { j -= m; m >>= 1; } j += m; } mmax = 2; while (n > mmax) { istep = mmax << 1; theta = 2 * M_PI / mmax; wtemp = sin(0.5 * theta); wpr = -2.0 * wtemp * wtemp; wpi = sin(theta); wr = 1.0; wi = 0.0; for (m=1 ; m