Main Content

dsp.FIRFilter

年代tatic or time-varying FIR filter

描述

Thedsp.FIRFilter年代ystem object™ filters each channel of the input using static or time-varying FIR filter implementations.

To filter each channel of the input:

  1. Create thedsp.FIRFilterobject and set its properties.

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

To learn more about how System objects work, seeWhat Are System Objects?

Under specific conditions, this System object also supports SIMD code generation. For details, seeCode Generation.

Creation

描述

fir= dsp.FIRFilterreturns a finite impulse response (FIR) filter object,fir, which independently filters each channel of the input over time using a specified FIR filter implementation.

example

fir= dsp.FIRFilter(num)returns an FIR filter System object,fir, with theNumeratorproperty set tonum.

fir= dsp.FIRFilter(Name,Value)returns an FIR filter System object,fir, with each property set to the specified value.

Properties

expand all

Unless otherwise indicated, properties arenontunable, which means you cannot change their values after calling the object. Objects lock when you call them, and thereleasefunction unlocks them.

If a property istunable, you can change its value at any time.

For more information on changing property values, see年代ystem Design in MATLAB Using System Objects.

年代pecify the filter structure. You can specify the filter structure as one ofDirect form|Direct form symmetric|Direct form antisymmetric|Direct form transposed|Lattice MA.

年代pecify the source of the filter coefficients asPropertyorInput port. When you specifyInput port, the filter object updates the time-varying filter once every frame.

Dependencies

这applies when you set the年代tructuretoDirect form|Direct form symmetric|Direct form antisymmetric|Direct form transposed.

年代pecify the source of the Lattice filter coefficients asPropertyorInput port. When you specifyInput port, the filter object updates the time-varying filter once every frame.

Dependencies

这applies when you set the年代tructuretoLattice MA.

年代pecify the filter coefficients as a real or complex numeric row vector.

可调:Yes

Dependencies

这property applies when you set theNumeratorSourceproperty toProperty, and the年代tructureproperty is set toDirect form,Direct form symmetric,Direct form antisymmetric, orDirect form transposed.

Data Types:single|double|int8|int16|int32|int64|uint8|uint16|uint32|uint64
Complex Number Support:Yes

年代pecify the reflection coefficients of a lattice filter as a real or complex numeric row vector.

可调:Yes

Dependencies

这property applies when you set the年代tructureproperty toLattice MA, and theReflectionCoefficientsSourceproperty toProperty.

Data Types:single|double|int8|int16|int32|int64|uint8|uint16|uint32|uint64
Complex Number Support:Yes

年代pecify the initial conditions of the filter states. The number of states or delay elements equals the number of reflection coefficients for the lattice structure, or the number of filter coefficients–1 for the other direct form structures.

You can specify the initial conditions as a scalar, vector, or matrix. If you specify a scalar value, the FIR filter object initializes all delay elements in the filter to that value. If you specify a vector whose length equals the number of delay elements in the filter, each vector element specifies a unique initial condition for the corresponding delay element. The object applies the same vector of initial conditions to each channel of the input signal.

If you specify a vector whose length equals 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.

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

可调:Yes

Data Types:single|double|int8|int16|int32|int64|uint8|uint16|uint32|uint64

Fixed-Point Properties

年代pecify whether to use full precision rules. If you setFullPrecisionOverridetotrue, which is the default, the object computes all internal arithmetic and output data types using full precision rules. These rules provide the most accurate fixed-point numerics. It also turns off the display of other fixed-point properties because they do not apply individually. These rules guarantee that no quantization occurs within the object. Bits are added, as needed, to ensure that no roundoff or overflow occurs. If you setFullPrecisionOverridetofalse, fixed-point data types are controlled through individual fixed-point property settings. For more information, seeFull Precision for Fixed-Point System Objects.

年代pecify the rounding method.

Dependencies

这property applies only if the object is not in full precision mode.

年代pecify the overflow action asWrapor年代aturate.

Dependencies

这property applies only if the object is not in full precision mode.

年代pecify the coefficients fixed-point data type as年代ame word length as inputorCustom.

Dependencies

这property applies when you set theNumeratorSourceproperty toProperty.

年代pecify the coefficients fixed-point type as a signed or unsignednumerictype(Fixed-Point Designer)object.

Dependencies

这property applies when you set theCoefficientsDataTypeproperty toCustom.

年代pecify the reflection coefficients fixed-point data type as年代ame word length as inputorCustom.

Dependencies

这property applies when you set theReflectionCoefficientsSourceproperty toProperty.

年代pecify the reflection coefficients fixed-point type as a signed or unsignednumerictype(Fixed-Point Designer)object.

Dependencies

这property applies when you set theReflectionCoefficientsDataTypeproperty toCustom.

年代pecify the product fixed-point data type asFull precision,年代ame as input, orCustom.

年代pecify the product fixed-point type as a signed or unsigned scalednumerictype(Fixed-Point Designer)object.

Dependencies

