# 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:

Create the

`dsphdl.BiquadFilter`

object and set its properties.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

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

= dsphdl.BiquadFilter

sets properties using one or more name-value pairs. Enclose each property name in single
quotes.`myfilt`

= dsphdl.BiquadFilter(`Name,Value`

)

For example:

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

## Properties

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.

`Structure`

— HDL filter architecture

`'Direct form II'`

(default) | `'Direct form II transposed'`

| `'Pipelined feedback form'`

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.

`Numerator`

— Coefficients of filter numerator

`[1,2,1]`

(default) | *NumSections*-by-3 matrix

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.

`Denominator`

— Coefficients of filter denominator

`[1,.1,.2]`

(default) | *NumSections*-by-3 matrix

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.

`ScaleValues`

— Gain values applied before and after second-order filter sections

`[1]`

(default) | vector of 1 to *NumSections*+1 values

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 `

— Rounding method for type-casting the output

`'Floor'`

(default) | `'Ceiling'`

| `'Convergent'`

| `'Nearest'`

| `'Round'`

| `'Zero'`

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.

`OverflowAction`

— Overflow handling for type-casting the output

`'Wrap'`

(default) | `'Saturate'`

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.

`NumeratorDataType`

— Data type of numerator coefficients

`'Same word length as first input'`

(default) | `numerictype`

object

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.

`DenominatorDataType`

— Data type of denominator coefficients

`'Same word length as first input'`

(default) | `numerictype`

object

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.

`ScaleValueDataType`

— Data type of section gains

`'Same word length as first input'`

(default) | `numerictype`

object

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.

`AccumulatorDataType`

— Data type of accumulator signals within each section

`'Same as first input'`

(default) | `numerictype`

object

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.

`OutputDataType`

— Data type of filter output

`'Same as first input'`

(default) | `'Full precision'`

| `numerictype`

object

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

### Input Arguments

`dataIn`

— Input data

scalar or column vector of real values

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
`Structure`

property 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`

`validIn`

— Indicates valid input data

scalar

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

`dataOut`

— Filtered output data

scalar or column vector of real values

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`

`validOut`

— Indicates valid output data

scalar

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)

## Algorithms

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

## Extended Capabilities

### C/C++ Code Generation

Generate C and C++ code using MATLAB® Coder™.

This System object supports C/C++ code generation for accelerating MATLAB^{®} simulations, and for DPI component generation.

### HDL Code Generation

Generate Verilog and VHDL code for FPGA and ASIC designs using HDL Coder™.

`double`

and `single`

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

To generate HDL code from predefined System objects, see HDL Code Generation from Viterbi Decoder System Object (HDL Coder).

## Version History

**Introduced in R2022a**

## See Also

## MATLAB Command

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

# Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

## How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

### Americas

- América Latina (Español)
- Canada (English)
- United States (English)

### Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)