Engee documentation

EngeeDSP.SOSFilter

Implementation of the IIR filter structure based on second-order sections.

Library

EngeeDSP

Description

To implement the IIR filter structure using second-order sections (SOS), follow these steps:

  1. Create an object EngeeDSP.SOSFilter and set its properties.

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

To learn more about how to work with system objects, see Engee System Objects.

Syntax

Creation

  • sos = EngeeDSP.SOSFilter() — returns the biquadrate IIR filter object sos, which independently filters each channel (column) of the input signal by time, using a given biquadrate structure.

  • sos = EngeeDSP.SOSFilter(Name=Value) — returns the biquadrate IIR filter object sos with the specified properties as a pair Name=Value, where Name — the name of the property, and Value — the appropriate value. You can specify multiple pairs «name-value» the order of the pairs does not matter. Unspecified properties retain their default values.

Using

  • y = sos(x) — filters the input signal x and outputs the filtered values y. The filter object sos filters each channel (column) of the input signal independently with successive calls to the algorithm.

    This syntax can only be used if for the property [Property:CoordicientSource] the value is set "Property".

  • y = sos(x,num,den) — filters the input signal x using the values of the argument num as the coefficients of the numerator, and den — as coefficients of the denominator of the filter.

    This syntax can only be used if for the [Property:CoordicientSource] the value is set "Input port", and for the property HasScaleValues value false.

  • y = sos(x,num,den,g) — also uses scaling factors g for the second-order section filter.

    This syntax can only be used if for the [Property:CoordicientSource] the value is set "Input port", and for the property HasScaleValues value true.

Arguments

Input arguments

x — input signal

+ scalar | vector | the matrix

Details

An input signal specified as a scalar, vector, or matrix.

This object also accepts a variable-size input signal. After running the system object algorithm, you can change the size of each input channel, but you cannot change the number of channels.

The input signal can be represented in the format fixed point. If the length of the fractional part is not specified, the object determines it based on the input data to ensure the highest possible accuracy.

The data type of all input arguments must be the same.

Типы данных

Float32, Float64, Int8, Int16, Int32, Int64, Fixed

Support for complex numbers

Yes

num — coefficients of the numerator

+ the P×3 matrix

Details

The coefficients of the numerator, given as a matrix on , where — the number of sections of the biquadrate filter. Each row corresponds to the coefficients of the numerator of the corresponding filter section.

After running the algorithm, the size of this input argument cannot be changed. However, the values of the numerator coefficients can be changed because the input is configurable.

The num signal can be represented in the format fixed point. If the length of the fractional part is not specified, the object determines it based on the input data to ensure the highest possible accuracy.

The data type of all input arguments must be the same.

The size and complexity of the input arguments num and den must be the same.

Dependencies

To use this argument, set the property to [Property:Coefficient Source] value "Input port".

Типы данных

Float32, Float64, Int8, Int16, Int32, Int64, Fixed

Support for complex numbers

Yes

den — denominator coefficients

+ the P×3 matrix

Details

The coefficients of the denominator of the filter, given as a matrix on , where — the number of sections of the biquadrate filter. Each row corresponds to the coefficients of the denominator of the corresponding filter section.

The leading coefficient of the denominator is always assumed to be equal 1. If any other value is specified in the first column, the object ignores this value and treats it as 1.

After running the algorithm, the size of this input argument cannot be changed. However, the values of the denominator coefficients can be changed because the input is configurable.

The den signal can be represented in the format fixed point. If the length of the fractional part is not specified, the object determines it based on the input data to ensure the highest possible accuracy.

The data type of all input arguments must be the same.

The size and complexity of the input arguments num and den must be the same.

Dependencies

To use this argument, set the property to [Property:Coefficient Source] value "Input port".

Типы данных

Float32, Float64, Int8, Int16, Int32, Int64, Fixed

Support for complex numbers

Yes

g — scaling factors for each second-order biquadrate section

+ vector 1×(P+1)

Details

The scaling coefficients of the biquad filter, set as a vector on , where — the number of sections of the biquadrate filter.

The g signal can be represented in the format fixed point. If the length of the fractional part is not specified, the object determines it based on the input data to ensure the highest possible accuracy.

The data type of all input arguments must be the same.

Dependencies

To use this argument, set the property to [Property:Coefficient Source] value "Input port", and for the property HasScaleValues value true.

Типы данных

Float32, Float64, Int8, Int16, Int32, Int64, Fixed

Output arguments

y — filtered output signal

+ scalar | vector | the matrix

Details

The filtered output signal returned as a scalar, vector, or matrix. The size and complexity of the output signal are the same as that of the input signal.

