Digital Signal Processing Reference
In-Depth Information
10 /* Start loop for number of quad factors */
11 for(j = 0; j < numb_quads ;j++)
12 { w = o - *m1 * *c++;
C: 0.20,1.0, -0.80 ,-2.0,-1.0,0.05,-0.20,-2.0,-1.0
M : 1.0 ,3.0, 2.0 ,4.0
w: -0.40
13 w -= *m2 * *c++;
C: 0.20,1.0,-0.80, -2.0 ,-1.0,0.05,-0.20,-2.0,-1.0
M : 1.0 ,3.0, 2.0 ,4.0
w: 1.20
14 o = w + *m1 * *c++;
C: 0.20,1.0,-0.80,-2.0, -1.0 ,0.05,-0.20,-2.0,-1.0
M : 1.0 ,3.0, 2.0 ,4.0
o: -0.80
15 o += *m2 * *c++;
C: 0.20,1.0,-0.80,-2.0,-1.0, 0.05 ,-0.20,-2.0,-1.0
M : 1.0 ,3.0, 2.0 ,4.0
o: -2.8
16 *m2++ = *m1;
M : 1.0 ,3.0,1.0, 4.0
17 *m1++ = w;
M : 1.2, 3.0 ,1.0, 4.0
18 }
19 /* Convert output to int and store */
20 *y++ = (int)ceil(o-0.5);
y: -3, 0 ,0,0,0,...
21 }
}
Listing 8.2 Continued.
Notice that the method used to access the gain constant is by using the *c
notation, which can be read as β€œthe value at which c is pointing.” Since c has just
been initialized to the start of the C array, and since the first element in C is the
gain constant, then c is pointing at the gain constant. The β€œ++” notation after c
instructs the computer to increment the value of c by one after the equation has
been evaluated. (This is referred to as post-incrementing as opposed to ++c ,
which is called preincrementing.) At this point, we are performing pointer
arithmetic, which is a special type of arithmetic. Remember that the variable c
(and C ) contains a number that is an address of where coefficients are stored in
memory. When we increment a pointer we are incrementing an address and
therefore must do so in a meaningful way. In this case, the coefficients are stored
as double s, which take up 8 bytes of memory on a PC. It would be meaningless
to increment the address of an array containing double s by 1 byte, or 2, or
anything but 8 bytes. Therefore, when we tell the machine to increment c , it
increments the number stored in c by 8. (This is what is meant by special
arithmetic.) The compiler keeps track of how to increment pointer variables based
Search WWH ::




Custom Search