public class FftFilter
extends java.lang.Object
The filter is specified as a 1D, 2D or 3D array of coefficients. Filter dimension must match that of arrays to be filtered. For example, a filter constructed with a 2D array of coefficients cannot be applied to a 1D array.
The linear shift-invariant filtering performed by this class is a convolution sum. Each output sample in y is a sum of scaled input samples in x. For 1D filters this sum is
nh-1-kh
y[i] = sum h[kh+j]*x[i-j] ; i = 0, 1, 2, ..., ny-1 = nx-1
j=-kh
For each output sample y[i], kh is the array index of the filter
coefficient h[kh] that scales the corresponding input sample x[i].
For example, in a symmetric filter with odd length nh, the index
kh = (nh-1)/2 is that of the middle coefficient in the array h.
In other words, kh is the array index of the filter's origin.
The lengths nx and ny of the input and output arrays x and y are assumed to be equal. By default, values beyond the ends of an input array x in the convolution sum above are assumed to be zero. That is, zero values are used for x[i-j] when i-j < 0 or when i-j >= nx. Other methods for defining values beyond the ends of the array x may be specified. With any of these methods, the input array x is padded with extra values so that x[i-j] is defined for any i-j in the range [kh-nh+1:kh+nx-1] required by the convolution sum.
For efficiency, this filter can cache the fast Fourier transform of its coefficients h when the filter is first applied to any input array x. The filter may then be applied again, without recomputing its FFT, to other input arrays x that have the same lengths. The FFT of a cached filter is recomputed only when the lengths of the input and output arrays have changed. Because this caching consumes memory, it is disabled by default.
Modifier and Type | Class and Description |
---|---|
static class |
FftFilter.Extrapolation
The method used to extrapolate values beyond the ends of input arrays.
|
Constructor and Description |
---|
FftFilter(float[] h)
Constructs an FFT filter for specified filter coefficients.
|
FftFilter(float[][] h)
Constructs an FFT filter for specified filter coefficients.
|
FftFilter(float[][][] h)
Constructs an FFT filter for specified filter coefficients.
|
FftFilter(int kh,
float[] h)
Constructs an FFT filter for specified filter coefficients.
|
FftFilter(int kh1,
int kh2,
float[][] h)
Constructs an FFT filter for specified filter coefficients.
|
FftFilter(int kh1,
int kh2,
int kh3,
float[][][] h)
Constructs an FFT filter for specified filter coefficients.
|
Modifier and Type | Method and Description |
---|---|
float[] |
apply(float[] x)
Applies this filter.
|
float[][] |
apply(float[][] x)
Applies this filter.
|
float[][][] |
apply(float[][][] x)
Applies this filter.
|
void |
apply(float[][][] x,
float[][][] y)
Applies this filter.
|
void |
apply(float[][] x,
float[][] y)
Applies this filter.
|
void |
apply(float[] x,
float[] y)
Applies this filter.
|
void |
setExtrapolation(FftFilter.Extrapolation extrapolation)
Sets the method used to extrapolate values beyond the ends of input arrays.
|
void |
setFilterCaching(boolean filterCaching)
Enables or disables caching of the Fourier transform of the filter.
|
public FftFilter(float[] h)
h
- array of filter coefficients; copied, not referenced.public FftFilter(int kh, float[] h)
kh
- array index of the filter's origin.h
- array of filter coefficients; copied, not referenced.public FftFilter(float[][] h)
h
- array of filter coefficients; copied, not referenced.public FftFilter(int kh1, int kh2, float[][] h)
kh1
- array index in 1st dimension of the filter's origin.kh2
- array index in 2nd dimension of the filter's origin.h
- array of filter coefficients; copied, not referenced.public FftFilter(float[][][] h)
h
- array of filter coefficients; copied, not referenced.public FftFilter(int kh1, int kh2, int kh3, float[][][] h)
kh1
- array index in 1st dimension of the filter's origin.kh2
- array index in 2nd dimension of the filter's origin.kh3
- array index in 3rd dimension of the filter's origin.h
- array of filter coefficients; copied, not referenced.public void setExtrapolation(FftFilter.Extrapolation extrapolation)
extrapolation
- the extrapolation method.public void setFilterCaching(boolean filterCaching)
filterCaching
- true, to enable caching; false, to disable.public float[] apply(float[] x)
x
- input array.public void apply(float[] x, float[] y)
x
- input array.y
- output array.public float[][] apply(float[][] x)
x
- input array.public void apply(float[][] x, float[][] y)
x
- input array.y
- output filtered array.public float[][][] apply(float[][][] x)
x
- input array.public void apply(float[][][] x, float[][][] y)
x
- input array.y
- output filtered array.