If the input signal is represented in a fixed-point format, the data type of the output signal is determined based on the value of the OutputDataType. If for a property OutputDataType value set "Full precision", the type of output data is calculated based on the diagrams of signal flows given in the Fixed-point filter structures section. If for a property OutputDataType a custom value is set, the output data is converted to the specified numeric type.

If the input is represented in floating-point format, the output data type is the same as the input data type, since floating-point inheritance takes precedence over fixed-point settings.

Типы данных

Float32, Float64, Int8, Int16, Int32, Int64, Fixed

Support for complex numbers

Yes

Features

# Structure — filter structure

+ "Direct form II transposed" (by default) | "Direct form I" | "Direct form I transposed" | "Direct form II"

Details

The filter structure, defined as "Direct form I", "Direct form I transposed", "Direct form II" or "Direct form II transposed" (by default).

# Coefficient Source — the source of the filter coefficients

+ "Property" (by default) | "Input port"

Details

The source of the filter coefficients is specified as one of the following:

  • "Property" (by default) — filter coefficients are set via the properties Numerator, Denominator and ScaleValues.

  • "Input port" — the coefficients of the numerator, denominator, and scale coefficients are specified as input arguments of the object when executing the algorithm.

# Numerator — coefficients of the numerator of the filter

+ [0.0975 0.195 0.0975] (by default) | the P×3 matrix

Details

The coefficients of the numerator of the filter, given as a matrix on , where — the number of sections of the biquadrate filter. Each row corresponds to the coefficients of the numerator of the corresponding filter section.

Dependencies

To use this property, set the [Property:Coefficient Source] value "Property".

# Denominator — coefficients of the denominator of the filter

+ [1 -0.9428 0.3333] (by default) | the P×3 matrix

Details

The coefficients of the denominator of the filter, given as a matrix on , where — the number of sections of the biquadrate filter. Each row corresponds to the coefficients of the denominator of the corresponding filter section.

The leading coefficient of the denominator is always assumed to be equal 1. If any other value is specified in the first column, the object ignores this value and treats it as 1.

After executing the algorithm, the size of this property cannot be changed. However, the denominator values can be changed because the property is configurable.

Dependencies

To use this property, set the [Property:Coefficient Source] value "Property".

# HasScaleValues — specify whether the filter has a scale factor for each section

+ false (default) | true

Details

Specify whether the filter has a scale factor for each section. If the value is set to true, using the ScaleValues You can set the scaling factors that will be applied before and after each section of the biquadrate filter.

# ScaleValues — scaling coefficients for each section of the second-order biquad filter

+ [1 1] (by default) | vector

Details

The scaling factors to apply before and after each section of the biquadrate filter, set as a vector. The length of the ScaleValues vector must be , where — the number of sections of the biquadrate filter. If you set a scalar value for this property, it will be used as a gain factor only before the first section of the filter. The remaining gain values are set to 1. If you set a vector for this property from values, each value will be used for a separate filter section.

Dependencies

To use this property, set the [Property:Coefficient Source] value "Property", and for the property HasScaleValues value true.

# RoundingMethod — rounding method

+ "Floor" (default) | "Ceiling" | "Convergent" | "Nearest" | "Round" | "Simplest" | "Zero"

Details

The rounding method for operations with integer types and fixed-point numbers, specified as one of the following:

  • "Floor" (by default);

  • "Ceiling";

  • "Convergent";

  • "Nearest";

  • "Round";

  • "Simplest";

  • "Zero".

# OverflowAction — selection of overflow action

+ "Wrap" (by default) | "Saturate"

Details

The choice of overflow action used when working with integer types and fixed-point numbers, set as one of the following:

  • "Wrap" (default) — the object wraps the result of its operations with a fixed point.

  • "Saturate" — the object saturates the result of its operations with a fixed point.

# SectionInputDataType is the data type at the input of the filter sections

+ "Same as input" (by default)

Details

The data type at the input of the filter sections used when working with integer types and fixed-point numbers.

Dependencies

To use this property, set the HasScaleValues value true.

# SectionOutputDataType is the data type at the output of the filter sections

+ "Same as section input" (by default)

Details

The data type at the output of the filter sections used when working with integer types and fixed-point numbers.

Dependencies

To use this property, set the HasScaleValues value true.

# NumeratorDataType is the data type of the numerator coefficients

+ "Same word length as input" (by default)

Details

The data type of numerator coefficients used when working with integer types and fixed-point numbers.

Dependencies

To use this property, set the [Property:Coefficient Source] value "Property".

# DenominatorDataType is the data type of the denominator coefficients

+ "Same word length as input" (by default)

Details

The data type of the denominator coefficients used when working with integer types and fixed-point numbers.

Dependencies

To use this property, set the [Property:Coefficient Source] value "Property".

