public class SincInterpolator
extends java.lang.Object
Below the specified (or computed) maximum frequency fmax, the maximum interpolation error should be less than the specified (or computed) maximum error emax. For frequencies above fmax, interpolation error may be much greater. Therefore, sequences to be interpolated should be bandlimited to frequencies less than fmax.
The maximum length lmax of an interpolator is an even positive integer. It is the number of uniform samples required to interpolate a single value y(x). Ideally, the weights applied to each uniform sample are values of a sinc function. Although the ideal sinc function yields zero interpolation error for all frequencies up to the Nyquist frequency (0.5 cycles/sample), it has infinite length.
With recursive filtering, infinite-length approximations to the sinc function are feasible and, in some applications, most efficient. When the number of interpolated values is large relative to the number of uniform samples, the cost of recursive filtering is amortized over those many interpolated values, and can be negligible. However, this cost becomes significant when only a few values are interpolated for each sequence of uniform samples.
This interpolator is based on a finite-length approximation to the sinc function. The efficiency of finite-length interpolators like this one does not depend on the number of samples interpolated. Also, this interpolator is robust in the presence of noise spikes, which affect only nearby samples.
Finite-length interpolators present a tradeoff between cost and accuracy. Interpolators with small maximum lengths are most efficient, and those with high maximum frequencies and small maximum errors are most accurate.
When interpolating multiple values of y(x) from a single sequence of uniformly sampled values, efficiency may be improved by using one of the methods that enables specification of multiple x values at which to interpolate.
Modifier and Type | Class and Description |
---|---|
static class |
SincInterpolator.Extrapolation
The method used to extrapolate samples when interpolating.
|
Constructor and Description |
---|
SincInterpolator()
Constructs a default sinc interpolator.
|
Modifier and Type | Method and Description |
---|---|
void |
accumulate(double xa,
float ya,
int nxu,
double dxu,
double fxu,
float[] yu)
Accumulates a specified real value y(x) into uniformly-sampled yu.
|
void |
accumulate(int nxa,
float[] xa,
float[] ya,
int nxu,
double dxu,
double fxu,
float[] yu)
Accumulates a specified real value y(x) into uniformly-sampled yu.
|
static SincInterpolator |
fromErrorAndFrequency(double emax,
double fmax)
Returns a sinc interpolator with specified maximum error and frequency.
|
static SincInterpolator |
fromErrorAndLength(double emax,
int lmax)
Returns a sinc interpolator with specified maximum error and length.
|
static SincInterpolator |
fromFrequencyAndLength(double fmax,
int lmax)
Returns a sinc interpolator with specified maximum frequency and length.
|
SincInterpolator.Extrapolation |
getExtrapolation()
Gets the extrapolation method for this interpolator.
|
double |
getMaximumError()
Gets the maximum error for this interpolator.
|
double |
getMaximumFrequency()
Gets the maximum frequency for this interpolator.
|
int |
getMaximumLength()
Gets the maximum length for this interpolator.
|
float[][] |
getTable()
Get a copy of the interpolation table.
|
long |
getTableBytes()
Gets the number of bytes consumed by the table of interpolators.
|
float |
interpolate(int nxu,
double dxu,
double fxu,
float[] yu,
double xi)
Interpolates one real value y(x).
|
void |
interpolate(int nxu,
double dxu,
double fxu,
float[] yu,
int nxi,
double dxi,
double fxi,
float[] yi)
Interpolates multiple real values y(x).
|
void |
interpolate(int nxu,
double dxu,
double fxu,
float[] yu,
int nxi,
float[] xi,
float[] yi)
Interpolates multiple real values y(x).
|
float |
interpolate(int nx1u,
double dx1u,
double fx1u,
int nx2u,
double dx2u,
double fx2u,
float[][] yu,
double x1i,
double x2i)
Interpolates one real value y(x1,x2).
|
float |
interpolate(int nx1u,
double dx1u,
double fx1u,
int nx2u,
double dx2u,
double fx2u,
int nx3u,
double dx3u,
double fx3u,
float[][][] yu,
double x1i,
double x2i,
double x3i)
Interpolates one real value y(x1,x2,x3).
|
float |
interpolate(Sampling sxu,
float[] yu,
double xi)
Interpolates one real value y(x).
|
void |
interpolate(Sampling sxu,
float[] yu,
Sampling sxi,
float[] yi)
Interpolates multiple real values y(x).
|
float |
interpolate(Sampling sx1u,
Sampling sx2u,
float[][] yu,
double x1i,
double x2i)
Interpolates one real value y(x1,x2).
|
float |
interpolate(Sampling sx1u,
Sampling sx2u,
Sampling sx3u,
float[][][] yu,
double x1i,
double x2i,
double x3i)
Interpolates one real value y(x1,x2,x3).
|
void |
interpolateComplex(int nxu,
double dxu,
double fxu,
float[] yu,
int nxi,
double dxi,
double fxi,
float[] yi)
Interpolates multiple complex values y(x).
|
void |
interpolateComplex(int nxu,
double dxu,
double fxu,
float[] yu,
int nxi,
float[] xi,
float[] yi)
Interpolates multiple complex values y(x).
|
void |
interpolateComplex(Sampling sxu,
float[] yu,
Sampling sxi,
float[] yi)
Interpolates multiple complex values y(x).
|
void |
setExtrapolation(SincInterpolator.Extrapolation extrap)
Sets the extrapolation method for this interpolator.
|
public SincInterpolator()
public static SincInterpolator fromErrorAndLength(double emax, int lmax)
emax
- the maximum error for frequencies less than fmax; e.g.,
0.01 for 1% percent error. 0.0 < emax <= 0.1 is required.lmax
- the maximum interpolator length, in samples.
Must be an even integer not less than 8.public static SincInterpolator fromErrorAndFrequency(double emax, double fmax)
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.fmax
- the maximum frequency, in cycles per sample.
Must be greater than 0.0 and less than 0.5.public static SincInterpolator fromFrequencyAndLength(double fmax, int lmax)
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.
fmax
- the maximum frequency, in cycles per sample.
Must be greater than 0.0 and less than 0.5*(1.0-1.0/lmax).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).public double getMaximumError()
public double getMaximumFrequency()
public int getMaximumLength()
public long getTableBytes()
public SincInterpolator.Extrapolation getExtrapolation()
public void setExtrapolation(SincInterpolator.Extrapolation extrap)
extrap
- the extrapolation method.public float interpolate(int nxu, double dxu, double fxu, float[] yu, double xi)
nxu
- number of input samples.dxu
- input sampling interval.fxu
- first input sampled x value.yu
- input array of sampled values y(x).xi
- value x at which to interpolate.public void interpolate(int nxu, double dxu, double fxu, float[] yu, int nxi, float[] xi, float[] yi)
nxu
- number of input samples.dxu
- input sampling interval.fxu
- first input sampled x value.yu
- input array of sampled values y(x).nxi
- number of output samples.xi
- input array of x values at which to interpolate.yi
- output array of interpolated values y(x).public void interpolate(int nxu, double dxu, double fxu, float[] yu, int nxi, double dxi, double fxi, float[] yi)
nxu
- number of input samples.dxu
- input sampling interval.fxu
- first input sampled x value.yu
- input array of sampled values y(x).nxi
- number of output samples.dxi
- output sampling interval.fxi
- first output sampled x value.yi
- output array of interpolated values y(x).public float interpolate(int nx1u, double dx1u, double fx1u, int nx2u, double dx2u, double fx2u, float[][] yu, double x1i, double x2i)
nx1u
- number of input samples in 1st dimension.dx1u
- input sampling interval in 1st dimension.fx1u
- first input sampled x value in 1st dimension.nx2u
- number of input samples in 2nd dimension.dx2u
- input sampling interval in 2nd dimension.fx2u
- first input sampled x value in 2nd dimension.yu
- input array of sampled values y(x).x1i
- 1st coordinate of x at which to interpolate.x2i
- 2nd coordinate of x at which to interpolate.public float interpolate(int nx1u, double dx1u, double fx1u, int nx2u, double dx2u, double fx2u, int nx3u, double dx3u, double fx3u, float[][][] yu, double x1i, double x2i, double x3i)
nx1u
- number of input samples in 1st dimension.dx1u
- input sampling interval in 1st dimension.fx1u
- first input sampled x value in 1st dimension.nx2u
- number of input samples in 2nd dimension.dx2u
- input sampling interval in 2nd dimension.fx2u
- first input sampled x value in 2nd dimension.nx3u
- number of input samples in 3rd dimension.dx3u
- input sampling interval in 3rd dimension.fx3u
- first input sampled x value in 3rd dimension.yu
- input array of sampled values y(x).x1i
- 1st coordinate of x at which to interpolate.x2i
- 2nd coordinate of x at which to interpolate.x3i
- 3rd coordinate of x at which to interpolate.public float interpolate(Sampling sxu, float[] yu, double xi)
sxu
- sampling of input samples.yu
- input array of uniformly sampled values y(x).xi
- value x at which to interpolate.public void interpolate(Sampling sxu, float[] yu, Sampling sxi, float[] yi)
sxu
- sampling of input samples.yu
- input array of uniformly sampled values y(x).sxi
- sampling of output samples.yi
- output array of interpolated values y(x).public float interpolate(Sampling sx1u, Sampling sx2u, float[][] yu, double x1i, double x2i)
sx1u
- sampling of input x in 1st dimension.sx2u
- sampling of input x in 2nd dimension.yu
- input array of sampled values y(x).x1i
- 1st coordinate of x at which to interpolate.x2i
- 2nd coordinate of x at which to interpolate.public float interpolate(Sampling sx1u, Sampling sx2u, Sampling sx3u, float[][][] yu, double x1i, double x2i, double x3i)
sx1u
- sampling of input x in 1st dimension.sx2u
- sampling of input x in 2nd dimension.sx3u
- sampling of input x in 3rd dimension.yu
- input array of sampled values y(x).x1i
- 1st coordinate of x at which to interpolate.x2i
- 2nd coordinate of x at which to interpolate.x3i
- 3rd coordinate of x at which to interpolate.public void interpolateComplex(int nxu, double dxu, double fxu, float[] yu, int nxi, double dxi, double fxi, float[] yi)
nxu
- number of input samples.dxu
- input sampling interval.fxu
- first input sampled x value.yu
- input array[2*nxu] of sampled complex values y(x).nxi
- number of output samples.dxi
- output sampling interval.fxi
- first output sampled x value.yi
- output array[2*nxi] of interpolated complex values y(x).public void interpolateComplex(int nxu, double dxu, double fxu, float[] yu, int nxi, float[] xi, float[] yi)
nxu
- number of input samples.dxu
- input sampling interval.fxu
- first input sampled x value.yu
- input array[2*nxu] of sampled complex values y(x).nxi
- number of output samples.xi
- input array[nxi] of x values at which to interpolate.yi
- output array[2*nxi] of interpolated complex values y(x).public void interpolateComplex(Sampling sxu, float[] yu, Sampling sxi, float[] yi)
sxu
- sampling of input samples.yu
- input array[2*nxu] of sampled complex values y(x).sxi
- sampling of output samples.yi
- output array[2*nxi] of interpolated complex values y(x).public void accumulate(double xa, float ya, int nxu, double dxu, double fxu, float[] yu)
xa
- value x at which to accumulate.ya
- value y(x) to accumulate.nxu
- number of input/output samples.dxu
- input/output sampling interval.fxu
- first input/output sampled x value.yu
- input/output array of sampled values y(x).public void accumulate(int nxa, float[] xa, float[] ya, int nxu, double dxu, double fxu, float[] yu)
nxa
- number of values to accumulate.xa
- input array of values x at which to accumulate.ya
- input array of values y(x) to accumulate.nxu
- number of input/output samples.dxu
- input/output sampling interval.fxu
- first input/output sampled x value.yu
- input/output array of sampled values y(x).public float[][] getTable()