Main Content

dsphdl.BiquadFilter

Biquadratic IIR (SOS) filter

Description

A biquad filter is a form of infinite-impulse response (IIR) filter where the numerator and denominator are split into a series of second-order sections connected by gain blocks. This type of filter can replace a large FIR filter that uses an impractical amount of hardware resources. Designs often use biquad filters as DC blocking filters or to meet a specification originally implemented with an analog filter, such as a pre-emphasis filter.

To filter input data with an HDL-optimized biquad filter:

  1. Create the dsphdl.BiquadFilter object and set its properties.

  2. Call the object with arguments, as if it were a function.

To learn more about how System objects work, see What Are System Objects?

Creation

Description

myfilt = dsphdl.BiquadFilter creates an HDL-optimized biquad filter. The default filter is a direct form II architecture with one section.

myfilt = dsphdl.BiquadFilter(Name,Value) sets properties using one or more name-value pairs. Enclose each property name in single quotes.

For example:

myfilt = dsphdl.BiquadFilter('Structure','Direct form II transposed');
[dataOut,validOut] = myfilt(dataIn,validIn);

Properties

expand all

Unless otherwise indicated, properties are nontunable, which means you cannot change their values after calling the object. Objects lock when you call them, and the release function unlocks them.

If a property is tunable, you can change its value at any time.

For more information on changing property values, see System Design in MATLAB Using System Objects.

Both the 'Direct form II' and 'Direct form II transposed' architectures are pipelined and quantized to fit well into FPGA DSP blocks. The output of these filters matches the output of the DSP System Toolbox™ System objects dsp.SOSFilter and dsp.FourthOrderSectionFilter. These architectures minimize the number of multipliers used by the filter but have a critical path through the feedback loop and sometimes cannot achieve higher clock rates.

'Pipelined feedback form' implements a pipelined architecture that uses more multipliers than either direct form II structure, but achieves higher clock rates after synthesis. Frame-based input is supported only when you use 'Pipelined feedback form'. The output of the pipelined filter is slightly different than the DSP System Toolbox functions dsp.SOSFilter and dsp.FourthOrderSectionFilter because of the timing of data samples applied in the pipelined filter stages.

Specify the numerator coefficients as a matrix of NumSections-by-3 values. NumSections is the number of second-order filter sections. The object infers the number of filter sections from the size of the numerator and denominator coefficients. The numerator coefficient and denominator coefficient matrices must be the same size. The default filter has one section.

Specify the denominator coefficients as a matrix of NumSections-by-3 values. The object assumes the first denominator coefficient of each section is 1.0.NumSections is the number of second-order filter sections. The object infers the number of sections from the size of the numerator and denominator coefficients. The numerator coefficient and denominator coefficient matrices must be the same size. The default filter has one section.

Specify the gain values as a vector of up to NumSections+1 values. NumSections is the number of second-order filter sections. The object infers the number of sections from the size of the numerator and denominator coefficients. If the vector has only one value, the object applies that gain before the first section. If you specify fewer values than there are filter sections, the object sets the remaining section gain values to one. The diagram shows a 3-section filter and the locations of the four scale values before and after the sections.

Implementing these gain factors outside the filter sections reduces the multipliers needed to implement the numerator of the filter.

Data Types

Rounding mode for type-casting the output and accumulator values to the data types specified by the OutputDataType and AccumulatorDataType properties. When the input data type is floating point, the object ignores this parameter. For more details, see Rounding Modes.

Overflow handling for type-casting the output and accumulator values to the data types specified by the OutputDataType and AccumulatorDataType properties. When the input data type is floating point, the object ignores the OverflowAction property. For more details, see Overflow Handling.

Data type of numerator coefficients, specified as 'Same word length as first input' or a numerictype object. To specify a numerictype object, call numerictype(s,w,f), where:

  • s is 1 for signed and 0 for unsigned.

  • w is the word length in bits.

  • f is the number of fractional bits.