# ScaleValuesDataType — the data type of the zoom coefficients

+ "Same word length as input" (by default)

Details

The data type of scaling factors used when working with integer types and fixed-point numbers.

Dependencies

To use this property, set the [Property:Coefficient Source] value "Property", and for the property HasScaleValues value true.

# MultiplicandDataType is the data type of the internal intermediate multiplier

+ "Same as output" (by default)

Details

The data type of the internal intermediate multiplier used when working with integer types and fixed-point numbers.

Dependencies

To use this property, set the Structure property to "Direct form I transposed".

# StateDataType is the data type of the internal state

+ "Full precision" (by default)

Details

The internal state data type used when working with integer types and fixed-point numbers.

Dependencies

To use this property, set the Structure property to "Direct form II".

# DenominatorAccumulatorDataType — accumulator data type

+ "Same word length as input" (by default)

Details

The data type of all accumulators in the filter, used when working with integer types and fixed-point numbers.

Dependencies

To use this property, set the [Property:Coefficient Source] value "Property".

# OutputDataType is the data type of the output signal

+ "Full precision" (by default)

Details

The data type of the output signal used when working with integer types and fixed-point numbers.

Methods

Common to all system objects

step!

Run the system object operation algorithm

release!

Allow changing the value of a system object property

reset!

Resetting the internal states of a system object

Additional Info

Filter Structures

Details

The diagrams below show the filter structures supported by a second-order sectional filter.

indirect form I

The figure shows a diagram of each section in the filter, if the filter structure is selected. Direct form I.

sosfilter 1

The figure shows the filter structure with sections when specifying scale factors .

sosfilter 3

The figure shows the filter structure if no scaling factors are specified.

sosfilter 5

The direct form of I is transposed

The figure shows a diagram of each section in the filter, if the filter structure is selected. Direct form I transposed.

sosfilter 7

The figure shows the filter structure with sections when specifying scale factors .

sosfilter 3

The figure shows the filter structure if no scaling factors are specified.

sosfilter 5

indirect form II

The figure shows a diagram of each section in the filter, if the filter structure is selected. Direct form II.

sosfilter 9

The figure shows the filter structure with sections when specifying scale factors .

sosfilter 3

The figure shows the filter structure if no scaling factors are specified.

sosfilter 5

Direct form II transposed_

The figure shows a diagram of each section in the filter, if the filter structure is selected. Direct form II transposed.

sosfilter 11

The figure shows the filter structure with sections when specifying scale factors .

sosfilter 3 The figure shows the filter structure if no scaling factors are specified.

sosfilter 5

Fixed-point filter structures

Details

The diagrams show the data types used in a second-order section-based filter when fixed-point data is fed to the input. For each structure supported by the filter, the data types shown in the diagrams can be set via the appropriate settings.

indirect form I

The figure shows a diagram of each section in the filter, if the filter structure is selected. Direct form I. The diagram shows the data types when applying fixed-point signals. Reinforcement operations , , , and they are performed with complete accuracy.

sosfilter 2

These diagrams show the fixed-point data types between the filter sections.

  • When the data is not optimized.

    sosfilter 4

  • When the scale factor is set to 1.

    sosfilter 6

The direct form of I is transposed

The figure shows a diagram of each section in the filter, if the filter structure is selected. Direct form I transposed. This diagram shows the data types when entering fixed-point signals. If for a property HasScaleValues value set false, there are no dotted casts. Reinforcement operations , , , and they are performed with complete accuracy.

sosfilter 8

These diagrams show the fixed-point data types between the filter sections.

  • When the data is not optimized.

    sosfilter 4

  • When the scale factor is set to 1.

    sosfilter 6

indirect form II

The figure shows a diagram of each section in the filter, if the filter structure is selected. Direct form II. This diagram shows the data types when entering fixed-point signals. If for a property HasScaleValues value set false, then the operation Cast absent. Reinforcement operations , , , and they are performed with complete accuracy.

sosfilter 10

These diagrams show the fixed-point data types between the filter sections.

  • When the data is not optimized.

    sosfilter 4

  • When the scale factor is set to 1.

    sosfilter 6

Direct form II transposed_

The figure shows a diagram of each section in the filter, if the filter structure is selected. Direct form II transposed. The diagram shows the data types when entering fixed-point signals. Reinforcement operations , , , and they are performed with complete accuracy. If for a property HasScaleValues value set false, the data type at the section output is automatically determined by the object’s algorithm and does not depend on the value of the SectionOutputDataType.

sosfilter 12

These diagrams show the fixed-point data types between the filter sections.

  • When the data is not optimized.

    sosfilter 4

  • When the scale factor is set to 1.

    sosfilter 6