Background of the Invention
The present invention relates to a fast calculation method and, more particularly, to a fast calculation method and its hardware apparatus using a linear interpolation operation to reduce the complexity of the hardware and increase the speed of the calculation.
The ways for processing signals in devices such as computers, processors and the like are divided into two categories, one is an analog signal processing for continuous signals and the other one is a digital signal processing for discrete signals. The digital signal processing is selected more frequently than the analog signal processing since the digital signal processing can directly perform a complicated mathematical operation on signal values, greatly increasing the operative flexibility thereof. A digital signal is a combination of discrete sampling values obtained from sampling an analog signal in a fixed sampling frequency. Therefore, digital signals will become more analytical by picking a value between two sampling values through an interpolation operation.
The interpolation operation can be either simple or complicated, depending on which kind of the interpolation operation has been taken. The simplest one is a zero-order interpolation operation which regards a target point, that is, an interpolation value, as the first one of the two sampling points. Although the zero-order interpolation operation is very simple because what the zero-order interpolation operation needs to do is merely duplicate the first sampling point of the two rather than performing any computation, a lot of quantized noise signals will be introduced and thus, the quality of the interpolation operation is poor. A more useful interpolation operation is a linear interpolation operation which considers the relation between two sampling points to be linear and the target point will be obtained through a proportional computation. The linear interpolation operation becomes the most commonly chosen method because the computation amount of the linear interpolation operation is not too much but the effect in reducing the quantized noise signals is remarkable.
To raise the analytic degree of a signal and to reduce the quantized noise signal, adding a linear interpolation function into a circuit will without doubt increase the complexity of the circuit. For example, obtaining a target point I between a point X and a point Y, as shown in FIG. 1, the operations including an addition, a subtraction, multiplications and a division have to be taken in the following expression.
When the expression described above is implemented by a hardware, the following two problems will be faced.
(1) In the event that a signal X and a signal Y are quantized and encoded to data with 8 bits, expressions of (16-K)*X! and (K*Y) can be operated through a multiplier with a dimension of 8 bits by 4 bits. But operations in such a way will increase the complexity of the circuit and the manufacturing cost by a wide margin. Moreover, a modified design will be required by changing the multiplier with a dimension of 8 bits by 4 bits to a multiplier with a dimension of 8 bits by 5 bits or 8 bits by 6 bits if linear interpolation operations of dividing into 32 equal parts, 64 equal parts, and so on are further to be taken.
(2) In the event of merely substituting an adder for a multiplier, the expressions of (16-K)* X! and (K*Y) will require to repeat an accumulative addition operation 16 times in total to complete the entire operation. Operations in such a way are considerably time consuming and a counter has to be externally added to control the time the accumulative addition operates. Additionally, the times of repeating the accumulative addition operation have to be raised higher than 32 times, 64 times, and so on if linear interpolation operation of dividing into 32 equal parts, 64 equal parts, and so on are further to be taken.
Summary of the Invention
Accordingly, an objective of the present invention is to provide a fast calculation method and its hardware apparatus using a linear interpolation operation to simultaneously solve both problems of the complexity in circuit and the time in operation described above.
According to one aspect of the present invention, there is provided a fast calculation method using a linear interpolation operation comprising steps of: a step of determining two existing values of two given points X and Y, and a number K regarded as a position pointer of a target point I; a step of storing the two existing values of the two given points X and Y intended to proceed the linear interpolation operation; a step of adding the two existing values of the two given points X and Y, and discarding the lowest order bit of the resulting value; a step of selectively substituting the resulting value discarded from the lowest order bit for one of the two existing values of the two given points X and Y in accordance with the digit of the highest order bit in a binary representation of the position pointer K; a step of repeating the previous two steps until the lowest order bit in the binary representation of the position pointer K is used; and a step of achieving the interpolation value of the target point I from one of the two resulting values discarded from the lowest order bit of the two given points X and Y.
According to another aspect of the present invention, there is provided a hardware apparatus using a linear interpolation operation comprising: two registers for storing two existing values of two given points X and Y intended to proceed the linear interpolation operation; an adder for adding those existing values stored in two registers and discarding the lowest order bit of the resulting value to form a mean value, that is, achieving an effect of being divided by two; and a multiplexer for selectively substituting the mean value coming from the adder for one of the two existing values stored in these registers in accordance with the digit of the corresponding bit in the binary representation of the position pointer K, wherein the interpolation value of the target point I is one of the two mean values stored in these registers after the lowest order bit in the binary representation of the position pointer K is used.
Brief Description of the Drawings
The above objective, other features and advantages of the present invention will become more apparent by describing in detail a preferred embodiment thereof with reference to the attached drawings, in which:
FIG. 1 is a schematic representation of a linear interpolation operation;
FIG. 2 is a circuit diagram showing an operation flow of a hardware apparatus in accordance with the present invention;
FIG. 3 is a schematic representation of applying a concept of a bisection method to gradually approach an interpolation value using an interpolation operation in a accordance with the present invention;
FIG. 4 is a schematic representation of applying a concept of a bisection method to further gradually approach an interpolation value using an interpolation operation in accordance with the present invention;
FIG. 5 is a flowchart showing the steps of applying the fast calculation method using the linear interpolation operation of the present invention;
FIG. 6 is a preferred embodiment of a hardware apparatus in accordance with the present invention; and
FIG. 7 is another preferred embodiment of a hardware apparatus in accordance with the present invention.
Detailed Description of the Preferred Embodiment
As shown in FIG. 1, there is a schematic representation of a linear interpolation operation, the distance between a given point X and a given point Y is divided into the n-th power of 2 equal lengths. The distance between a target point I and the given point X is equal to the summation of K equal lengths with a condition of 2.sup.n -1.ltoreq.K.ltoreq.0. Here, the number K is regarded as a position pointer of the target point I. The value of the number K is converted into n bits through a binary scale and a binary representation thereof is K!.sub.2 =K.sub.n K.sub.n-1 K.sub.n-2 . . . K.sub.2 K.sub.1, in which the K.sub.n is the highest order bit and K.sub.1 is the lowest order bit. As a result, the expression I={(2.sup.n -K)*X!+(K*)}Y/2.sup.n is referred to as a linear interpolation formula.
The linear interpolation method adopts a concept of a bisection method. The position where the target point I located will be gradually approached by sequentially referring to the digit of the corresponding bit in the binary representation of the position pointer K from the highest order bit to the lowest order bit, and then the interpolation value of the target point I is achieved.
Because the number K is the position pointer of the point I, the position of the target point I will be affected by every bit in the binary representation of the number K to either come closer to or go farther from the position of the given point X. Taking the highest order bit K.sub.n in the binary representation of the number K for example, with reference to FIG. 3, the target point I must be located on the left side of the entire interval between the given point X and the given point Y if K.sub.n equals 0, and reversely, the target point I must be located on the right side of the entire interval between the given point X and the given point Y if K.sub.n equals 1. Similarly, with reference to FIG. 4, when K.sub.n equals 0, that is, the target point I is located within the interval between the given point X and a mid-point (X+Y)/2, the target point I must be positioned on the left side of the interval between the given point X and the mid-point (X+Y)/2 if K.sub.n-1 equals 0 and the target point I must be positioned on the right side of the interval between the given point X and the mid-point (X+Y)/2. Reversely, when K.sub.n equals 1, that is, the target point I is located within the interval between the point (X+Y)/2 and the given point Y, the effect that K.sub.n-1 generates will be in the same case as described above. How the position of the target point I will be affected by the other bits in the binary representation of the number K can be analogized in accordance with the principle described above.
Therefore, an interpolation value of a target point I can be achieved through applying a fast calculation method using a linear interpolation operation, and the steps are shown in FIG. 5.
Firstly, two existing values of two given points X and Y, and a number K regarded as a position pointer of the target point I is determined in step 1.
Next, the two existing values of the two given points X and Y intended to proceed the linear interpolation operation are stored in step 2.
Subsequently, the two existing values of the two given points X and Y are added, and the lowest bit of the resulting value is discarded in step 3.
Then, in step 4, the resulting value discarded from the lowest order bit will selectively substitute for one of the two existing values of the two given points X and Y in accordance with the highest order bit in the binary representation of the position pointer K, and the principle for substitution will depend on the larger difference of the two, one is the difference between the resulting value and the value of the given point X and the other one is between the resulting value and the value of the given point Y.
And then, the previous two steps will be repeated until the lowest order bit in the binary representation of the position pointer K is used.
Finally, in step 5, the interpolation value of the target point I is one of the final two resulting values stored depending on the substitution principle.
The hardware apparatus of the present invention will be now explained hereinafter. FIG. 2 shows a hardware apparatus of the present invention including two registers A and B, 10 and 20, an adder 30, and a multiplexer 40. Two existing values of two given points X and Y intended to proceed the linear interpolation operation are stored in the register A 10 and the register B 20 respectively. The two values stored in the two registers A and B, 10 and 20 are added in the adder 30 and the lowest order bit of the resulting value is discarded to form a mean value of the two. The mean value is then sent to the multiplexer 40 and every bit in the binary representation of the position pointer K will be sent to a selecting input terminal of the multiplexer 40 in sequence from the highest order bit to the lowest order bit. When the highest order bit in the binary representation of the position pointer K sent to the multiplexer 40 is "1", the mean value described above is sent back to the register A 10. Reversely, when the highest order bit in the binary representation of the position pointer K sent to the multiplexer 40 is "0", the mean value is sent back to the register B 20. The addition operation is proceeded in the adder 30 to obtain a new mean value and the if process of storing back the new mean value to either the register A 10 or the register B 20 will be proceeded again in accordance with the digit of the next higher order bit in the binary representation of the position pointer K. The above process is repeated until the lowest order bit in the binary representation of the position pointer K is sent, in the meantime, the final mean value stored in the register A 10 is the interpolation value with the least error.
Every time, the lowest order bit of the resulting value sent from the adder 30 is discarded by the bisection operation, that is, only the integer portion of the sum of the two values stored in the register A 10 and the register B 20 is stored and the fractional portion of the sum described above is discarded. The maximum error in the binary representation is 0.1111111 . . . , in which the digit 1 with the shortest distance away from the decimal point is the fractional portion discarded by the last one bisection operation and the digit 1 with the greatest distance away from the decimal point is the fractional portion discarded by the first one bisection operation. Therefore, the maximum accumulated error is 1/2+(1/2).sup.2 +(1/2).sup.3 +(1/2).sup.4 + . . . , the total sum must be less than 1 when converting to decimal scale.
A preferred embodiment is shown in FIG. 6. Suppose that the distance between a given point X and a given point Y is divided into 32 equal parts and the distance ratio between the position of a target point I and the given point X to the distance between the target point I and the given point Y is 25 to 7, that is, the value of the position pointer K is 25. According to the definition described above, 32 is the 5th power of 2, that is, n equals 5. Accordingly, the relational expression should be the following. ##EQU1##
The operation is carried out through the hardware apparatus shown in FIG. 2 and the resulting values discarded from the lowest order bit being stored in the registers A and B, 10 and 20, every time after the bisection method has been operated are shown in the table of FIG. 6. After the bisection method has been operated 5 times, the integer value stored in the register A 10 is exactly the same as the above expression (7*X+25*Y)/32.
Here, another preferred embodiment is shown in FIG. 7. Suppose that the distance between the given point X and the given point Y is divided into 64 equal parts and the distance ratio between the position of the target point I and the given point X to the distance between the target point I and the given point Y is 19 to 45, that is, the value of the position pointer K is 19. Referring to the previous definition, 64 is the 6th power of 2, that is, n equals 6. Accordingly, the relational expression should be the following. ##EQU2##
The operation is carried out through the hardware apparatus shown in FIG. 4 and the values are stored in registers A and B every time after the bisection method has been operated 6 times. The integer value stored in the register A is exactly the same as the intended expression (45*X+19*Y)/64.
Although the invention has been explained in relation to its preferred embodiment, it is to be understood that many other possible modifications and variations can be made without departing from the spirit and scope of the invention as hereinafter claimed.