siny y À
1
3!
y
3
1
5!
y
5
À
1
7!
y
7
Á Á Á ,
3:8:1b
where y is in radians and `!' represents the factorial operation. The accuracy of the
approximation depends on how many terms are used in the series. Usually more terms
are needed to provide reasonable accuracy for larger values of y. However, in real-time
DSP application, only a limited number of terms can be used. Using a function
approximation approach such as the Chebyshev approximation, cos(y) and sin(y) can
be computed as
cosy 1 À 0:001922y À 4:9001474y
2
À 0:264892y
3
5:04541y
4
1:800293y
5
,
3:8:2a
siny 3:140625y 0:02026367y
2
À 5:325196y
3
0:5446788y
4
1:800293y
5
,
3:8:2b
where the value y is defined in the first quadrant. That is, 0 y < p=2. For y in the
other quadrants, the following properties can be used to transfer it to the first quadrant:
sin180
o
À y siny,
cos180
o
À y À cosy,
3:8:3
sinÀ180
o
y À siny,
cosÀ180
o
y À cosy
3:8:4
and
sinÀy À siny,
cosÀy cosy:
3:8:5
The C55x assembly routine given in Table 3.9 synthesizes the sine and cosine functions,
which can be used to calculate the angle y from À180
o
to 180
o
.
As shown in Figure 3.11, data in the Q15 format is within the range defined in (3.4.4).
Since the absolute value of the largest coefficient given in this experiment is 5.325196, we
cannot use the Q15 format to represent this number. To properly represent the coeffi-
cients, we have to scale the coefficient, or use a different Q format that represents both
the fractional numbers and the integers. We can achieve this by assuming the binary
point to be three bits further to the right. This is called the Q12 format, which has one
sign-bit, three integer bits, and 12 fraction bits, as illustrated in Figure 3.23(a). The
Q12 format covers the range À8 to 8. In the given example, we use the Q12 format
for all the coefficients, and map the angle Àp y p to a signed 16-bit number
(0x8000 x 0x7FFF), as shown in Figure 3.23(b).
When the sine_cos subroutine is called, a 16-bit mapped angle (function
argument) is passed to the assembly routine in register T0 following the C calling
conversion described in Chapter 2. The quadrant information is tested and stored in
TC1 and TC2. If TC1 (bit 14) is set, the angle is located in either quadrant II or IV. We
use the 2's complement to convert the angle to the first or third quadrant. We mask out
the sign-bit to calculate the third quadrant angle in the first quadrant, and the negation
changes the fourth quadrant angle to the first quadrant. Therefore the angle to be
118
DSP FUNDAMENTALS AND IMPLEMENTATION CONSIDERATIONS