Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

dsp.HDLFIRFilter System object

Finite impulse response filter—optimized for HDL code generation

Description

The dsp.HDLFIRFilter System object™ models FIR filter architectures optimized for HDL code generation. The object is sample based, accepting one scalar at a time. It provides a hardware-friendly interface with optional input and output flow control signals.

The object implements a direct-form systolic FIR filter architecture based on multiply-accumulate operations with pipeline registers. The choice of architecture makes the object well-suited for high-throughput HDL code generation targeted for FPGAs with dedicated DSP blocks. The generated HDL code runs at a high clock rate and can filter new input data on every cycle.

The object provides flexible and efficient resource sharing options. This property results in tradeoffs between throughput and resource utilization. A sharing factor of N indicates that the object reduces overall DSP resource utilization by a factor of N. In this case, the object can process an input sample only every N calls to the object. To determine when the object is ready for new input data, use the optional readyPort property.

To provide a cycle-accurate simulation of the generated HDL code, the object models pipeline registers and resource sharing. These operations cause a delay between valid input data and the corresponding valid output data. The actual latency depends on the number of coefficients and the sharing factor.

To filter input data with an HDL-optimized FIR filter:

  1. Create the dsp.HDLFIRFilter 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? (MATLAB).

Creation

Syntax

firFilt = dsp.HDLFIRFilter
firFilt = dsp.HDLFIRFilter(num)
firFilt = dsp.HDLFIRFilter(___,Name,Value)

Description

firFilt = dsp.HDLFIRFilter creates an HDL-optimized discrete FIR filter System object, firFilt, with default filter properties.

firFilt = dsp.HDLFIRFilter(num) creates the filter with the Numerator property set to num.

firFilt = dsp.HDLFIRFilter(___,Name,Value) creates the filter with properties set using one or more name-value pairs. Enclose each property name in single quotes.

For example:

Numerator = firpm(10,[0,0.1,0.5,1],[1,1,0,0]);
fir = dsp.HDLFIRFilter(Numerator,'ValidInPort',false);
...
[dataOut,validOut] = fir(dataIn); ;

Properties

expand all

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 (MATLAB).

Main

Discrete FIR filter coefficients, specified as a vector of numeric values. You can also specify the vector as a workspace variable, or as a call to a filter design function. Complex coefficients are not supported. When the input data type is floating point, the object casts the coefficients to the same data type as the input. When the input data type is integer or fixed point, you can modify coefficient type casting details using the CoefficientsDataType property.

Example: 'Numerator',firpm(30,[0 0.1 0.2 0.5]*2,[1 1 0 0]) defines the coefficients using a linear-phase filter design function.

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

Resource sharing option, specified false or true. To reduce the overall DSP resource utilization on the FPGA, set this property to true. Then set the SharingFactor property to the value by which you want to reduce the number of DSPs.

Factor by which the number of DSPs is reduced, specified as a positive integer. A sharing factor of N indicates that the object reduces DSP resource utilization by a factor of N. In this case, the object can process an input sample only every N calls to the object.

Dependencies

To enable this property, set the Sharing property to true.

Data Types

Rounding method for type casting, specified as 'Floor', 'Ceiling', 'Convergent', 'Nearest', 'Round', or 'Zero'. The rounding method is used when casting the output to the data type specified by the OutputDataType property. When the input data type is floating point, the RoundingMethod property has no effect. See Rounding Modes for more details.

Overflow handling for type casting, specified as 'Wrap' or 'Saturate'. Overflow handling is used when casting the output to the data type specified by the OutputDataType property. When the input data type is floating point, the OverflowAction property has no effect. See Overflow Handling for more details.

Data type of discrete FIR filter coefficients, specified as 'Same word length as input', or as a numerictype object. To specify the 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 filter coefficients of the discrete FIR filter to the specified data type. The quantization uses nearest rounding and saturate overflow modes. When the input data type is floating point, the Coefficients property has no effect.

Data type of discrete FIR filter output, specified as 'Same word length as input', 'Full precision', or as a numerictype object. To specify the 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 output of the discrete FIR filter to the specified data type. The quantization uses the settings of RoundingMethod and OverflowAction. When the input data type is floating point, the OutputDataType property has no effect.

Control Ports

Enable optional valid input control signal, specified as true or false. When ValidInPort is true, you must call the object with an extra argument, validIn. The first argument of the object, dataIn, is treated as valid only when validIn is true. The extra argument is mandatory when DSP resources are shared. In this case, the object ignores the value of ValidInPort.

Enable optional ready output control signal, specified as true or false. When ReadyPort is true, the object returns an extra value, ready. The object sets ready to true to indicate that it is ready to accept new input data on the next call.

Usage

Syntax

[dataOut,validOut] = firFilt(dataIn)
[dataOut,validOut] = firFilt(dataIn,validIn)
[dataOut,validOut,ready] = firFilt(dataIn,validIn)

Description

[dataOut,validOut] = firFilt(dataIn) filters the input data, dataIn, using the specified firFilt filter object. The returned output data, dataOut, is valid only when validOut is true.

[dataOut,validOut] = firFilt(dataIn,validIn) filters the input data only when validIn is true.

Use this syntax when the ValidInPort or the Sharing property is true. When you set Sharing to true, the object forces ValidInPort to true. For example:

firFilt = dsp.FIRHDLFilter(Numerator,'Sharing',true,'SharingFactor',10);
...
for k=1:length(dataIn)
    [dataOut,validOut] = firFilt(dataIn(k),validIn(k));

example

[dataOut,validOut,ready] = firFilt(dataIn,validIn) returns ready set to true when the object is ready to accept new input data on the next call.

To return ready, set the ReadyPort property to true. For example:

