Page 372 - Analog and Digital Filter Design
P. 372

Introduction to Digital Filters  369




                      Now  the  fundamentals  have  been  explained,  we  must  examine  some
                      arithmetic.


                      Adding Two’s Complement Numbers
                      Addition is the most basic of processes. Samples can be averaged by adding them
                      together and then dividing by the number of  samples. Filtering processes need
                      addition (as well as multiplication).

                      Adding two’s complement numbers is as simple as adding decimal numbers; the
                      advantage is that the signs are automatically taken care of. A simple equation
                      using two positive numbers will be given first.

                            Number      0111,0011,1011,1011    (73BBh or 29627)
                            Add         0011,1010,1001,1010    (3A9Ah or 15002)

                            Result      1010,1110,0101,0101    (AE55h or -51ABh  or -20907)
                      So, what went wrong? The problem here was not taking into account  the size
                      of  the numbers. The maximum number that  can be used in  16-bit two’s com-
                      plement arithmetic is 32767, or 2” - 1. The addition of decimal 29627 and I5002
                      results in 44629, which is beyond the allowed range.

                      Adding a negative and a positive number together gives the correct result. This
                      is shown in the following example.
                            Number         01 1 1,001 1,101 1,101 1  (73BBh or 29627)

                            Add            101 1,1010,0001,1000  (BA18h or -45E8h  or -17896)
                            Result   (I),  0010,1101,1101,0011  (2DD3h or 11731)

                      Notice that there has been a carry, which is ignored.

                      In DSPs that use Q15 format numbers, the accumulator has a 430 structure. A
                      Q15 number must be converted into a Q30 number before addition. This can
                      be  done  by  shifting  the  number  left  by  15 places  in  the  32-bit  accumulator.
                      This means that, after addition, the two most significant bits comprise the sign
                      and  carry  information.  The  accumulator’s result  is  then  shifted  left  by  one
                      bit, so the carry falls off  the end. The most significant bit in the accumulator
                      is now the sign bit, and the upper  half  of  the accumulator can be  stored in a
                      16-bit register.
   367   368   369   370   371   372   373   374   375   376   377