iir filter using biquadratic structures -pg电子麻将胡了
iir filter using biquadratic structures
description
the dsp.biquadfilter object implements a cascade of biquadratic
sections, where the coefficients for each section are supplied by a separate row of an
n-by-6 second-order sections (sos) matrix. each row of the sos
matrix contains the numerator and denominator coefficients of the corresponding section
of the filter. the resulting filter can be applied to a vector or matrix input, where
each column represents a channel of data that is processed independently.
to implement an iir filter structure using biquadratic or sos:
create the
dsp.biquadfilterobject 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
syntax
description
returns a
biquadratic iir (sos) filter system object™, biquad = dsp.biquadfilterbiquad, which independently filters each
channel (column) of the input over time using the sos section [1 0.3
0.4 1 0.1 0.2] with a direct-form ii transposed structure.
biquad = dsp.biquadfilter(sosmatrix,scalevalues) returns
a biquadratic filter object, with the sosmatrix property
set to sosmatrix and the scalevalues
property set to scalevalues.
biquad = dsp.biquadfilter(
returns a biquadratic filter object, name,value)biquad, with each
property set to the specified value.
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 function unlocks them.
if a property is tunable, you can change its value at any time.
for more information on changing property values, see .
structure — filter structure
'direct form ii transposed' (default) | 'direct form i' | 'direct form i transposed' | 'direct form ii'
specify the filter structure as 'direct form i',
'direct form i transposed', 'direct form
ii', 'direct form ii transposed'.
sosmatrixsource — sos matrix source
'property' (default) | 'input port'
specify the source of the sos matrix as 'property' or
'input port'.
sosmatrix — sos matrix
[1 0.3 0.4 1 0.1 0.2] (default) | n-by-6 matrix
specify the second-order section (sos) matrix as an n-by-6 matrix, where n is the number of sections in the filter. each row of the sos matrix contains the numerator and denominator coefficients of the corresponding section of the filter. the system function, h(z), of a biquad filter is:
the coefficients are ordered in the rows of the sos
matrix as (b0,
b1,b2,1,
–a1,
–a2). you can use coefficients of real or complex values. this
property applies only when you set the sosmatrixsource
property to property. the leading denominator coefficient
of the biquad filter, a0, equals 1 for each filter section, regardless of the
specified value.
data types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fi
scalevalues — scale values for each biquad section
1 (default) | scalar | vector
specify the scale values to apply before and after each section of a
biquad filter. scalevalues must be either
a scalar or a vector of length n 1, where
n is the number of sections. if you set this property
to a scalar, the scalar value is used as the gain value only before the
first filter section. the remaining gain values are set to
1. if you set this property to a vector of
n 1values, each value is used for a separate section
of the filter.
dependencies
this property applies only when you set the
sosmatrixsource property to
property.
data types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64
initialconditions — initial conditions for direct form ii structures
0 (default) | scalar | vector | matrix
specify the initial conditions of the filter states when the
structure property is one of | direct form
ii | direct form ii transposed |. the
number of states or delay elements (zeros and poles) in a direct-form ii
biquad filter equals twice the number of filter sections. you can specify
the initial conditions as a scalar, vector, or matrix.
when you specify a scalar value, the biquad filter initializes all delay elements in the filter to that value. when you specify a vector of length equal to the number of delay elements in the filter, each vector element specifies a unique initial condition for the corresponding delay element.
the biquad filter applies the same vector of initial conditions to each channel of the input signal. when you specify a vector of length equal to the product of the number of input channels and the number of delay elements in the filter, each element specifies a unique initial condition for the corresponding delay element in the corresponding channel. when you specify a matrix with the same number of rows as the number of delay elements in the filter, and one column for each channel of the input signal, each element specifies a unique initial condition for the corresponding delay element in the corresponding channel.
dependencies
this property applies only when you set the
structure property to one of direct
form ii or direct form ii
transposed.
data types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64
numeratorinitialconditions — initial conditions on zeros side
0 (default) | scalar | vector | matrix
specify the initial conditions of the filter states on the side of the filter structure with the zeros. the number of states or delay elements in the numerator of a direct-form i biquad filter equals twice the number of filter sections. you can specify the initial conditions as a scalar, vector, or matrix. when you specify a scalar, the biquad filter initializes all delay elements on the zeros side in the filter to that value. when you specify a vector of length equal to the number of delay elements on the zeros side in the filter, each vector element specifies a unique initial condition for the corresponding delay element on the zeros side.
the biquad filter applies the same vector of initial conditions to each channel of the input signal. when you specify a vector of length equal to the product of the number of input channels and the number of delay elements on the zeros side in the filter, each element specifies a unique initial condition for the corresponding delay element on the zeros side in the corresponding channel. when you specify a matrix with the same number of rows as the number of delay elements on the zeros side in the filter, and one column for each channel of the input signal, each element specifies a unique initial condition for the corresponding delay element on the zeros side in the corresponding channel.
dependencies
this property applies only when you set the
structure property to one of direct
form i or direct form i
transposed.
data types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64
denominatorinitialconditions — initial conditions on poles side
0 (default) | scalar | vector | matrix
specify the initial conditions of the filter states on the side of the filter structure with the poles. the number of denominator states, or delay elements, in a direct-form i (noncanonic) biquad filter equals twice the number of filter sections. you can specify the initial conditions as a scalar, vector, or matrix. when you specify a scalar, the biquad filter initializes all delay elements on the poles side of the filter to that value. when you specify a vector of length equal to the number of delay elements on the poles side in the filter, each vector element specifies a unique initial condition for the corresponding delay element on the poles side.
the object applies the same vector of initial conditions to each channel of the input signal. when you specify a vector of length equal to the product of the number of input channels and the number of delay elements on the poles side in the filter, each element specifies a unique initial condition for the corresponding delay element on the poles side in the corresponding channel. when you specify a matrix with the same number of rows as the number of delay elements on the poles side in the filter, and one column for each channel of the input signal, each element specifies a unique initial condition for the corresponding delay element on the poles side in the corresponding channel.
dependencies
this property only applies when you set the
structure property to one of direct
form i or direct form i
transposed.
data types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64
optimizeunityscalevalues — optimize unity scale values
true (default) | false
when this boolean property is set to true, the biquad
filter removes all unity scale gain computations. this reduces the number of
computations and increases the fixed-point accuracy.
dependencies
this property applies only when you set the
sosmatrixsource property to
property.
scalevaluesinputport — how to specify scale values
true (default) | false
select how to specify scale values. by default, this property is
true, and the scale values are specified via the
input port. when this property is false, all scale values
are 1.
dependencies
this property applies only when the
sosmatrixsource property is input
port.
fixed-point properties
roundingmethod — rounding method for fixed-point operations
floor (default) | ceiling | convergent | nearest | round | simplest | zero
specify the rounding method.
overflowaction — overflow action for fixed-point operations
wrap (default) | saturate
specify the overflow action as one of wrap or
saturate.
multiplicanddatatype — multiplicand word and fraction lengths
same as output (default) | custom
specify the multiplicand fixed-point data type as one of same
as output or custom.
dependencies
this property applies only when you set the
structure property to direct form
i transposed.
custommultiplicanddatatype — custom multiplicand word and fraction lengths
numerictype([],32,30) (default) | numerictype
specify the multiplicand fixed-point type as a scaled (fixed-point designer) object
with a signedness of
auto.
dependencies
this property applies only when you set the
multiplicanddatatype property to
custom.
sectioninputdatatype — section input word and fraction lengths
same as input (default) | custom
specify the section input fixed-point data type as either
same as input or
custom.
customsectioninputdatatype — custom section input word and fraction lengths
numerictype([],16,15) (default) | numerictype
specify the section input fixed-point type as a scaled (fixed-point designer) object
with a signedness of
auto.
dependencies
this property applies only when you set the
sectioninputdatatype property to
custom.
sectionoutputdatatype — section output word and fraction lengths
same as section input (default) | custom
specify the section output fixed-point data type as either
same as section input or
custom.
customsectionoutputdatatype — custom section output word and fraction lengths
numerictype([],16,15) (default) | numerictype
specify the section output fixed-point type as a signed, scaled
(fixed-point designer) object
with a signedness of
auto.
dependencies
this property applies only when you set the
sectionoutputdatatype property to
custom.
numeratorcoefficientsdatatype — numerator coefficients word and fraction lengths
same word length as input (default) | custom
specify the numerator coefficients fixed-point data type as
same word length as input or
custom. setting this property also sets the
denominatorcoefficientsdatatype and
scalevaluesdatatype properties to the same
value.
dependencies
this property applies only when you set the
sosmatrixsource property to
property.
customnumeratorcoefficientsdatatype — custom numerator coefficients word and fraction lengths
numerictype([],16,15) (default) | numerictype
specify the numerator coefficients fixed-point type as a (fixed-point designer) object
with a signedness of auto. the
word length of the
customnumeratorcoefficientsdatatype,
customdenominatorcoefficientsdatatype, and
customscalevaluesdatatype properties must be
the same.
dependencies
this property applies only when you set the
sosmatrixsource property to
property and the
numeratorcoefficientsdatatype property to
custom.
denominatorcoefficientsdatatype — denominator coefficients word and fraction lengths
same word length as input (default) | custom
specify the denominator coefficients fixed-point data type as
same word length as input or
custom. setting this property also sets the
numeratorcoefficientsdatatype and
scalevaluesdatatype properties to the same
value.
dependencies
this property applies only when you set the
sosmatrixsource property to
property.
customdenominatorcoefficientsdatatype — custom denominator coefficients word and fraction lengths
numerictype([],16,15) (default) | numerictype
specify the denominator coefficients fixed-point type as a (fixed-point designer) object
with a signedness of auto. the
customnumeratorcoefficientsdatatype,
customdenominatorcoefficientsdatatype, and
customscalevaluesdatatype properties must have
the same word lengths.
dependencies
this property applies only when you set the
sosmatrixsource property to
property and the
denominatorcoefficientsdatatype property to
custom.
scalevaluesdatatype — scale values word and fraction lengths
same word length as input (default) | custom
specify the scale values fixed-point data type as same word
length as input or custom. setting this
property also sets the
numeratorcoefficientsdatatype and
denominatorcoefficientsdatatype properties to
the same value.
dependencies
this property applies only when you set the
sosmatrixsource property to
property.
customscalevaluesdatatype — custom scale values word and fraction lengths
numerictype([],16,15) (default) | numerictype
specify the scale values fixed-point type as a (fixed-point designer) object
with a signedness of auto. the
customnumeratorcoefficientsdatatype,
customdenominatorcoefficientsdatatype, and
customscalevaluesdatatype properties must have
the same word lengths.
dependencies
this property applies only when you set the
sosmatrixsource property to
property and the
scalevaluesdatatype property to
custom.
numeratorproductdatatype — numerator product word and fraction lengths
same as input (default) | custom | full precision
specify the mode to determine the numerator product fixed-point data type as:
same as input(default) — the numerator product word and fraction lengths are same as that of the input.custom— enables thecustomnumeratorproductdatatypeproperty, which you can use to specify the custom numerator product data type. specify the data type as anumerictypeobject.full precision— use full-precision rules to specify the data type. these rules provide the most accurate fixed-point numerics. the rules prevent quantization from occurring within the object. bits are added, as needed, so that no roundoff or overflow occurs. for more information, see .
setting this property also sets the
denominatorproductdatatype property to the same
value.
customnumeratorproductdatatype — custom numerator product word and fraction lengths
numerictype([],32,30) (default) | numerictype
specify the product fixed-point type as a scaled (fixed-point designer) object
with a signedness of auto. the
customnumeratorproductdatatype and
customdenominatorproductdatatype properties
must have the same word lengths.
dependencies
this property applies only when you set the
numeratorproductdatatype property to
custom.
denominatorproductdatatype — denominator product word and fraction lengths
same as input (default) | custom | full precision
specify the mode to determine the denominator product fixed-point data type as:
same as input(default) — the denominator product word and fraction lengths are same as that of the input.custom— enables thecustomdenominatorproductdatatypeproperty, which you can use to specify the custom denominator product data type. specify the data type as anumerictypeobject.full precision— use full-precision rules to specify the data type. these rules provide the most accurate fixed-point numerics. the rules prevent quantization from occurring within the object. bits are added, as needed, so that no roundoff or overflow occurs. for more information, see .
setting this property also sets the
numeratorproductdatatype property to the same
value.
customdenominatorproductdatatype — custom denominator product word and fraction lengths
numerictype([],32,30) (default) | numerictype
specify the product fixed-point type as a scaled (fixed-point designer) object
with a signedness of auto. the
customnumeratorproductdatatype and
customdenominatorproductdatatype properties
must have the same word lengths.
dependencies
this property applies only when you set the
denominatorproductdatatype to
custom.
numeratoraccumulatordatatype — numerator accumulator word and fraction lengths
same as product (default) | same as input | custom
specify the numerator accumulator fixed-point data type as
same as input, same as
product, or custom. setting this property
also sets the denominatoraccumulatordatatype
property to the same value.
customnumeratoraccumulatordatatype — custom numerator accumulator word and fraction lengths
numerictype([],32,30) (default) | numerictype
specify the numerator accumulator fixed-point type as a scaled
(fixed-point designer) object
with a signedness of auto. the
customnumeratoraccumulatordatatype and
customdenominatoraccumulatordatatype properties
must have the same word lengths.
dependencies
this property applies only when you set the
numeratoraccumulatordatatype property to
custom.
denominatoraccumulatordatatype — denominator accumulator word and fraction lengths
same as product (default) | same as input | custom
specify the denominator accumulator fixed-point data type as
same as input, same as
product, or custom. setting this property
also sets the numeratoraccumulatordatatype property
to the same value.
customdenominatoraccumulatordatatype — custom denominator accumulator word and fraction lengths
numerictype([],32,30) (default) | numerictype
specify the denominator accumulator fixed-point type as a scaled
(fixed-point designer) object
with a signedness of auto. the
customnumeratoraccumulatordatatype and
customdenominatoraccumulatordatatype properties
must have the same word lengths.
dependencies
this property applies only when you set the
denominatoraccumulatordatatype property to
custom.
statedatatype — state word and fraction lengths
same as accumulator (default) | same as input | custom
specify the state fixed-point data type as same as
input, same as accumulator, or
custom.
dependencies
this property applies when you set the structure property to
direct form ii or direct form ii
transposed.
customstatedatatype — custom state word and fraction lengths
numerictype([],16,15) (default) | numerictype
specify the state fixed-point type as a scaled (fixed-point designer) object
with a signedness of
auto.
dependencies
this property applies only when you set the
statedatatype property to
custom.
numeratorstatedatatype — numerator state word and fraction lengths
same as accumulator (default) | same as input | custom
specify the numerator state fixed-point data type as same as
input, same as accumulator, or
custom. setting this property also sets the
denominatorstatedatatype property to the same
value.
dependencies
this property applies only when you set the structure property to
direct form i transposed.
customnumeratorstatedatatype — custom numerator state word and fraction lengths
numerictype([],16,15) (default) | numerictype
specify the numerator state fixed-point type as a scaled (fixed-point designer) object
with a signedness of auto. the
customnumeratorproductdatatype and
customdenominatorproductdatatype properties
must have the same word lengths.
dependencies
this property applies only when you set the
statedatatype property to
custom.
denominatorstatedatatype — denominator state word and fraction lengths
same as accumulator (default) | same as input | custom
specify the denominator state fixed-point data type as same
as input, same as accumulator, or
custom. setting this property also sets the
numeratorstatedatatype property to the same
value.
dependencies
this property applies only when you set the structure property to
direct form i transposed.
customdenominatorstatedatatype — custom denominator state word and fraction lengths
numerictype([],16,15) (default) | numerictype
specify the denominator state fixed-point type as a scaled (fixed-point designer) object
with a signedness of auto. the
customnumeratorstatedatatype and
customdenominatorstatedatatype properties must
have the same word lengths.
dependencies
this property applies only when you set the
statedatatype property to
custom.
outputdatatype — output word and fraction lengths
same as accumulator (default) | same as input | custom
specify the output fixed-point data type as same as
input, same as accumulator, or
custom.
customoutputdatatype — custom output word and fraction lengths
numerictype([],16,15) (default) | numerictype
specify the output fixed-point type as a scaled (fixed-point designer) object
with a signedness of
auto.
dependencies
this property applies only when you set the outputdatatype property to
custom.
usage
description
input arguments
x — data input
vector | matrix
data input, specified as a vector or a matrix. this object also accepts variable-size inputs. once the object is locked, you can change the size of each input channel, but you cannot change the number of channels.
the data type of all the inputs must be the same. if the input is fixed-point, it must be signed fixed point with power-of-two slope and zero bias.
the complexity of x, num,
and den must be the same.
data types: single | double | int8 | int16 | int32 | int64 | fi
complex number support: yes
num — numerator coefficients
3-by-n matrix
numerator coefficients, specified as a 3-by-n
numeric matrix, where n is the number of biquad
filter sections. the complexity of x,
num, and den must be the
same.
the data type of all the inputs must be the same. if
num is fixed point, it must be signed fixed
point with power-of-two slope and zero bias.
dependencies
this input applies only when you set sosmatrixsource property is input
port.
data types: single | double | int8 | int16 | int32 | int64 | fi
complex number support: yes
den — denominator coefficients
2-by-n matrix
denominator coefficients, specified as a 2-by-n numeric matrix, where n is the number of biquad filter sections. the object assumes that the first denominator coefficient of each section is 1.
the data type of all the inputs must be the same. if
den is fixed point, it must be signed fixed
point with power-of-two slope and zero bias.
the complexity of x, num,
and den must be the same.
dependencies
this input applies only when you set sosmatrixsource property is input
port.
data types: single | double | int8 | int16 | int32 | int64 | fi
complex number support: yes
g — scale values
1-by-(n 1) vector
scale values of the biquad filter, specified as a 1-by-(n
1) numeric vector, where n is the number
of biquad filter sections.
the data type of all the inputs must be the same. if
g is fixed point, it must be signed fixed point
with power-of-two slope and zero bias.
dependencies
this input applies when the sosmatrixsource property is input
port and the scalevaluesinputport
property is true.
data types: single | double | int8 | int16 | int32 | int64 | fi
output arguments
y — filtered output
vector | matrix
filtered output, returned as a vector or a matrix. the size, data type, and complexity of the output signal matches that of the input signal.
data types: single | double | int8 | int16 | int32 | int64 | fi
complex number support: yes
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 dsp.biquadfilter
| frequency response of discrete-time filter system object | |
| visualize frequency response of dsp filters | |
| impulse response of discrete-time filter system object | |
| information about filter system object | |
| returns the filter system object coefficients in a structure | |
| estimate cost of implementing filter system object | |
| scale second-order sections | |
| create an options object for second-order section scaling | |
| check scaling of biquadratic filter | |
| cumulative second-order section of the biquadratic filter | |
| generate hdl code for quantized dsp filter (requires filter design hdl coder) | |
| convert discrete-time filter system object to transfer function | |
| reorder second-order sections of biquadratic filter system object |
common to all system objects
| run system object algorithm | |
| release resources and allow changes to system object property values and input characteristics | |
| reset internal states of system object |
examples
filter a signal using biquadratic filter
use a fourth order, lowpass biquadratic filter object with a normalized cutoff frequency of 0.4 to filter high frequencies from an input signal. display the result as a power spectrum using the spectrum analyzer.
t = (0:1000)'/8e3; xin = sin(2*pi*0.3e3*t) sin(2*pi*3e3*t); % input is 0.3 & % 3khz sinusoids src = dsp.signalsource(xin, 100); sink = dsp.signalsink; [z,p,k] = ellip(4,1,60,.4); % set up the filter [sosmatrix,scalevalues] = zp2sos(z,p,k); biquad = dsp.biquadfilter(sosmatrix,scalevalues,structure="direct form i"); sa = spectrumanalyzer(samplerate=8e3,... method="welch",... plotastwosidedspectrum=false,... overlappercent=80,spectrumunits="dbw",... ylimits=[-160 -10]); while ~isdone(src) input = src(); filteredoutput = biquad(input); sink(filteredoutput); sa(filteredoutput) end