firFilt = dsp.FIRHDLFilter(Numerator,'Sharing',true, ...
            'SharingFactor',10,'ReadyPort',true)
...
for k=1:length(dataIn)
    [dataOut,validOut,ready] = firFilt(dataIn(k),validIn(k));

Input Arguments

expand all

Input data, specified as a real or complex scalar. When the input data type is integer or fixed point, the object uses fixed-point arithmetic for internal calculations. double and single are accepted for simulation but not for HDL code generation.

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

Validity of the input data, specified as a logical scalar. The first argument, dataIn, is treated as valid only when validIn is 1 (true). validIn is required when Sharing is set to true. Otherwise, it is required only when ValidInPort property is set to true.

Data Types: logical

Output Arguments

expand all

Filtered output data, returned as a real or complex scalar. When the input data is floating point, the output data inherits the data type of the input data. When the input data is integer or fixed point, the OutputDataType property determines the output data type.

Data Types: fi | single | double
Complex Number Support: Yes

Validity of the output data, returned as a logical scalar. The object sets validOut to 1 (true) with each valid output data on dataOut.

Data Types: logical

Indicator of whether the object is ready for new input data, returned as a logical scalar. The object sets ready to true to indicate that it is ready to accept new input data on the next call. The object returns this value only when the ReadyPort property is set to true.

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)
stepRun System object algorithm
cloneCreate duplicate System object
getNumInputsNumber of inputs required to call the System object
getNumOutputsNumber of outputs from calling the System object
isLockedDetermine if System object is locked
releaseRelease resources and allow changes to System object property values and input characteristics
resetReset internal states of System object

Examples

expand all

Create an HDL FIR filter System object with default settings.

firFilt = dsp.HDLFIRFilter;

Create an input signal of some random noise, and allocate memory for outputs.

L = 100;
dataIn = randn(L,1);
dataOut = zeros(L,1);
validOut = false(L,1);

Call the object on the input signal, asserting that the input data is always valid. The object processes one data sample at a time.

for k=1:L
    [dataOut(k),validOut(k)] = firFilt(dataIn(k),true);
end

Operate a 31-tap lowpass filter with resource sharing.

Design the filter coefficients. Then create an HDL FIR filter System object. Enable resource sharing and the ready output port.

numerator = firpm(30,[0 0.1 0.2 0.5]*2,[1 1 0 0]);
sharingFactor = 10;
firFilt = dsp.HDLFIRFilter('Numerator',numerator, ...
    'Sharing',true,'SharingFactor',sharingFactor,'ReadyPort',true);

The specified sharingFactor indicates that the filter requires 10 time steps to calculate each output. Create input signals dataIn and validIn such that new data is applied only every sharingFactor time steps.

L = 16;
x = fi(randn(L,1),1,16);
dataIn = zeros(L*sharingFactor,1,'like',x);
dataIn(1:sharingFactor:end) = x;
validIn = false(L*sharingFactor,1);
validIn(1:sharingFactor:end) = true;

Create a LogicAnalyzer object to view the inputs and outputs

la = dsp.LogicAnalyzer('NumInputPorts',5, ...
    'SampleTime',1,'TimeSpan',length(dataIn));
tags = getDisplayChannelTags(la);
modifyDisplayChannel(la,tags{1},'Name','dataIn');
modifyDisplayChannel(la,tags{2},'Name','validIn');
modifyDisplayChannel(la,tags{3},'Name','dataOut');
modifyDisplayChannel(la,tags{4},'Name','validOut');
modifyDisplayChannel(la,tags{5},'Name','ready');

Call the filter System object on the input signals, and view the results in the Logic Analyzer.

for k=1:length(dataIn)
    [dataOut,validOut,ready] = firFilt(dataIn(k),validIn(k));
    la(dataIn(k),validIn(k),dataOut,validOut,ready)
end

The object models HDL pipeline registers and resource sharing. Therefore, there is an initial delay before the object returns valid output samples.

To generate HDL code from a System object™, create a function that contains and calls the object.

Create Function

Write a function that creates and calls an 11-tap HDL FIR filter System object. You can generate HDL from this function.

function [dataOut,validOut] = HDLFIR11Tap(dataIn)
%HDLFIR11Tap
% Process one sample of data using the dsp.HDLFIRFilter System
% object. 
% dataIn is a fixed-point scalar value. 
% You can generate HDL code from this function.
    persistent fir
    if isempty(fir)
        Numerator = firpm(10,[0 0.1 0.5 1],[1 1 0 0]);
        fir = dsp.HDLFIRFilter(Numerator,'ValidInPort',false);
    end
    [dataOut,validOut] = fir(dataIn);    
end


Create Test Bench for Function

Clear the workspace, create an input signal of some random noise, and allocate memory for outputs.

clear variables
clear HDLFIR11Tap
L = 200;
dataIn = fi(randn(L,1),1,16);
dataOut = zeros(L,1);
validOut = false(L,1);

Call the function on the input signal.

for k = 1:L
    [dataOut(k),validOut(k)] = HDLFIR11Tap(dataIn(k));
end

Plot the signals with the Logic Analyzer.

la = dsp.LogicAnalyzer('NumInputPorts',3,'SampleTime',1,'TimeSpan',L);
tags = getDisplayChannelTags(la);
modifyDisplayChannel(la,tags{1},'Name','dataIn','Format','Analog','Height',50);
modifyDisplayChannel(la,tags{2},'Name','dataOut','Format','Analog','Height',50);
modifyDisplayChannel(la,tags{3},'Name','validOut');
la(dataIn,dataOut,validOut)

Algorithms

This object implements the algorithms described on the Discrete FIR Filter HDL Optimized block reference page.

Introduced in R2017a

Was this topic helpful?