main content

iir filter using biquadratic structures -凯发k8网页登录

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:

  1. create the dsp.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

biquad = dsp.biquadfilter returns a biquadratic iir (sos) filter system object™, biquad, 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.

example

biquad = dsp.biquadfilter(sosmatrix,scalevalues) returns a biquadratic filter object, with the sosmatrix property set to sosmatrix and the scalevalues property set to scalevalues.

example

biquad = dsp.biquadfilter(name,value) returns a biquadratic filter object, 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 .

specify the filter structure as 'direct form i', 'direct form i transposed', 'direct form ii', 'direct form ii transposed'.

specify the source of the sos matrix as 'property' or 'input port'.

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:

h(z)=k=02bkzk1l=12alzl

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

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

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

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

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

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.

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

specify the rounding method.

specify the overflow action as one of wrap or saturate.

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.

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.

specify the section input fixed-point data type as either same as input or custom.

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.

specify the section output fixed-point data type as either same as section input or custom.

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.

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.

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.

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.

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.

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.

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.

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 the customnumeratorproductdatatype property, which you can use to specify the custom numerator product data type. specify the data type as a numerictype object.

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

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.

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 the customdenominatorproductdatatype property, which you can use to specify the custom denominator product data type. specify the data type as a numerictype object.

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

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

specify the output fixed-point data type as same as input, same as accumulator, or custom.

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

example

y = biquad(x) filters the input signal x , and outputs the filtered values, y. the biquad filter object filters each channel of the input signal over successive calls to the algorithm.

y = biquad(x,num,den) filters the input using num as the numerator coefficients, and den as the denominator coefficients of the biquad filter. this configuration applies when the sosmatrixsource property is input port and the scalevaluesinputport property is false.

y = biquad(x,num,den,g) specifies the scale values, g, of the biquad filter. this configuration applies when the sosmatrixsource property is input port and the scalevaluesinputport property is true.

input arguments

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

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

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

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

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)
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
run system object algorithm
release resources and allow changes to system object property values and input characteristics
reset internal states of system object

examples

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)

figure figure 1: magnitude response (db) contains an axes object. the axes object with title magnitude response (db), xlabel frequency (khz), ylabel magnitude (db) contains an object of type line.

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

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 error or warn options 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

version history

introduced in r2012a

see also

functions

  • | | | | | | | | | | |

objects

  • | |

blocks

topics

    网站地图