filteredresult = sink.buffer; fvtool(biquad,fs=8000)

linf-norm scaling of a biquadratic sos filter
demonstrate the linf-norm scaling of a biquadratic sos filter using the scale function.
fs = 8000; fcutoff = 2000; [z,p,k] = butter(10,fcutoff/(fs/2)); [sosmatrix,scalevalues] = zp2sos(z,p,k); sosfilt = dsp.sosfilter(structure='direct form i', ... numerator=sosmatrix(:,1:3),denominator=sosmatrix(:,4:6), ... hasscalevalues=true,scalevalues=scalevalues)
sosfilt =
dsp.sosfilter with properties:
structure: 'direct form i'
coefficientsource: 'property'
numerator: [5x3 double]
denominator: [5x3 double]
hasscalevalues: true
scalevalues: [0.0029 1 1 1 1 1]
show all properties
scale(sosfilt,'linf',scalevalueconstraint='none',maxscalevalue=2)
more about
fixed point
the following diagrams show the data types used in the dsp.biquadfilter object when the input is fixed-point. for each
filter structure the object supports, the data types shown in the diagrams can be
set through the respective fixed-point properties of the object.
direct form i


the following diagram shows the data types for one section of the filter for fixed-point signals.

the following diagrams show the fixed-point data types between filter sections.
when the data is not optimized:

