This blog presents a computationally-efficient linear interpolation trick that requires at most one multiply per output sample.

Background: Linear Interpolation

Looking at Figure 1(a) let's assume we have two points, [x(0),y(0)] and [x(1),y(1)], and we want to compute the value y, on the line joining those two points, associated with the value x.

Figure 1: Linear interpolation: given x, x(0), x(1), y(0), and y(1), compute the value of y.

Equating the slopes of line segments on the blue line in Figure 1(a) we can write:

. (1)

Solving Eq. (1) for y gives us:

. (2)



Equation (2) requires four additions, two multiplications, and one division to compute a single y value. As in Figure 1(b) to compute, say, two different intermediate y values on the blue line requires us to evaluate Eq. (2) twice.

Linear Interpolation With Time-Domain Periodic Samples

DSP folks, when processing periodically sampled time-domain x(k) sequences, have a better scheme for linear interpolation. In that scenario, for example, the z-domain transfer function of an L = 3 linear interpolator is:

(3)



implemented in a tapped-delay line structure as shown in Figure 2. The "↑L" upsample process means insert L–1 zero-valued samples in-between each sample of the x(k) input sequence.

Figure 2: L = 3 DSP linear interpolator block diagram.

The traditional Figure 2 interpolation method requires 2L-2 multiplies and 2L-2 additions per output sample. The following proposed linear interpolation is more computationally efficient.

Proposed Efficient Linear Interpolation

Our efficient linear interpolator is the simple network shown in Figure 3. That mysterious block labeled 'Zero-Order Hold' is merely the operation where each u(k) input sample is repeated L–1 times. For example, if L = 3 and the input to the Zero-Order Hold operation is {1,-4,3}, the output of the process is {1,1,1,-4,-4,-4,3,3,3}.

Figure 3: Proposed linear interpolation block diagram.

The example sequences in Figure 4 highlight the operation of the proposed Figure 3 linear interpolator.

Figure 4: Proposed linear interpolation example sequences when L = 3.

The important details to notice in Figure 4 are:

• The v(n) sequence is simply the u(k) sequence with each u(k) sample repeated L-1 = 2 times (zero-order hold)

• The x(k) input samples are preserved in the y(n) output sequence

• The transient response of our proposed interpolator is L-1 samples, so the first valid output sample is the L-1 = 2nd y(n) sample

• If we're able to set L to an integer power of two then, happily, the 1/L multiplication can be implemented with a binary arithmetic right shift by log 2 (L) bits yielding a multiplierless linear interpolator

• If an interpolator output/input gain of L is acceptable, the 1/L multiplication can be eliminated.

Fixed-Point Arithmetic Implementation

When implemented in fixed-point two's complement arithmetic, the 1/L multiply in Figure 3 induces significant (and unpredictable) quantization distortion in the y(n) output, particularly when the x(k) input is low in frequency or small in amplitude. We can drastically reduce that distortion by moving the 1/L multiplication to be the final operation as shown in Figure 5.

Figure 5: Fixed-point arithmetic implementation of the proposed linear interpolator.

When using two's complement arithmetic, if the x(k) input samples are N bits in width then the bit width of the accumulator register used in the first adder must be N+1 bits in width.

We must ensure that the bit width of the accumulator register used in the second adder be large enough to accommodate a gain of L from the x(k) input to the output of the second adder.

As with the Figure 3 implementation, if the value L in Figure 5 is an integer power of two then a binary right shift can eliminate the final 1/L multiplication. And again, if an interpolator gain of L is acceptable then no 1/L scaling need be performed in Figure 5.

Conclusions

We've introduced efficient floating-point (Figure 3) and fixed-point (Figure 5) linear interpolators. Their computational workloads are compared in Appendix A.

The experienced reader might now say, "Ah, while those networks are computationally simple, linear interpolation is certainly not the most accurate method of interpolation, particularly for large interpolation factors." Rocky Balboa would reply with, "This is very true. But if interpolation is being done in multiple stages, using these efficient interpolators as the final stage at the highest data rate (when the signal samples are already close together) will introduce only a small interpolation error."

Appendix A: Computational Workload Comparison

Table A-1 compares the arithmetic workload of the above linear interpolation by L methods, measured in computations per output sample.

Table A-1: Arithmetic computations per output sample for linear interpolation by L.