public float[] map(final float[] data) { final float[] out = new float[data.length * upFactor / downFactor]; for (int i = 0; i < data.length; i++) { final float sample = data[i]; for (int j = 0; j < upFactor; j++) { final Filters.FIRFilter filter = filters[j]; filter.addToDelayLine(sample); final int upsampledIndex = i * upFactor + j; if (upsampledIndex % downFactor == 0) { out[upsampledIndex / downFactor] = (float) filter.filter(); } } } return out; }
public float[] map(final float[] data) { final int outLength = data.length * factor; if (out == null || out.length != outLength) { out = new float[outLength]; } else { Arrays.fill(out, 0); } for (int i = 0; i < data.length; i++) { final float sample = data[i]; for (int j = 0; j < factor; j++) { final Filters.FIRFilter filter = filters[j]; filter.addToDelayLine(sample); out[i * factor + j] = (float) filter.filter(); } } return out; }
/** * Creates a decimator with the given FIR (low pass) filter. * * @param filter FIR filter * @param factor nth frame to keep (factor) */ public Decimator(final Filters.FIRFilter filter, final int factor) { super(filter.getCoefficients()); this.factor = factor; }
@Override public void reset() { super.reset(); pos = 0; }
/** * Creates a resampler using a FIR low pass filter and the given up- and down-sample factors. * The filter must be appropriate for the given factors. Internally the up- and down-factors are * divided by their greatest common divisor to increase efficiency. * * @param filter FIR filter * @param upFactor upsample factor * @param downFactor downsample factor */ public Resampler(final Filters.FIRFilter filter, final int upFactor, final int downFactor) { this(filter.getCoefficients(), upFactor, downFactor); }
/** * Creates an interpolator with the given FIR filter for filtering after upsampling to avoid * aliasing. It's recommended to use a filter with a multiple of the upsample factor as the * number of coefficients (taps). If that's not the case, zeros are added to the filter's * coefficients. * * @param filter FIR filter * @param factor upsample factor */ public Interpolator(final Filters.FIRFilter filter, final int factor) { this(filter.getCoefficients(), factor); }