## Orders of Magnitude, Logarithmic Scales, and Decibels

Electrical engineering, to a degree more than many other fields of engineering, features coexisting, interacting quantities over many orders of magnitude. Both a $1 \Omega$ resistor and a $1\ \text{M} \Omega = 10^6 \Omega$ resistor are common, and it is not unusual to find a circuit board that features at least one of each.

Determining if a particular resistor should be $100\ \Omega \text{,}\ 1\ \text{K} \Omega \text{,}\ 10\ \text{K} \Omega \text{, or}\ 100\ \text{K} \Omega$ is far more important than whether it should be $1\ \text{K} \Omega \ \text{or}\ 2.2\ \text{K} \Omega$.

Logarithms compress values from many orders of magnitude down to a smaller space. Some of the basic rules about logarithms to remember include:

\begin{align} \log_b (b^x) & = x \\ b^{\log_b x} & = x \\ \log_b 1 & = 0 \\ \log_b b & = 1 \\ \log_b (x \cdot y) & = \log_b x + \log_b y \\ \log_b (\frac {x} {y}) & = \log_b x - \log_b y \\ \log_b (x^y) & = y \cdot \log_b x \\ \log_y x & = \frac {\log_b x} {\log_b y} \quad \text{for any} \ b>1 \end{align}

(The equation $\log_2 16 = 4$ is read aloud as: "The log-base-two of sixteen equals four.")

If the base is not explicitly specified, the context usually determines the intended base. Base $b=10$ is commonly used in engineering and is commonly written as $\log(x)$. In mathematics, the natural base $b=e=2.71828\dots$ is commonly used and written as $\ln(x)$. In computer science, base $b=2$ is commonly used and written as $\lg(x)$. If it's ever unspecified and unclear, ask.

### Decibels

Taking a logarithm compresses multiplicative differences into additive differences. For example, if we have two functions $x(t)$ and $y(t) = 25 \cdot x(t)$, then the logarithms (in any base) of these two functions will only differ by a constant:

$$\log_b y(t) = \log_b \big( 25 \cdot x(t) \big) = \log_b {25} + \log_b x(t)$$

This is a useful way of thinking about lots of electronic systems like amplifiers and filters, which in general apply multiplicative transformations to an input signal. With logarithms, we can think of that multiplicative transformation as just shifting the value up or down on the y-axis.

The decibels difference between two multiplicatively-related voltage or current signals is defined as:

$$A = 20 \log \frac {V_{out}} {V_{in}}$$

where A is in dB. In this context, the logarithm is defined as being base 10.

Where does the factor 20 come from? The answer is that this was defined so that a 10X multiplicative increase in power would be equivalent to adding +10dB.

