This application note shows how to determine the optimal size of operands in a DSP algorithm. Running examples using operands of type real, variable precision floating and fixed point operands are provided in the free FinSim evaluation.

The examples provide code that shows how to:
a) perform fft transforms
b) perform in seconds filtering and fft transforms on 1 million samples.
c) find the optimal fractional size for floating point representation.
d) find the optimal fractional size for fixed point representation.

FinSimMath

The DSP algorithm is described in FinSimMath, which is a superset of Verilog IEEE-std-1364.

FinSimMath's variable precision capabilities are described in chapter 8 of FinSim's User's Guide. The main features added to Verilog are:

a) additional system functions, such as $VpFft, $VpIfft, $VpSin, $VpCos, $VpTan, $VpCtan, $VpAsin, $VpAcos, $VpAtan, $VpActan, $VpPow, $VpPow2, $VpLog, $VpLn, $VpAbs, $VpFloor, $VpHypot, etc.

b) the capability of declaring variable precision objects by using the attributes varprec = data and varprec = descriptor in standard Verilog syntax.

Such objects can store values in fixed and floating point formats and the size of the formats can be changed during the execution of the simulation, by using the system tasks $VpAssociateDescriptorToData, $VpSetDescriptorInfo, and $VpSetDefaultOptions.

c) the capability of overloading arithmetic and logical operators as well as assignment operators, i.e. the compiler will find, if possible, the appropriate functions to implement the described functionality, without needing conversion functions.

d) support for displaying variable precision objects:

- %y: real number representation,

- %k: hex representation

- %h: binary representation

e) support for predefined types:

- VpComplex: pair of variable precision numbers as carthesian co-ordinates

- VpFComplex: pair of real numbers as carthesian co-ordinates

- VpPolar: pair of variable precision numbers as polar co-ordinates

- VpFComplex: pair of real numbers as polar co-ordinates

Butterworth IIR LP order 6 filter

The example chosen is a Butterworth IIR LP order 6 filter.

After having decided on the values of the coefficients based on the overall specifications, one must first make sure that the algorithm works as intended. For this purpose we represent all operands as being of Verilog real type, as shown in the FinSimMath description of the filter with operands of type real.
The steps performed in the given example at this stage are:

1) load in an array of type real an input waveform consisting of the sum of two sinusoids, one of a low frequency and the other of a high frequency and having 1/10 the magnitude of the first sinusoid.

2) load in an array of real an ideal output waveform consisting of the first sinusoid loaded in the input.

3) perform a Butterworth IIR LP order 6 filter which reduces the effect of the high frequency (second) sinusoid of the input.

4) Display the values of the input, ideal output and filtered output.

6) Perform a Fast Fourier Transform (FFT) on the input and display the resulting values. Note that only the first half of the values have meaning.

7) Perform an FFT on the ideal output and display the first half of the resulting values.

8) Perform an FFT on the filtered output and display the first half of the resulting values.

9) Compute the distance between the filtered output and the ideal output. The distance is computed using a user defined task written in standard Verilog. It uses as metrics the average value of the absolute values of differences.

Please note that the steps listed above do not represent all the steps that can be performed in order to ascertain the correctness of the algorithm. The example provided merely shows how the useful steps listed above can be performed in one Verilog simulation and extremely fast. For example, using FinSimMath one can perform a 1 million point fft in 3-4 seconds.

Determining format and sizes of operands

After having verified that the algorithm works correctly using operands of type real, one is assured that the algorithm works properly for the provided input data if the operands are floating point numbers with exponent of 12 bits and mantissa of 52 bits. One can at this stage determine which is the ideal format and what are the sizes of the fields of the particular chosen format (floating or fixed point format).

The FinSimMath code used to show capabilities for determining sizes of operands uses VpComplex types. This code looks almost identical to code using VpFComplex types above for the filtering part. The only differences are:

i) code associating descriptors to data

ii)code providing values for descriptors and global options.