2 +----------------------------------------------------------------------+
3 | Question: My filter design package gives me decimal fractional |
4 | numbers as output for my FIR filter coefficients. |
5 | How do I convert these decimal fractions into the |
7 +----------------------------------------------------------------------+
10 It's fairly easy to convert decimal fractions into the
11 data format required by the DSP56200. The DSP56200 coeffi-
12 cients are represented as 24-bit signed, fractional, 2's
13 complement numbers as shown in Table 1.
15 TABLE 1 - Representations for FIR Filter Coefficients
16 -----------------------------------------------------
19 Fraction 24-Bit Binary Value Coefficient
20 -------- ------------------- ----------
22 0.75 0.1100000 00000000 00000000 60 00 00
23 0.5 0.1000000 00000000 00000000 40 00 00
24 0.25 0.0100000 00000000 00000000 20 00 00
25 0.125 0.0010000 00000000 00000000 10 00 00
26 -0.125 1.1110000 00000000 00000000 F0 00 00
27 -0.75 1.0100000 00000000 00000000 A0 00 00
29 Each 24-bit coefficient is separated into three bytes
30 corresponding to the high, middle, and low bytes. The high
31 byte is written to the DSP56200 at address 0A (hex), the
32 middle byte to address 0B (hex), and the low byte to address
37 Step 1: Multiply the decimal fraction by 8388608.0 (decimal).
38 Note that 8388608 = 2 raised to the 23rd power.
39 Step 2: Truncate or round the result into an integer.
40 Step 3: Logically AND this integer with 00FFFFFF (hex).
41 Step 4: Write the result to an output file as a hex integer.
43 It is easy to write a program to perform this conversion on
44 a set of coefficients. If done by computer program, make
45 sure that all integer variables are represented with at
46 least 24-bits. An example of a short "C" program is
47 included at the end of this answer.
51 (1) Avoid letting a coefficient value be exactly 800000
52 (-1.0 in a fractional system). If this coefficient
53 is multiplied by a data sample with value -1.0, the
54 result is -1.0 instead of +1.0 as expected. This is
55 because +1.0 cannot be represented in a signed, 2's
56 complement, fractional system.
58 (2) The filter coefficients must be carefully selected
59 to prevent overflow. If there is a possibility of
60 overflow with a set of filter coefficients, then all
61 coefficients must be scaled by a constant value. The
62 DSP56200's 24-bit coefficients allow plenty of room
63 for scaling. If 12-bit input data samples are used
64 in a system, the potential for overflow is greatly
65 reduced if the samples are right justified and sign-
66 extended four bits before they are sent to the
71 /****************************************\
72 ** DECIMAL FRACTION TO HEX CONVERSION **
73 \****************************************/
75 /******************************************************************\
76 * This program converts one decimal, fractional number to a hex *
77 * number which can be written to the DSP56200's Coefficient RAM *
78 * Access registers. It prompts the user for a decimal fraction *
79 * and returns the corresponding hex number. *
81 * Examples of Program Results (useful for checking programs) *
90 * 0.00784313678741455 => 010101 *
91 * -0.00784313678741455 => fefeff *
93 * Note: The program assumes that the variable type "long" is an *
94 * integer which is at least 24-bits wide. *
96 * Also: The DSP56200 cannot use any coefficient value with a *
97 * magnitude of 1.0 or larger. All coefficients must be *
98 * signed, fractional quantities. *
99 \******************************************************************/
103 double fractnum; /* double precision floating pt */
104 long hexval; /* long integer */
107 /* Read 1 Decimal Floating Point Number from the Keyboard */
108 printf("Enter the decimal fraction: ");
109 scanf("%lf", &fractnum);
111 /* Convert to a Hex Integer which can be used by the DSP56200 */
112 hexval = (long) (8388608.0 * fractnum);
113 hexval = 0x00ffffffL & hexval;
115 /* Write the Hex number out to the Terminal */
116 printf("DSP56200 Coefficient = %06lx\n", hexval);