Because power is proportional to the square of voltage (which we'll discuss in more detail in the Power section), a $10\text{X}$ increase in voltage through an amplifier results in a $10^2 = 100\text{X}$ increase in power, or +20dB.

Since $\frac {P_{out}} {P_{in}} = \big( \frac {V_{out}} {V_{in}} \big) ^2$, then:

\begin{align} A & = 20 \log \sqrt{ \frac {P_{out}} {P_{in}} } \\ & = 20 \cdot \frac{1}{2} \log \frac {P_{out}} {P_{in}} \\ & = 10 \log \frac {P_{out}} {P_{in}} \end{align}

(To avoid complicating the discussion of decibels at this early stage, we're going to avoid talking about reference impedance here. As logarithms of negative numbers don't exist, we're also generally talking about the envelope or amplitude of the signal, rather than the signal waveform itself.)

Here are some common decibel values and hints about where they're from:

$$\begin{array}{c|ccc} \text{Decibels} & V\ \text{or}\ I\ \text{Multiplier} & P\ \text{Multiplier} & P\ \text{Multiplier} \\ \hline +40\ \text{dB} & 100 & 10000 & 10^4 \\ +30\ \text{dB} & \sqrt{1000} & 1000 & 10^3 \\ +20\ \text{dB} & 10 & 100 & 10^2 \\ +10\ \text{dB} & \sqrt{10} & 10 & 10^1\\ +6\ \text{dB} & 2 & 4 & 10^{0.60206\dots} \\ +3\ \text{dB} & \sqrt{2} & 2 & 10^{0.30103\dots} \\ 0\ \text{dB} & 1 & 1 & 10^0 \\ -3\ \text{dB} & \sqrt{\frac {1} {2}} & \frac {1} {2} & 10^{-0.30103\dots} \\ -6\ \text{dB} & \frac {1} {2} & \frac {1} {4} & 10^{-0.60206\dots} \\ -10\ \text{dB} & \sqrt{\frac {1} {10}} & \frac {1} {10} & 10^{-1} \\ -20\ \text{dB} & \frac {1} {10} & \frac {1} {100} & 10^{-2} \\ -30\ \text{dB} & \sqrt{\frac{1} {1000}} & \frac{1} {1000} & 10^{-3} \\ -40\ \text{dB} & \frac {1} {100} & \frac {1} {10000} & 10^{-4} \\ \end{array}$$

It is not unusual to see decibel values outside these bounds: +80 dB represents a power multiplier of $10^8$ and a voltage multiplier of $10^4$. In general, we can just invert the equations above for A dB:

\begin{align} \frac {V_{out}} {V_{in}} & = 10 ^ {(A / 20)} \\ \frac {P_{out}} {P_{in}} & = 10 ^ {(A / 10)} \end{align}

The values for $\pm 3 \ \text{dB}$ and $\pm 6 \ \text{dB}$ are not exact but are common approximations, because:

\begin{align} 20 \log_{10} 2 & = 6.0206\dots & \approx 6 \\ 20 \log_{10} \sqrt{2} & = 3.0103\dots & \approx 3 \end{align}

These exact decibel values for multiplication by $2$ and $\sqrt{2}$ are commonly truncated. That's why engineers speak colloquially about +3 dB or +6 dB to refer to a power gain of 2 or a voltage gain of 2, respectively.

If we connected two amplifiers together in series, each of which had 10x voltage gain, then each would contribute +20dB gain. We can add the decibel values to get +40dB overall voltage gain -- a factor of $10^2$ in voltage and a factor of $10^4$ in power.

### Absolute Decibel Units

Any unit specified only as "dB" refers only to a relative factor between signals.

However, it is often convenient to define the denominator as a specific unit-bearing quantity.

For example, "dBm" means "decibels relative to 1 milliwatt." Therefore, +20 dBm represents "+20dB relative to 1 milliwatt." As Watts are a unit of power, and +20 dB is a multiplication of 100X in power, then "+20 dBm" is simply a short way of saying "100 milliwatts."

In another example, "dBV" means "decibels relative to 1 Volt." Therefore, -60 dBv represents "-60dB relative to 1 volt." As -60 dB in voltage is a voltage factor of $10^{-3}$, then "-60 dBV" is simply a short way of saying "1 millivolt."

Be careful to track whether a decibel unit is relative or absolute, and whether the absolute reference represents a power or voltage level.

### Decibels Rolloff

In future sections when we talk about frequency response of amplifiers and filters, we will sometimes consider numbers like "-20 dB/decade" or "-6 dB/octave".

A decade is a 10X increase in frequency, for example from 100 Hz to 1000 Hz. Saying "minus 20 dB per decade" might mean that the output signal at 1000 Hz is only $\frac {1} {10}$ as large in voltage amplitude as the signal at 100 Hz.

An octave is a 2X increase in frequency, just as it is in music. For example 100 Hz and 200 Hz are one octave apart. Saying "minus 6 dB per octave" might mean that the output signal at 200 Hz is only $\frac {1} {2}$ as large in voltage amplitude as the signal at 100 Hz.

It turns out that these two examples are actually referring to the same thing:

$$-20 \ \text{dB/decade} \approx -6 \ \text{dB/octave}$$

Let's prove it. How many octaves are in a decade?

$$k = \log_2 10 = \frac {\log 10} {\log 2} \approx 3.322$$

If we start at frequency $f$ and double it three times (i.e. go up three octaves), we'll end up with $2^3 \cdot f = 8 \cdot f$ -- almost enough to reach $10 \cdot f$, but not quite. If we double $f$ four times (i.e. go up four octaves), we'll end up with $2^4 \cdot f = 16 \cdot f$ -- more than a decade; we've gone too far. The real number of octaves necessary to complete a decade is between three and four, and is shown as $k$ above.

If our signal is reduced by -6 dB/octave, and we go up in frequency by 3.322 octaves, the total reduction is:

$$(-6 \frac {\text{dB}} {\text{octave}}) (3.322 \frac {\text{octaves}} {\text{decade}}) = -19.932 \frac {\text{dB}} {\text{decade}}$$

That -19.932 dB is really precisely -20dB when we account for the fact that -6 dB is only a rounded-off approximation for $20 \log_{10} 2 \approx 6.0206$.

### Semi-Logarithmic Plotting

On a semi-log plot, the y-axis is plotted on a logarithmic scale while the x-axis remains linear. This turns functions that are exponentially changing (with any base) into straight lines. For example, consider the value of a savings account with initial value 1000 growing at 5% per year, with time $t$ in years. The value of the account is:

$$m(t) = 1000 \cdot 1.05^t$$

If we take the log,

\begin{align} \log m(t) & = \log \big( 1000 \cdot 1.05^t \big) \\ \log m(t) & = \log 1000 + \log 1.05^t \\ \log m(t) & = \log 1000 + t \cdot \log 1.05 \\ \log m(t) & \approx 3 + 0.02119 \cdot t \end{align}

The logarithm has transformed an exponential (with base 1.05) into a straight line.

For a similar example, plotting the value of a stock or mutual fund should be done on a semi-log plot. (It should also be plotted with dividends reinvested to show total returns, though this is a separate issue we can't address here.) Why logarithmic? Because if we plot with a linear scale, it looks like all the growth has happened in just the last few years. If we plot with a logarithmic scale, it reveals that in fact an investor at roughly any point has roughly doubled their investment value in about a decade. This reflects the idea that in general, in any given year, the company's profit (whether retained earnings or distributed as dividends) will be roughly a few percent of its current value.

To see for yourself, load this data, click "Max" to set the maximum timescale from 1970 onwards. The linear graph looks absolutely tiny for the first half of the dataset. Now, click "Edit Graph", click "Format", and check the box next to "Log Scale"; if the horizontal scale resets you may have to click "Max" again. Now, while it's not smooth or consistent or risk free, you'd see that in fact the general trend of growth (in a %/year growth sense) has been present for many decades.

### Log-Log Plotting

If plotting with a logarithmic scale on the y-axis is powerful, then plotting with a logarithmic scale on both the x-axis and y-axis is really powerful.

Consider our function $y(x) = \frac {1} {1+x}$ that we used for computing various approximations in the Algebraic Approximations section. Taking the log of both sides:

\begin{align} y(x) & = \frac {1} {1+x} \\ \log y(x) & = \log \big( \frac {1} {1+x} \big) \\ \log y(x) & = - \log (1+x) \\ \end{align}

This alone doesn't look very easy to understand, but let's again apply various approximations in different limiting asymptotes for $x$:

\begin{align} \log y(x) = - \log (1+x) & \approx - \log(1) = 0 & \text{for} \ |x| \ll 1 \\ \log y(x) = - \log (1+x) & \approx - \log(x) & \text{for} \ x \gg 1 \\ \end{align}

Now let's define $p = \log x$ and $q = \log y$. These represent the logarithmically-transformed $x$ and $y$ axes for plotting.

\begin{align} q & \approx 0 & \text{for} \ |x| \ll 1 \\ q & \approx -p & \text{for} \ x \gg 1 \\ \end{align}

Now we have two very simple equations for lines which are good approximations for $q$ in different regimes: the first section has a slope of 0 (a horizontal line), and the second section has a slope of -1. The approximation line will do badly near the "knee" where the two approximations meet, but will do well everywhere else.

Instead of defining these in terms of $x$ we can transform to $p$, and join the lines into a single approximation function (again looking only at positive $p$ due to the domain of logarithm):

\begin{align} \hat{q}(p) & = 0 & \text{for} \ p \le 0 \\ \hat{q}(p) & = -p & \text{for} \ p \ge 0 \\ \end{align}

Finally, we can join these at $p=0$ by seeing that we can take the minimum value of either segment at any given $p$:

$$\hat{q}(p) = \min \big( 0, -p \big)$$

This is simply a compact representation of the two segments above, but importantly, it is a representation that the mathematical expression evaluation software inside CircuitLab knows how to handle directly using the MIN(a,b) notation -- see the documentation on expressions for more information.

We'll show how good the log-log plot is by considering value of $p$ from $10^{-5} \ \text{to} \ 10^{+5}$ -- a factor of 10 billion from bottom to top!

Interactive Exercise Click the "circuit" shown above, then click "Simulate", then "Run DC Sweep". You'll see two lines plotted:

\begin{align} q(p) & = \log \big( \frac {1} {1 + 10^p} \big) \\ \hat{q}(p) & = \min \big( 0, -p \big) \end{align}

The approximation $\hat{q}(p)$ is quite good for $p \le -1$ and $p \ge +1$, which corresponds to $x \le 0.1$ and $x \ge 10$. In the middle, neither approximation is excellent, but the error can be quantified now that we know it's there.

We've taken a complicated-looking fraction and turned it into a collection of straight line segments by using two tools: log-log plots and asymptotic approximations. That's the power of log-log plotting: it turns rational polynomials (fractions with $x^n$ in the numerator or denominator) into straight line approximations that work over many orders of magnitude.

Note that the second line segment has slope -1, corresponding to $x^{-1}$. If the original fraction had $x^{-2}$, the slope would be -2.

Log-log plots and the straight line approximation concept will come up again when we look at filters and amplifiers and frequency response. Log-log is a great fit there because the independent variable (frequency) varies over many orders of magnitude, as does the dependent variable (amplification of magnitude).

And, as we'll see, the frequency response of common filters can be described by rational polynomials, so we'll get straight line segment approximations there too when using these same tools. For example, a simple RC low-pass filter will have a $1/f$ amplitude response for frequencies above its corner frequency, mapping precisely to the example we've just illustrated.

If the concepts of asymptotic approximations, semi-log, and log-log plots are still unfamiliar, you're encouraged to brush up and explore these concepts on paper and/or in simulation, as they will come up again and again as we go.

### Metric Decimal Unit Prefixes

As electronic quantities span many orders of magnitude, it's common in electronics to use unit prefixes that help designate orders-of-magnitude at various powers of $10^3$. These make human-readable numbers simpler.

$$\begin{array}{c|cccl} \text{Value} & \text{Prefix} & \text{Abbreviation} & \text{Example} \\ \hline 10^{12} & \text{tera} & \text{T} & 3 \ \text{THz} = 3 \times 10^{12} \ \text{Hz} \\ 10^{9} & \text{giga} & \text{G} & 2.4 \ \text{GHz} = 2.4 \times 10^{9} \ \text{Hz} \\ 10^{6} & \text{mega} & \text{M} & 10 \ \text{M}\Omega = 10^7 \ \Omega \\ 10^{3} & \text{kilo} & \text{k} & 2.2 \ \text{k}\Omega = 2200 \ \Omega \\ 10^{0} & - & - & 5 \ \text{V} \\ 10^{-3} & \text{milli} & \text{m} & 5.3 \ \text{mV} = 0.0053 \ \text{V} \\ 10^{-6} & \text{micro} & \mu & 22 \ \mu \text{F} = 0.000022 \ \text{F} \\ 10^{-9} & \text{nano} & \text{n} & 200 \ \text{nV} = 2 \times 10^{-7} \ \text{V} \\ 10^{-12} & \text{pico} & \text{p} & 12 \ \text{pF} = 12 \times 10^{-12} \ \text{F} \\ 10^{-15} & \text{femto} & \text{f} & 200 \ \text{fs} = 2 \times 10^{-14} \ \text{s} \end{array}$$

The abbreviation for micro is $\mu$, the Greek lowercase letter mu. However, because this is hard to type into a computer, it's often written with just the lowercase letter u: $22 \ \mu \text{F} = 22 \ \text{uF}$, but is spoken aloud as "twenty two micro Farads" either way.

Most electronics software, including the CircuitLab simulation software, will understand these prefixes if the prefix comes immediately after the digits of the number (with no space in between). For example, you can enter "2.2k" in the value field for a resistor to get a 2200 ohm resistance. One confusing case is that mega is represented by uppercase "M" and milli is represented by lowercase "m"; modern software like CircuitLab will interpret these two correctly as written, but some older SPICE-based circuit software dates back to the 1970s and can't handle the difference between uppercase and lowercase characters! These older programs instead use "MEG" to denote mega. Be careful that the computer interprets your value correctly.

### What's Next

In the next section, Complex Numbers, we'll talk about real and imaginary numbers and their connection to circles, trigonometry, and sine waves. (Later, we'll connect complex numbers with our algebraic approximations & log-log plotting to explore the frequency domain.)