when you specify optimizeunityscalevalues to
true, and scale values to 1:

direct form i transposed


the following diagram shows the data types for one section of the filter for fixed-point signals.

the dashed casts are omitted when you specify
optimizeunityscalevalues to true, and
scale values to 1.
the following diagrams show the fixed-point data types between filter sections.
when the data is not optimized:

when you specify optimizeunityscalevalues to
true, and scale values to 1:

direct form ii


the following diagram shows the data types for one section of the filter for fixed-point signals.

the dashed casts are omitted when you specify
optimizeunityscalevalues to true, and
scale values to 1.
the following diagrams show the fixed-point data types between filter sections.
when the data is not optimized:

when you specify optimizeunityscalevalues to
true, and scale values to 1:

direct form ii transposed


the following diagram shows the data types for one section of the filter for fixed-point signals.

the following diagrams show the fixed-point data types between filter sections.
when the data is not optimized:

when you specify optimizeunityscalevalues to
true, and scale values to 1:

algorithms
this object implements the algorithm, inputs, and outputs described on the block reference page. the object properties correspond to the block parameters, except:
coefficient source
action when the a0 values of the sos matrix are not one – the biquad filter object assumes the zero-th-order denominator coefficient equals 1 regardless of the specified value. the biquad filter object does not support the
errororwarnoptions found in the corresponding block.
both this object and its corresponding block support variable-size input. when you call the object, it can handle an input argument which is changing in size.
extended capabilities
c/c code generation
generate c and c code using matlab® coder™.
usage notes and limitations:
see (matlab coder).
hdl code generation
generate verilog and vhdl code for fpga and asic designs using hdl coder™.
this object supports hdl code generation with the hdl coder™ or filter design hdl coder™ products. for hdl coder workflows and limitations, see (hdl coder). for filter design hdl coder workflows and limitations, see (filter design hdl coder).
version history
introduced in r2012a
see also
functions
- | | | | | | | | | | |
objects
- | |
blocks
topics
打开示例
您曾对此示例进行过修改。是否要打开带有您的编辑的示例?
matlab 命令
您点击的链接对应于以下 matlab 命令:
请在 matlab 命令行窗口中直接输入以执行命令。web 浏览器不支持 matlab 命令。
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.