# dsphdl.BiquadFilter

## 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', ... 'OutputDataType','Custom', ... 'CustomOutputDataType',numerictype(1,16,14)); [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'`

| `'Direct form I fully serial'`

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. These architectures do not support vector
input.

`'Pipelined feedback form'`

implements a pipelined architecture
that uses more multipliers than either direct form II structure, but achieves higher
clock rates after synthesis. Vector 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.

`'Direct form I fully serial'`

implements a fully serial
architecture that uses only one multiplier. When you select this option, the object
stores the numerator, denominator, and scale values in the same ROM. You can control the
data type of the ROM by using the `CoefficientDataType`

property.
When you select this architecture, the object has an output `ready`

argument. The `ready`

argument indicates when the object is ready for
new input data. Apply input data only when `ready`

is
`1`

(`true`

). This architecture does not support
vector input.

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

— Method to determine data type of numerator coefficients

`'Same word length as first input'`

(default) | `'Custom'`

Data type of numerator coefficients, specified as ```
'Same word length as
first input'
```

or `'Custom'`

.

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.

#### Dependencies

To enable this property, set the `Structure`

property to
`'Direct form II'`

, ```
'Direct form II
transposed'
```

, or `'Pipelined feedback form'`

.

`DenominatorDataType`

— Method to determine data type of denominator coefficients

`'Same word length as first input'`

(default) | `'Custom'`

Data type of denominator coefficients, specified as ```
'Same word length as
first input'
```

or `'Custom'`

.

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.

#### Dependencies

To enable this property, set the `Structure`

property to
`'Direct form II'`

, ```
'Direct form II
transposed'
```

, or `'Pipelined feedback form'`

.

`ScaleValuesDataType`

— Method to determine data type of section gains

`'Same word length as first input'`

(default) | `'Custom'`

Data type of the scale values, specified as ```
'Same word length as first
input'
```

or `'Custom'`

.

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.

#### Dependencies

To enable this property, set the `Structure`

property to
`'Direct form II'`

, ```
'Direct form II
transposed'
```

, or `'Pipelined feedback form'`

.

`CoefficientDataType`

— Method to determine data type of coefficient memory when using serial architecture

`'Same word length as first input'`

(default) | `'Custom'`

Data type of the scale values, specified as ```
'Same word length as first
input'
```

or `'Custom'`

.

The object casts the numerator, denominator, and scale values to this data type and stores them in an eight-element memory of this word length. 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.

#### Dependencies

To enable this property, set the `Structure`

property to
`'Direct form I fully serial'`

.

`AccumulatorDataType`

— Method to determine data type of accumulator signals within each section

`'Same as first input'`

(default) | `'Custom'`

Data type of accumulator signals within each section (as indicated in the diagrams
in the Algorithms section),
specified as `'Same as first input'`

, or
`'Custom'`

.

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`

— Method to determine data type of filter output

`'Same as first input'`

(default) | `'Full precision'`

| `'Custom'`

Data type of filter output, specified as `'Same as first input'`

,
`'Full precision'`

, or `'Custom'`

.

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.

`CustomNumeratorDataType`

— Data type of numerator coefficients

`numerictype`

object

Data type of numerator coefficients, specified as 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.

#### Dependencies

This property applies when you set the `NumeratorDataType`

property to `'Custom'`

.

`CustomDenominatorDataType`

— Data type of denominator coefficients

`numerictype`

object

Data type of denominator coefficients, specified as 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.

#### Dependencies

This property applies when you set the `DenominatorDataType`

property to `'Custom'`

.

`CustomScaleValuesDataType`

— Data type of section gains

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

#### Dependencies

This property applies when you set the `ScaleValuesDataType`

property to `'Custom'`

.

`CustomCoefficientDataType`

— Data type of coefficient memory when using serial architecture

`numerictype`

object

Data type of coefficient memory when using serial architecture, specified as 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 casts the numerator, denominator, and scale values to this data type and stores them in an eight-element memory of this word length.

#### Dependencies

This property applies when you set the `CoefficientDataType`

property to `'Custom'`

.

`CustomAccumulatorDataType`

— Data type of accumulator signals within each section

`numerictype`

object

Data type of accumulator signals within each section (as indicated in the diagrams
in the Algorithms section),
specified as 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.

#### Dependencies

This property applies when you set the `AccumulatorDataType`

property to `'Custom'`

.

`CustomOutputDataType`

— Data type of filter output

`numerictype`

object

Data type of filter output, specified as 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.

#### Dependencies

This property applies when you set the `OutputDataType`

property to `'Custom'`

.

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

When you set the `Structure`

property to ```
'Direct form
I fully serial'
```

, the object has an output `ready`

argument that indicates when the object is ready for new input. You can apply input
data only when the output `ready`

argument is `1`

(`true`

). Your design can react to the `ready`

argument to provide the next input sample, or you can space your input data with
enough cycles in between to process each sample. Use the `validOut`

argument to determine the cycles required to process one sample.

The software supports `double`

and
`single`

data types 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`

`ready`

— Indicates object is ready for new input data

scalar

Control signal that indicates that the object is ready for new input data sample
on the next call. When `ready`

is `1`

(`true`

), you can specify the `dataIn`

and `validIn`

inputs for the next
time step. When `ready`

is `0`

(`false`

), the object ignores any input data in the next time step.

When using the `'Direct form I fully serial'`

architecture, the
object processes one sample at a time. If your design waits for the object to return
`ready`

set to `0`

(`false`

)
before stopping the application of input data, then one additional input data value
arrives at the object. The object stores this additional data while processing the
current data, and does not set `ready`

to `1`

(`true`

) until the additional input is processed.

#### Dependencies

To enable this argument, set the `Structure`

property to
`'Direct form I fully serial'`

.

**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)

### Specific to `dsphdl.BiquadFilter`

`getLatency` | Latency of biquad filter |

## 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 VHDL, Verilog and SystemVerilog code for FPGA and ASIC designs using HDL Coder™.

The software supports `double`

and
`single`

data types 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**

### R2023a: Minimum resource architecture

The object now has the option to set the `Structure`

property to
`'Direct form I fully serial'`

to implement a fully serial architecture
that uses only one multiplier. When you select this option, the object stores the numerator,
denominator, and scale values in the same ROM, and you can control the data type of the ROM
by using the `CoefficientDataType`

property. When you select this
architecture, the object has an output `ready`

argument that indicates
when the object is ready for new input. You can apply input data only when the output
`ready`

argument is `1`

(`true`

).

## See Also

## MATLAB コマンド

次の MATLAB コマンドに対応するリンクがクリックされました。

コマンドを MATLAB コマンド ウィンドウに入力して実行してください。Web ブラウザーは MATLAB コマンドをサポートしていません。

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)