| Contents | Index |
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:
Generate an interface for loading coefficients from memory. Coefficients stored in memory are called programmable coefficients.
Test the interface.
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.
Note You can also generate a processor interface for loading FIR filter coefficients.Specifying Memory for Programmable Coefficients for further information. |
The following IIR filter types support programmable filter coefficients:
Second-order section (SOS) infinite impulse response (IIR) Direct Form I (dfilt.df1sos )
SOS IIR Direct Form I transposed (dfilt.df1tsos)
SOS IIR Direct Form II (dfilt.df2sos)
SOS IIR Direct Form II transposed (dfilt.df2tsos)
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:
'Internal': (Default) Do not generate a processor interface. Coefficients are obtained from the filter object and hard-coded.
'ProcessorInterface': Generate a processor interface for coefficients.
When you specify 'ProcessorInterface', the generated entity or module definition for the filter includes the following port definitions:
coeffs_in: Input port for coefficient data
write_address: Write address for coefficient memory (See also Addressing Scheme for Loading IIR Coefficients.)
write_enable: Write enable signal for coefficient memory
write_done: Signal to indicate completion of coefficient write operation
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;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.
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:
[] : Empty vector.
This is the default. When the value of TestbenchCoeffStimulus is unspecified (or set to the default value of []) the test bench loads the coefficients from the filter object and then forces the input stimuli. This shows the response to the input stimuli and verifies that the interface writes one set of coefficients into the memory without encountering an error.
A cell array containing the following elements:
New_Hd.ScaleValues: column vector of scale values for the IIR filter
New_Hd.sosMatrix: second-order section (SOS) matrix for the IIR filter
You can specify the elements of the cell array in any of the following forms:
{New_Hd.ScaleValues , New_Hd.sosMatrix}
{New_Hd.ScaleValues ; New_Hd.sosMatrix}
{New_Hd.sosMatrix , New_Hd.ScaleValues}
{New_Hd.sosMatrix ; New_Hd.ScaleValues}
{New_Hd.ScaleValues}
{New_Hd.sosMatrix}
In this case, the filter processes the input stimuli twice. First, the test bench loads the coefficients from the filter object and forces the input stimuli to show the response. Then, the filter loads the set of coefficients specified in the TestbenchCoeffStimulus cell array, and shows the response by processing the same input stimuli for a second time. In this case, the internal states of the filter, as set by the first run of the input stimulus, are retained. The test bench verifies that the interface writes two different sets of coefficients into the register file. The test bench also provides an example of how the memory interface can be used to program the filter with different sets of coefficients.
If you omit New_Hd.ScaleValues, the test bench uses the scale values loaded from the filter object twice. Likewise, if you omit New_Hd.sosMatrix, the test bench uses the SOS matrix loaded from the filter object twice.
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:
Section address: Width is ceil(log2N) bits, where N is the number of sections.
Coefficient address : Width is 3 bits
The total width of the write_address port is therefore ceil(log2N) + 3bits.
| Section Address | Coefficient Address | Description |
|---|---|---|
| S S ... S | 000 | Section scale value |
| S S ... S | 001 | Numerator coefficient: b1 |
| S S ... S | 011 | Numerator coefficient: b2 |
| S S ... S | 100 | Numerator coefficient: b3 |
| S S ... S | 101 | Denominator coefficient: a2 |
| S S ... S | 110 | Denominator coefficient: a3 (if order = 2; otherwise unused) |
| S S ... S | 110 | Unused |
| 0 0 ... 0 | 111 | Last scale value |
The following GUI options let you specify programmable coefficients:
The Coefficient source list on the Generate HDL dialog box lets you select whether coefficients are obtained from the filter object and hard-coded (Internal), or from memory (Processor interface). The default is Internal.
The corresponding command-line property is CoefficientSource (see Generating a Port Interface for Programmable IIR Filter Coefficients).

The Coefficient stimulus option on the Test Bench pane of the Generate HDL dialog box lets you lets specify how the test bench tests the generated memory interface.
The corresponding command-line property is TestbenchCoeffStimulus (see Generating a Test Bench for Programmable IIR Coefficients).

![]() | Programmable Filter Coefficients for FIR Filters | Digital Down Converter (DDC) and Digital Up Converter (DUC) System Objects | ![]() |

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 |