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 UI 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.
The following IIR filter types support programmable filter coefficients:
Second-order section (SOS) infinite impulse response (IIR) Direct Form I
SOS IIR Direct Form I transposed
SOS IIR Direct Form II
SOS IIR Direct Form II transposed
Limitations
Programmable filter coefficients are supported for IIR filters with fully parallel architectures only.
The generated interface assumes that the coefficients are stored in a register file.
When you generate a processor interface for an IIR filter, the
OptimizeScaleValues
property must be between 1
and 0
. For
example:
filt.OptimizeScaleValues = 0
fvtool
and filter
, commands. Disabling
filt.OptimizeScaleValues
may add quantization at section inputs and
outputs.You can also generate a processor interface for loading FIR filter coefficients.Specifying Memory for Programmable Coefficients for further information.
You can specify a processor interface using the Coefficient source menu on the Generate HDL dialog box.
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
.
The Coefficient stimulus option on the Test Bench pane of the Generate HDL dialog box specifies how the test bench tests the generated memory interface.
The corresponding command-line property is TestBenchCoeffStimulus
.
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, the 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.
The TestbenchCoeffStimulus
specified the source of coefficients used
for the test bench. The valid values for TestbenchCoeffStimulus
are:
[]
: Empty vector. (default)
When the value of TestbenchCoeffStimulus
is an empty vector, the
test bench loads the coefficients from the filter object, and then forces the input
stimuli. This test 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_filt.ScaleValues
: column vector of scale values for the
IIR filter
New_filt.sosMatrix
: second-order section (SOS) matrix for the
IIR filter
You can specify the elements of the cell array in the following forms:
{New_filt.ScaleValues,New_filt.sosMatrix}
{New_filt.ScaleValues;New_filt.sosMatrix}
{New_filt.sosMatrix,New_filt.ScaleValues}
{New_filt.sosMatrix;New_filt.ScaleValues}
{New_filt.ScaleValues}
{New_filt.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 processes the same
input stimuli again. 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_filt.ScaleValues
, the test bench uses the scale
values loaded from the filter object twice. Likewise, if you omit
New_filt.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 the different types of coefficients (scale values, numerator
coefficients, and denominator coefficients) to be loaded via a single port
(coeffs_in
).
Each type of coefficient has the same word length, but can 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 three bits.
The total width of the write_address
port is therefore
ceil(log2N) + 3
bits.
Section Address | Coefficient Address | Description |
---|---|---|
S S ... S | 000 | Section scale value |
S S ... S | 001 | Numerator coefficient: b1 |
S S ... S | 010 | Numerator coefficient: b2 |
S S ... S | 011 | Numerator coefficient: b3 |
S S ... S | 100 | Denominator coefficient: a2 |
S S ... S | 101 | Denominator coefficient: a3 (if order = 2; otherwise
unused) |
S S ... S | 110 | Unused |
0 0 ... 0 | 111 | Last scale value |