Finite Impulse Response Filters#
Finite impulse response (FIR) filters allow the use of arbitrary filters with a finite number of taps. This library does not provide FIR filter design tools, but allows for coefficients to be imported from other design tools, such as SciPy/filter_design.
FIR Direct#
The direct FIR implements the filter as a convolution in the time domain.
This library uses FIR filter_fir_s32
implementation from lib_xcore_math
to run on xcore.
More information on implementation can be found in XCORE Math Library documentation.
- class audio_dsp.dsp.fir.fir_direct(fs: float, n_chans: int, coeffs_path: Path, Q_sig: int = 27)
An FIR filter, implemented in direct form in the time domain.
When the filter coefficients are converted to fixed point, if there will be leading zeros, a left shift is applied to the coefficients in order to use the full dynamic range of the VPU. A subsequent right shift is applied to the accumulator after the convolution to return to the same gain.
- Parameters:
- fsint
Sampling frequency in Hz.
- n_chansint
Number of channels the block runs on.
- coeffs_pathPath
Path to a file containing the coefficients, in a format supported by np.loadtxt.
- Q_sig: int, optional
Q format of the signal, number of bits after the decimal point. Defaults to Q4.27.
- Attributes:
- fsint
Sampling frequency in Hz.
- n_chansint
Number of channels the block runs on.
- Q_sig: int
Q format of the signal, number of bits after the decimal point.
- coeffsnp.ndarray
Array of the FIR coefficients in floating point format.
- coeffs_intlist
Array of the FIR coefficients in fixed point int32 format.
- shiftint
Right shift to be applied to the fixed point convolution result. This compensates for any left shift applied to the coefficients.
- n_tapsint
Number of taps in the filter.
- buffernp.ndarray
Buffer of previous inputs for the convlution in floating point format.
- buffer_intlist
Buffer of previous inputs for the convlution in fixed point format.
- buffer_idxlist
List of the floating point buffer head for each channel.
- buffer_idx_intlist
List of the fixed point point buffer head for each channel.
- process(sample: float, channel: int = 0) float
Update the buffer with the current sample and convolve with the filter coefficients, using floating point math.
- Parameters:
- samplefloat
The input sample to be processed.
- channelint
The channel index to process the sample on.
- Returns:
- float
The processed output sample.
- reset_state() None
Reset all the delay line values to zero.
- check_coeff_scaling()
Check the coefficient scaling is optimal.
If there will be leading zeros, calculate a shift to use the full dynamic range of the VPU