The object type-casts the numerator coefficients to the specified data type. The quantization rounds to the nearest representable value and saturates on overflow. When the input data type is floating point, the object ignores this property.

The object returns a warning if the data type of the coefficients does not have enough fractional length to represent the coefficients accurately.

Data type of denominator coefficients, specified as 'Same word length as first input' or a numerictype object. To specify a numerictype object, call numerictype(s,w,f), where:

  • s is 1 for signed and 0 for unsigned.

  • w is the word length in bits.

  • f is the number of fractional bits.

The object type-casts the denominator coefficients to the specified data type. The quantization rounds to the nearest representable value and saturates on overflow. When the input data type is floating point, the object ignores this property.

The object returns a warning if the data type of the coefficients does not have enough fractional length to represent the coefficients accurately.

Data type of the scale values, specified as 'Same word length as first input' or a numerictype object. To specify a numerictype object, call numerictype(s,w,f), where:

  • s is 1 for signed and 0 for unsigned.

  • w is the word length in bits.

  • f is the number of fractional bits.

The object type-casts the scale values to the specified data type. The quantization rounds to the nearest representable value and saturates on overflow. When the input data type is floating point, the object ignores this property.

Data type of accumulator signals within each section (as indicated in the diagrams in the Algorithms section), specified as 'Same as first input', or a numerictype object. To specify a numerictype object, call numerictype(s,w,f), where:

  • s is 1 for signed and 0 for unsigned.

  • w is the word length in bits.

  • f is the number of fractional bits.

The object type-casts the output of the filter to the specified data type. The quantization uses the settings of the RoundingMethod and OverflowAction properties. When the input data type is floating point, the object ignores this property.

Data type of filter output, specified as 'Same as first input', 'Full precision', or a numerictype object. To specify a numerictype object, call numerictype(s,w,f), where:

  • s is 1 for signed and 0 for unsigned.

  • w is the word length in bits.

  • f is the number of fractional bits.

The object type-casts the output of the filter to the specified data type. The quantization uses the settings of the RoundingMethod and OverflowAction properties. When the input data type is floating point, the object ignores this property.

Usage

Description

[dataOut,validOut] = myfilt(dataIn,validIn) filters the input data only when validIn is true.

Input Arguments

expand all

Input data, specified as a scalar or column vector of real values. When the input has an integer or fixed-point data type, the object uses fixed-point arithmetic for internal calculations.

Vector input is supported only when you set the Structureproperty to 'Pipelined feedback form'. The object accepts vectors up to 64 samples, but large vector sizes can make the calculation of internal data types challenging. Vector sizes of up to 16 samples are practical for hardware implementation.

double and single data types are supported for simulation, but not for HDL code generation.

Data Types: fi | single | double | int8 | int16 | int32 | uint8 | uint16 | uint32

Control signal that indicates if the input data is valid. When validIn is 1 (true), the object captures the values from the dataIn argument. When validIn is 0 (false), the object ignores the values from the dataIn argument.

Data Types: logical

Output Arguments

expand all

Filtered output data, returned as a scalar or column vector of real values. The output dimensions match the input dimensions. When the input data is floating point, the output data inherits the data type of the input data. When the input data is an integer type or fixed-point type, the OutputDataType property determines the output data type.

Data Types: fi | single | double | int8 | int16 | int32 | uint8 | uint16 | uint32

Control signal that indicates if the output data is valid. When validOut is 1 (true), the object returns valid data from the dataOut argument. When validOut is 0 (false), values from the dataOut argument are not valid.

Data Types: logical

Object Functions

To use an object function, specify the System object™ as the first input argument. For example, to release system resources of a System object named obj, use this syntax:

release(obj)

expand all

stepRun System object algorithm
releaseRelease resources and allow changes to System object property values and input characteristics
resetReset internal states of System object

Algorithms

This System object implements the algorithms described on the Biquad Filter block reference page.

Extended Capabilities

Version History

Introduced in R2022a