这property applies when you set theProductDataTypeproperty toCustom.

年代pecify the accumulator fixed-point data type toFull precision,年代ame as input,年代ame as product, orCustom.

年代pecify the accumulator fixed-point type as a signed or unsigned scalednumerictype(Fixed-Point Designer)object.

Dependencies

这property applies when you set theAccumulatorDataTypeproperty toCustom.

年代pecify the state fixed-point data type as one of年代ame as input,年代ame as accumulator, orCustom.

Dependencies

这property does not apply to any of the direct form or direct form I filter structures.

年代pecify the state fixed-point type as a signed or unsigned scalednumerictype(Fixed-Point Designer)object.

Dependencies

这property applies when you set the年代tateDataTypeproperty toCustom.

年代pecify the output fixed-point data type as one of年代ame as input,年代ame as accumulator, orCustom.

年代pecify the output fixed-point type as a signed or unsigned scalednumerictype(Fixed-Point Designer)object.

Dependencies

这property applies when you set theOutputDataTypeproperty toCustom.

Usage

描述

example

y= fir(x)applies an FIR filter to the real or complex input signalxto produce the outputy.

y= fir(x,coeff)uses the time-varying coefficients,coeff, to filter the input signalxand produce the outputy. You can use this option when you set theNumeratorSourceorReflectionCoefficientsSourceproperty toInput port.

Input Arguments

expand all

Data input, specified as a vector or a matrix. When the input data is of a fixed-point type, it must be signed when the structure is set toDirect form symmetricorDirect form antisymmetric. The FIR filter object operates on each channel of the input signal independently over successive calls to the object.

这年代ystem object supports variable-size input.

Data Types:single|double|int8|int16|int32|uint8|uint16|uint32|fi
Complex Number Support:Yes

Time-varying filter coefficients, specified as a row vector. The data and coefficient inputs must have the same data type.

Data Types:single|double|int8|int16|int32|uint8|uint16|uint32|fi
Complex Number Support:Yes

Output Arguments

expand all

Filtered output, returned as a vector or a matrix. The output has the same size and data type as the input.

Data Types:single|double|int8|int16|int32|uint8|uint16|uint32|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 namedobj, use this syntax:

release(obj)

expand all

freqz Frequency response of discrete-time filter年代ystem object
fvtool Visualize frequency response of DSP filters
impz Impulse response of discrete-time filter年代ystem object
info Information about filter年代ystem object
coeffs Returns the filter年代ystem objectcoefficients in a structure
cost Estimate cost of implementing filter年代ystem object
grpdelay Group delay response of discrete-time filter年代ystem object
generatehdl Generate HDL code for quantized DSP filter (requiresFilter Design HDL Coder)
step Run年代ystem objectalgorithm
release Release resources and allow changes to年代ystem objectproperty values and input characteristics
reset Reset internal states of年代ystem object

Examples

collapse all

Use an FIR filter to apply a low pass filter to a waveform with two sinusoidal components.

t = (0:1000)'/8e3; xin = sin(2*pi*0.3e3*t)+sin(2*pi*3e3*t); sr = dsp.SignalSource; sr.Signal = xin; sink = dsp.SignalSink; fir = dsp.FIRFilter(fir1(10,0.5)); sa = spectrumAnalyzer(...'SampleRate',8e3,...'Method','welch',...'PlotAsTwoSidedSpectrum',false,...'OverlapPercent',80,...'SpectrumUnits','dBW',...'YLimits',[-150 -10]);while~isDone(sr) input = sr(); filteredOutput = fir(input); sink(filteredOutput); sa(filteredOutput)end

filteredResult = sink.Buffer; fvtool(fir,'Fs',8000)

Figure Magnitude Response (dB) contains an axes object. The axes object with title Magnitude Response (dB) contains an object of type line.

Design an FIR filter as a System object.

N = 10; Fc = 0.4; B = fir1(N,Fc); fir1 = dsp.FIRFilter(B); fvtool(fir1)

Figure Magnitude Response (dB) contains an axes object. The axes object with title Magnitude Response (dB) contains an object of type line.

这can also be achieved by usingfdesignas a constructor anddesignto design the filter.

N = 10; Fc = 0.4; specLowpass = fdesign.lowpass('N,Fc',...N,Fc); fir2 = design(specLowpass,...'systemobject',true)
fir2 = dsp.FIRFilter with properties: Structure: 'Direct form' NumeratorSource: 'Property' Numerator: [-1.2414e-18 -0.0126 -0.0247 0.0635 0.2748 0.3981 ... ] InitialConditions: 0 Show all properties
fvtool(fir2);

Figure Magnitude Response (dB) contains an axes object. The axes object with title Magnitude Response (dB) contains 2 objects of type line.

Algorithms

这object implements the algorithm, inputs, and outputs described on theDiscrete FIR Filter(Simulink)block reference page. The object properties correspond to the block parameters.

Extended Capabilities

Version History

Introduced in R2012a