/** * Returns a sinc interpolator with specified maximum error and frequency. * Computes the maximum length lmax. * @param emax the maximum error for frequencies less than fmax; e.g., * 0.01 for 1% percent error. Must be greater than 0.0 and less than 1.0. * @param fmax the maximum frequency, in cycles per sample. * Must be greater than 0.0 and less than 0.5. * @return the sinc interpolator. */ public static SincInterpolator fromErrorAndFrequency( double emax, double fmax) { return new SincInterpolator(emax,fmax,0); }
/** * Returns a sinc interpolator with specified maximum error and length. * Computes the maximum frequency fmax. Note that for some parameters * emax and lmax, the maximum frequency fmax may be zero. In this case, * the returned interpolator is useless. * @param emax the maximum error for frequencies less than fmax; e.g., * 0.01 for 1% percent error. 0.0 < emax <= 0.1 is required. * @param lmax the maximum interpolator length, in samples. * Must be an even integer not less than 8. * @return the sinc interpolator. */ public static SincInterpolator fromErrorAndLength( double emax, int lmax) { return new SincInterpolator(emax,0.0,lmax); }
/** * Returns a sinc interpolator with specified maximum frequency and length. * Computes the maximum error emax. * <p> * The product (1-2*fmax)*lmax must be greater than one. For when this * product is less than one, a useful upper bound on interpolation error * cannot be computed. * @param fmax the maximum frequency, in cycles per sample. * Must be greater than 0.0 and less than 0.5*(1.0-1.0/lmax). * @param lmax the maximum interpolator length, in samples. * Must be an even integer not less than 8 and greater than * 1.0/(1.0-2.0*fmax). * @return the sinc interpolator. */ public static SincInterpolator fromFrequencyAndLength( double fmax, int lmax) { return new SincInterpolator(0.0,fmax,lmax); }
/** * Constructs a dynamic warping for specified bounds on shifts. * @param shiftMin lower bound on shift u. * @param shiftMax upper bound on shift u. */ public DynamicWarping(int shiftMin, int shiftMax) { Check.argument(shiftMax-shiftMin>1,"shiftMax-shiftMin>1"); _lmin = shiftMin; _lmax = shiftMax; _nl = 1+_lmax-_lmin; _si = new SincInterpolator(); _extrap = ErrorExtrapolation.NEAREST; }
/** * Warps a sampled function using only 1st components of shifts. * @param f array of values f(x). * @return array of values g(y) = f(y-u1(x(y)). */ public float[][] warp1(float[][] f) { SincInterpolator si = new SincInterpolator(); float[][] g = new float[_n2][_n1]; for (int i2=0; i2<_n2; ++i2) { for (int i1=0; i1<_n1; ++i1) { g[i2][i1] = si.interpolate(_n1,1.0,0.0,f[i2],i1-u1y(i1,i2)); } } return g; }
/** * Unwarps a sampled function using only 1st components of shifts. * @param g array of values g(x). * @return array of values f(x) = g(x+u1(x)). */ public float[][] unwarp1(float[][] g) { SincInterpolator si = new SincInterpolator(); float[][] f = new float[_n2][_n1]; for (int i2=0; i2<_n2; ++i2) { for (int i1=0; i1<_n1; ++i1) { f[i2][i1] = si.interpolate(_n1,1.0,0.0,g[i2],i1+u1x(i1,i2)); } } return f; }
/** * Warps a sampled function. * @param f array of values f(x). * @return array of values g(y) = f(y-u(x(y)). */ public float[] warp(float[] f) { SincInterpolator si = new SincInterpolator(); float[] g = new float[_n]; for (int i=0; i<_n; ++i) { double y = i; double x = y-uy(y); g[i] = si.interpolate(_n,1.0,0.0,f,x); } return g; }
/** * Unwarps a sampled function. * @param g array of values g(x). * @return array of values f(x) = g(x+u(x)). */ public float[] unwarp(float[] g) { SincInterpolator si = new SincInterpolator(); float[] f = new float[_n]; for (int i=0; i<_n; ++i) { double x = i; double y = x+ux(x); f[i] = si.interpolate(_n,1.0,0.0,g,y); } return f; }
/** * Warps a sampled function using only 1st components of shifts. * @param f array of values f(x). * @return array of values g(y) = f(y-u1(x(y)). */ public float[][][] warp1(float[][][] f) { SincInterpolator si = new SincInterpolator(); float[][][] g = new float[_n3][_n2][_n1]; for (int i3=0; i3<_n3; ++i3) { for (int i2=0; i2<_n2; ++i2) { for (int i1=0; i1<_n1; ++i1) { g[i3][i2][i1] = si.interpolate( _n1,1.0,0.0,f[i3][i2],i1-u1y(i1,i2,i3)); } } } return g; }
/** * Unwarps a sampled function using only 1st components of shifts. * @param g array of values g(x). * @return array of values f(x) = g(x+u1(x)). */ public float[][][] unwarp1(float[][][] g) { SincInterpolator si = new SincInterpolator(); float[][][] f = new float[_n3][_n2][_n1]; for (int i3=0; i3<_n3; ++i3) { for (int i2=0; i2<_n2; ++i2) { for (int i1=0; i1<_n1; ++i1) { f[i3][i2][i1] = si.interpolate( _n1,1.0,0.0,g[i3][i2],i1+u1x(i1,i2,i3)); } } } return f; }
/** * Warps a sampled function using only all components of shifts. * @param f array of values f(x). * @return array of values g(y) = f(y-u(x(y)). */ public float[][] warp(float[][] f) { SincInterpolator si = new SincInterpolator(); float[][] g = new float[_n2][_n1]; for (int i2=0; i2<_n2; ++i2) { double y2 = i2; for (int i1=0; i1<_n1; ++i1) { double y1 = i1; double x1 = y1-u1y(y1,y2); double x2 = y2-u2y(y1,y2); g[i2][i1] = si.interpolate(_n1,1.0,0.0,_n2,1.0,0.0,f,x1,x2); } } return g; }
/** * Unwarps a sampled function using only all components of shifts. * @param g array of values g(x). * @return array of values f(x) = g(x+u(x)). */ public float[][] unwarp(float[][] g) { SincInterpolator si = new SincInterpolator(); float[][] f = new float[_n2][_n1]; for (int i2=0; i2<_n2; ++i2) { double x2 = i2; for (int i1=0; i1<_n1; ++i1) { double x1 = i1; double y1 = x1+u1x(x1,x2); double y2 = x2+u2x(x1,x2); f[i2][i1] = si.interpolate(_n1,1.0,0.0,_n2,1.0,0.0,g,y1,y2); } } return f; }
/** * Warps a sampled function using only all components of shifts. * @param f array of values f(x). * @return array of values g(y) = f(y-u(x(y)). */ public float[][][] warp(float[][][] f) { SincInterpolator si = new SincInterpolator(); float[][][] g = new float[_n3][_n2][_n1]; for (int i3=0; i3<_n3; ++i3) { double y3 = i3; for (int i2=0; i2<_n2; ++i2) { double y2 = i2; for (int i1=0; i1<_n1; ++i1) { double y1 = i1; double x1 = y1-u1y(y1,y2,y3); double x2 = y2-u2y(y1,y2,y3); double x3 = y3-u3y(y1,y2,y3); g[i3][i2][i1] = si.interpolate( _n1,1.0,0.0,_n2,1.0,0.0,_n3,1.0,0.0,f, x1,x2,x3); } } } return g; }
/** * Unwarps a sampled function using only all components of shifts. * @param g array of values g(x). * @return array of values f(x) = g(x+u(x)). */ public float[][][] unwarp(float[][][] g) { SincInterpolator si = new SincInterpolator(); float[][][] f = new float[_n3][_n2][_n1]; for (int i3=0; i3<_n3; ++i3) { double x3 = i3; for (int i2=0; i2<_n2; ++i2) { double x2 = i2; for (int i1=0; i1<_n1; ++i1) { double x1 = i1; double y1 = x1+u1x(x1,x2,x3); double y2 = x2+u2x(x1,x2,x3); double y3 = x3+u3x(x1,x2,x3); f[i3][i2][i1] = si.interpolate( _n1,1.0,0.0,_n2,1.0,0.0,_n3,1.0,0.0,g, y1,y2,y3); } } } return f; }
/** * Construct a shift estimator with specified parameters. * When applied to multi-dimensional arrays, the estimator has half-width * sigma1 for the 1st dimension, half-width sigma2 for the 2nd dimension, * and half-width sigma3 for 3rd and higher dimensions. * @param sigma1 correlation window half-width for 1st dimension; * must not be less than 1. * @param sigma2 correlation window half-width for 2nd dimension; * must not be less than 1. * @param sigma3 correlation window half-width for 3rd and higher * dimensions; must not be less than 1. */ public LocalShiftFinder(double sigma1, double sigma2, double sigma3) { Check.argument(sigma1>=1.0,"sigma1>=1.0"); Check.argument(sigma2>=1.0,"sigma2>=1.0"); Check.argument(sigma3>=1.0,"sigma3>=1.0"); _lcfSimple = new LocalCorrelationFilter( LocalCorrelationFilter.Type.SIMPLE, LocalCorrelationFilter.Window.GAUSSIAN, sigma1,sigma2,sigma3); _si = new SincInterpolator(); _si.setExtrapolation(SincInterpolator.Extrapolation.CONSTANT); }
SincInterpolator si = new SincInterpolator(); si.setExtrapolation(extrapolation);
SincInterpolator si = new SincInterpolator(); si.setExtrapolation(SincInterpolator.Extrapolation.CONSTANT); for (int i2=0; i2<nl2; ++i2) {
public void testExtrapolation() { SincInterpolator si = new SincInterpolator(); Random random = new Random(); int lmax = si.getMaximumLength();
public void testComplex() { SincInterpolator si = new SincInterpolator(); Random random = new Random(); int nxu = 100;