Skip to Main Content Skip to Search
Product Documentation

Programmable Filter Coefficients for IIR Filters

About Programmable Filter Coefficients for IIR Filters

By default, the coder obtains filter coefficients from a filter object and hard-codes them into the generated code. An HDL filter realization generated in this way cannot be used with a different set of coefficients.

For IIR filters, the coder provides GUI options and corresponding command-line properties that let you:

To use programmable coefficients, a port interface (referred to as a processor interface) is generated for the filter entity or module. Coefficient loading is assumed to be under the control of a microprocessor that is external to the generated filter. The filter uses the loaded coefficients for processing input samples.

For IIR filters, the current release supports programmable coefficients that are stored in a register file.

Supported IIR Filter Types

The following IIR filter types support programmable filter coefficients:

Generating a Port Interface for Programmable IIR Filter Coefficients

This section describes how to use the CoefficientSource property to specify that a processor interface for loading coefficients is generated. You can also use the Coefficient source menu on the Generate HDL dialog box for this purpose.

The valid value strings for the property are:

When you specify 'ProcessorInterface', the generated entity or module definition for the filter includes the following port definitions:

Example

In the following command-line example, a processor interface is generated in VHDL code for an SOS IIR Direct Form II filter.

Fs = 48e3;             % Sampling frequency
Fc = 10.8e3;           % Cut-off frequency
N = 5;                 % Filter Order
f_lp = fdesign.lowpass('n,f3db',N,Fc,Fs);
Hd = design(f_lp,'butter','FilterStructure','df2sos');
Hd.arithmetic = 'fixed';
Hd.OptimizeScaleValues = 0; %** SEE NOTE ON LIMITATIONS FOLLOWING **
generatehdl(Hd, 'CoefficientSource', 'ProcessorInterface')

The following listing shows the VHDL entity definition generated for the filter object Hd.

ENTITY Hd IS
PORT( clk              :   IN    std_logic; 
      clk_enable       :   IN    std_logic; 
      reset            :   IN    std_logic; 
      filter_in        :   IN    std_logic_vector(15 DOWNTO 0); -- sfix16_En15
      write_enable     :   IN    std_logic; 
      write_done       :   IN    std_logic; 
      write_address    :   IN    std_logic_vector(4 DOWNTO 0); -- ufix5
      coeffs_in        :   IN    std_logic_vector(15 DOWNTO 0); -- sfix16
      filter_out       :   OUT   std_logic_vector(15 DOWNTO 0)  -- sfix16_En12
      );

END Hd;

Limitation

When you generate a processor interface for an IIR filter, you must set the value of the filter's OptimizeForScaleValue from 1 to 0. For example:

Hd.OptimizeScaleValues = 0;

You should then make sure the filter still has the desired response, using the fvtool and filter, commands. The disabling of Hd.OptimizeScaleValues may add quantization at section inputs and outputs.

Generating a Test Bench for Programmable IIR Coefficients

This section describes how to use the TestbenchCoeffStimulus property to specify how the test bench drives the coefficient ports. You can also use the Coefficient stimulus option for this purpose.

When a coefficient memory interface has been generated for a filter, all coefficient ports have associated test vectors. The TestbenchCoeffStimulus property determines how the test bench drives the coefficient ports.

The TestBenchStimulus property determines the filter input stimuli, as with any filter.

The TestbenchCoeffStimulus specified the source of coefficients used for the test bench. The valid values for TestbenchCoeffStimulus are:

Addressing Scheme for Loading IIR Coefficients

The following table gives the address generation scheme for the write_address port when loading IIR coefficients into memory. This addressing scheme allows all types of coefficients (scale values, numerator coefficients, and denominator coefficients) to be loaded via a single port (coeffs_in).

Note that all types of coefficients have the same word length, but may have different fractional lengths.

The address for each coefficient is divided into two fields:

The total width of the write_address port is therefore ceil(log2N) + 3bits.

Section AddressCoefficient Address Description
S S ... S000Section scale value
S S ... S001Numerator coefficient: b1
S S ... S011Numerator coefficient: b2
S S ... S100Numerator coefficient: b3
S S ... S101Denominator coefficient: a2
S S ... S110Denominator coefficient: a3 (if order = 2; otherwise unused)
S S ... S110Unused
0 0 ... 0111Last scale value

GUI Options for Programmable Coefficients

The following GUI options let you specify programmable coefficients:

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS