Approximation Math

Introduction

Back in 2003, I used an approximation for the logarithm function in a hardware application. When originally implemented, the function only had to work for a limited range of input. Recently, a customer has requested that we expand the range of operation for this function. This post examines how I went about expanding this approximation's range of operation.

Engineers frequently have to approximate common mathematical functions. You might wonder why we still need to approximate these functions when there are excellent mathematical libraries available for all commonly used processors. There are two reasons:

  • Speed
    Library functions are coded for accuracy and they frequently take a long time to execute. There are applications where accuracy is less important than speed and approximations may accurate enough and fast enough to solve your problem. For example, I have had to use approximations to the square root function when computing the magnitude of vectors in real-time navigation applications. Library functions simply were too slow.
  • Cost
    Library functions require lots of memory and may force you to buy a faster processor in order to execute them. My cost limitations are usually so tough that I have to use cheap processors like AVRs, which have limited memory and throughput. I need to find inexpensive ways to implement math functions on these brain-dead computers.

We will examine my original implementation and how I went about expanding its range of operation, which engineers refer to as the function's "dynamic range."

Background

Decibel Basics

Technically, I view decibels as a scaling rather than a unit. Decibels are always expressed relative to a unit, in this case milliwatts. Equation 1 defines the dBm, which means decibels relative to one mW.

Eq. 1 {{P}_{dBm}}=10\cdot \log \left( {{P}_{mW}} \right)

where

  • PmW is the measured power in milliwatts [mW],
  • PdBm is the measured power expressed in decibels milliwatt (dBm)

I need to approximate Equation 1 over a range from - 6 dBm to 0 dBm with an accuracy of better than 0.5 dB. This post will use a 4th-order polynomial to approximate the logarithm function. Equation 2 defines my polynomial model. I also include an equivalent matrix version.

Eq. 2 d{{B}_{Approx}}(x)={{a}_{4}}\cdot {{x}^{4}}+{{a}_{3}}\cdot {{x}^{3}}+{{a}_{2}}\cdot {{x}^{2}}+{{a}_{1}}\cdot x+{{a}_{0}}
d{{B}_{Approx}}(x)=\left[ {{a}_{4}}\quad {{a}_{3}}\quad {{a}_{2}}\quad {{a}_{1}}\quad {{a}_{0}} \right]\cdot {{\left[ {{x}^{4}}\quad {{x}^{3}}\quad {{x}^{2}}\quad x\quad 1 \right]}^{T}}

Now that we know a bit about decibels, let's discuss how cable TV works, and if you want some more information, you can also click here to check out the updated cable TV statistics for this year.

Some Cable TV Basics

Figure 1 illustrates the scenario I find myself in. In general, one laser will drive multiple stages of amplification. Thus, one laser and a "tree" of EDFAs can serve thousands of homes.

Figure 1: General Optical Deployment Model using Lasers and EDFAs.

Figure 1: General Optical Deployment Model using Lasers and EDFAs.


Video service providers use a laser to transmit their video signal to the homes they serve. The power of this signal is important because it determines how many homes can be served -- every home must receive a specified level of power to provide a high quality signal. However, more optical power requires more expensive transmission gear (e.g. devices called EDFAs). Service providers want to use exactly the amount of optical power that they need and no more. They set the power of this signal in decibels because that is how the equipment was designed (again, the decibel legacy). For all sorts of reasons, my gear at the home needs to measure the power of this signal. However, real components measure power in mW (or a similar unit) not decibels. Yet, I need to be able to provide an optical power measurement in decibels for system monitoring purposes. I do not want to raise my product costs by adding memory just to compute decibels. So I decided to use a polynomial approximation to the logarithm because it requires little memory and is very fast on an AVR processor.

Analysis

My Original Polynomial Approximation

Figure 2 shows my Mathcad implementation of a minimum-maximum error curve fit routine. I chose to use a dynamic range from -6 dBm to 0 dBm (to be truthful, the actual range I used was slightly different but for reasons that are unimportant here).

Figure 2: My Original Determination of Logarithmic Approximation Coefficients.

Figure 2: My Original Determination of Logarithmic Approximation Coefficients.


Figure 3 shows the "goodness of fit" for this approxmation.
Figure 3: Goodness of Fit for the Original Approximation.

Figure 3: Goodness of Fit for the Original Approximation.

A Wider Dynamic Range Version

Approach

A service provider wants me to expand the range of operation of my optical power measurement to -12 dB to 6 dBm from -6 dBm to 0 dBm. As I thought about it, I made the following observations.

  • I can break this range into three parts related by a factor of 4:
    • -12 dBm to -6 dBm
    • -6 dBm to 0 dBm
    • 0 dm to 6 dBm
  • You can see these ranges are related by a factor of 4 by noting that 10\cdot \log (4)\doteq 6 \text{ dB}

Given these observations, I can state Equation 3.

Eq. 3 10\cdot \log \left( 4\cdot x \right)=10\cdot \log \left( x \right)+6
10\cdot \log \left( \frac{x}{4} \right)=10\cdot \log \left( x \right)-6

So I can use my dB approximation over a wider dynamic range by using Equation 3 as shown in Equation 4.

Eq. 4

Results

Figure 4 shows the effectiveness of my approximation. This is not too bad and I can reuse software that has already been tested.

Figure 4: Wider Dynamic Range Version of the dB Approximation.

Figure 4: Wider Dynamic Range Version of the dB Approximation.

Conclusion

This was a nice example of using a property of logarithms to solve a common engineering problem.

This entry was posted in Electronics, General Mathematics. Bookmark the permalink.