Wave Walker DSP

DSP Algorithms for RF Systems

Trending

Buy the Book!

DSP for Beginners: Simple Explanations for Complex Numbers! The second edition includes a new chapter on complex sinusoids.

Basic Rules for Complex Numbers
September 17, 2021

Table of Contents

Introduction

The mathematics of DSP and complex numbers can be confounding.

Understanding how j = \sqrt{-1} was difficult when I first started my DSP education and it’s still not something I fully grasp. When starting out in your DSP education sometimes it is enough to simply understanding how the tools and procedures are applied, rather than how they are derived.

Personally, early in my career I accepted the fact that j = \sqrt{-1} is true and useful, along with a host of other equations. Over many years of experience in the classroom and in the laboratory I have build some intuition around the mathematics and can apply them appropriately. But it all started with understanding the mathematical rules of complex numbers.

More posts on complex numbers:

Square Root of -1

As

(1)   \begin{equation*}j = \sqrt{-1},\end{equation*}

then

(2)   \begin{equation*}\begin{split}j^2 & = j \cdot j \\& = \sqrt{-1} \cdot \sqrt{-1} \\& = (-1)^{0.5} \cdot (-1)^{0.5} \\& = -1^{1} \\& = -1.\end{split}\end{equation*}

Similarly,

(3)   \begin{equation*}\begin{split}j^3 & = j \cdot j^2 \\& = j \cdot -1 \\& = -j,\end{split}\end{equation*}

and

(4)   \begin{equation*}\begin{split}j^4 & = j^2 \cdot j^2 \\& = -1 \cdot -1 \\& =1.\end{split}\end{equation*}

Note that generalizing (1) – (4) leads to

(5)   \begin{equation*}j^n = j^{n+4}.\end{equation*}

Mathematically it may be useful to represent j in the numerator rather than the denominator, which can be done by multiplying by j/j,

(6)   \begin{equation*}\begin{split}\frac{1}{j} & = \frac{1}{j} \cdot \frac{j}{j} \\& = \frac{j}{j^2} \\& = -j.\end{split}\end{equation*}

Cartesian Form

Cartesian form is one way to represent complex numbers in a form similar to two dimensional vectors. Cartesian form is the default representation used in computing systems. An example of a two dimensional vector \vec{z} is given by

(7)   \begin{equation*}\vec{z} = c \hat{x} + d \hat{y}\end{equation*}

where \hat{x} and \hat{y} are unit vectors. The values c and d are independent of one another because the two unit vectors \hat{x} and \hat{y} are orthogonal to one another. An example of a two-dimensional vector is given in Figure 1.

Figure 1: An example of a two-dimensional vector 1x + 3y.
Figure 1: An example of a two-dimensional vector 1x + 3y.

Complex numbers are similar to two-dimensional linear vectors but with additional mathematic relationships. Complex numbers are made of real and imaginary components. For the complex number c,

(8)   \begin{equation*}c = a + j\cdot b,\end{equation*}

a is the real component and b is the imaginary component. Where the unit vectors \hat{x} and \hat{y} are made explicit in (7), the unit vector for a is implied and the unit vector for b is j. Figure 2 gives an example of a complex number plotted in the complex domain.

Figure 2: An example of complex number 1 + 3j plotted in the complex domain. Note that the plots of Figure 1 and Figure 2 are identical, it is only the mathematical representation and axes that are different.
Figure 2: An example of complex number 1 + 3j plotted in the complex domain. Note that the plots of Figure 1 and Figure 2 are identical, it is only the mathematical representation and axes that are different.

Magnitude

The magnitude of a complex number is it’s length in the complex domain,

(9)   \begin{equation*}\begin{split}|c| & = \sqrt{c \cdot c^*} \\& = \sqrt{(a + jb) \cdot (a - jb)} \\& = \sqrt{a (a - jb) + jb (a - jb)} \\& = \sqrt{a^2 - abj + abj + b^2} \\& = \sqrt{a^2 + b^2},\end{split}\end{equation*}

which is analogous to the Euclidean distance of a 2D vector.

For example, the magnitude of c = 1 + 3j from Figure 2 is

(10)   \begin{equation*}\begin{split}|1 + 3j| & = \sqrt{1^2 + 3^2} \\& = \sqrt{1 + 9} \\& = \sqrt{10} \\& \approx 3.16.\end{split}\end{equation*}

Magnitude-Squared

The magnitude-squared tends to be found in DSP concepts such as energy and power. The magnitude-squared is the square of the magnitude,

(11)   \begin{equation*}\begin{split}|c|^2 & = c \cdot c^* \\& = a^2 + b^2,\end{split}\end{equation*}

where c = a + jb. For example, the magnitude-squared of c = 1 + 3j from Figure 2 is

(12)   \begin{equation*}\begin{split}|1 + 3j| & = 1^2 + 3^2 \\& =1 + 9 \\& = 10.\end{split}\end{equation*}

Angle and Phase

The angle or phase of a complex number is its angular distance from 0 degrees, which is 3 o’clock on a clock face. The angle also describes the relationship between the sine and cosine component of a complex exponential if the complex number was treated as the hypotenuse of a triangle.

Mathematically the arctangent is used to calculate the angle of a complex number \sphericalangle{c} where

(13)   \begin{equation*}\sphericalangle c = \text{arctan} \left( \frac{\text{IM}\{c\}}{\text{RE}\{c\}} \right).\end{equation*}

The arctan(\cdot) has a phase ambiguity due the division of \text{IM}\{c\}/\text{RE}\{c\}. For example, the same angle is calculated when c = 1+j and c = -1-j,

(14)   \begin{equation*}\begin{split}\sphericalangle (1+j) & = \text{arctan}( j/1 ) \\& = \pi/4,\end{split}\end{equation*}

(15)   \begin{equation*}\begin{split}\sphericalangle(-1-j) & = \text{arctan} (-j/-1) \\& = \text{arctan}( j/1) \\& = \pi/4,\end{split}\end{equation*}

although visually it can be seen in Figure 3 that the angles are not the same.

Figure 3: The arctan() has a phase ambiguity in which 1+j and -1-j are calculated to have the same angle, but have different angular distances from 0 degrees.
Figure 3: The arctan() has a phase ambiguity in which 1+j and -1-j are calculated to have the same angle, but have different angular distances from 0 degrees.

The phase ambiguity is resolved in software by treating the real and imaginary components as separate inputs as in MATLAB’s atan2() function or NumPy’s arctan2(). For example, using arctan2() is given in the following code snippet:

import numpy as np
c = 1 + 1j
print( np.arctan2( np.imag(c), np.real(c) ) )
c = -1 - 1j
print( np.arctan2( np.imag(c), np.real(c) ) )

By convention the angle is measured from 0 degrees, and therefore

(16)   \begin{equation*}-\pi \le \sphericalangle c < \pi.\end{equation*}

An example of angles plotted on [-\pi, \pi] is given in Figure 4.

Figure 4: An example of angles between -pi and pi.
Figure 4: An example of angles between -pi and pi.

The angle is periodic in 2\pi,

(17)   \begin{equation*}\sphericalangle c = \sphericalangle c + 2\pi,\end{equation*}

and may also be represented by

(18)   \begin{equation*}0 \le \sphericalangle c < 2\pi.\end{equation*}

An example of angles plotted on [0, 2\pi] is given in Figure 5.

Figure 5: An example of angles between 0 and 2pi.
Figure 5: An example of angles between 0 and 2pi.

Polar

Polar form is most commonly used mathematically (pen and paper) due to its simplified multiplication. Almost all useful DSP functions require complex multiplication and therefore the polar form is the most common when working through the mathematics manually.

The polar form of complex number c given by

(19)   \begin{equation*}c = A e^{j \phi}\end{equation*}

where A is the amplitude and \phi is the phase. The complex number c = a + jb can be represented in polar form by

(20)   \begin{equation*}\begin{split}c & = |c| e^{j \sphericalangle c} \\& = \sqrt{a^2 + b^2} e^{j \text{arctan}(b/a) }.\end{split}\end{equation*}

Conjugation

Conjugation (\cdot)^* negates the imaginary element of a complex number such that

(21)   \begin{equation*}c^* = \text{RE}\{ c \} - j\cdot\text{IM}\{ c \}.\end{equation*}

For c = a + jb, the conjugate is given by

(22)   \begin{equation*}c^* = a - jb.\end{equation*}

Conjugation is also the mirroring of c across the imaginary axis. Figure 6 gives an example of a complex number and it’s conjugate in the complex domain.

Figure 6: The conjugation operation * negates the imaginary component of a complex number, mirroring it across the imaginary axis.
Figure 6: The conjugation operation * negates the imaginary component of a complex number, mirroring it across the imaginary axis.

The conjugation operation does not effect the magnitude of a complex number c = a + jb,

(23)   \begin{equation*}\begin{split}|c^*| = & |a - jb| \\& = \sqrt{a^2 + b^2} \\& = |c|.\end{split}\end{equation*}

Conjugation negates the angle of a complex number,

(24)   \begin{equation*}\begin{split}\sphericalangle{c^*} = -\sphericalangle{c}.\end{split}\end{equation*}

Addition

The addition of complex numbers c and z,

(25)   \begin{equation*}c = a + jb,\end{equation*}

(26)   \begin{equation*}z = x + jy.\end{equation*}

is given by

(27)   \begin{equation*}c + z = (a + x) + j(b + y).\end{equation*}

The addition of complex numbers is most easily done with Cartesian form rather than polar form. Adding complex numbers sums the real and imaginary portions separately (as they are orthogonal to one another) which can be visualized in Figure 7.

Figure 7: An example of the addition of two complex numbers.
Figure 7: An example of the addition of two complex numbers.

Multiplication

The multiplication of complex numbers c and z,

(28)   \begin{equation*}c = a + jb,\end{equation*}

(29)   \begin{equation*}z = x + jy.\end{equation*}

is given by

(30)   \begin{equation*}\begin{split}c \cdot z & = (a + jb) \cdot (x + jy) \\& = a(x + jy) + jb(x + jy) \\& = ax + jay + bxj + byj^2 \\& = (ax - by) + j(bx + by).\end{split}\end{equation*}

The multiplication of (30) is clunky due to the distribution of the multiplication across multiple terms and can be simplified by converting both terms to polar first.

The multiplication of two complex numbers c = |c| e^{j \sphericalangle{c}} and z = |z| e^{j \sphericalangle{z}} is given by

(31)   \begin{equation*}c \cdot z = |c| |z| e^{j \left( \sphericalangle{c} + \sphericalangle{z} \right)}.\end{equation*}

Figure 8 gives an example for c = 2e^{j\pi/3} and z = 1.5e^{-j\pi/2} where c \cdot z = 3e^{-j\pi/6}.

Figure 8: An example of multiplying two complex numbers. The magnitudes are multiplied and their phases summed.
Figure 8: An example of multiplying two complex numbers. The magnitudes are multiplied and their phases summed.

Conclusion

Complex mathematics can be confusing, I know it was for me when first starting out in my career. Understanding how to apply the rules of complex math in the classroom allowed me to experiment and apply those rules to building DSP algorithms in the laboratory. Over the course of many years I was able to develop intuition about complex mathematics that allows for the development of new algorithms. But it all started by being comfortable in my uncomfortableness of not completely understanding why they all worked, but knowing enough to be able to apply the mathematics.

Check out more posts on complex numbers:

Leave a Reply

God, the Lord, is my strength; He makes my feet like the deer's; He makes me tread on my high places. Habakkuk 3:19
For everything there is a season, and a time for every matter under heaven. A time to cast away stones, and a time to gather stones together. A time to embrace, and a time to refrain from embracing. Ecclesiastes 3:1,5
The earth was without form and void, and darkness was over the face of the deep. And the Spirit of God was hovering over the face of the waters. Genesis 1:2
Behold, I am toward God as you are; I too was pinched off from a piece of clay. Job 33:6
Enter His gates with thanksgiving, and His courts with praise! Give thanks to Him; bless His name! Psalm 100:4
Lift up your hands to the holy place and bless the Lord! Psalm 134:2
Blessed is the man who trusts in the Lord, whose trust is the Lord. He is like a tree planted by water, that sends out its roots by the stream, and does not fear when heat comes, for its leaves remain green, and is not anxious in the year of drought, for it does not cease to bear fruit. Jeremiah 17:7-8
He said to him, “You shall love the Lord your God with all your heart and with all your soul and with all your mind. This is the great and first commandment. And a second is like it: You shall love your neighbor as yourself. On these two commandments depend all the Law and the Prophets.” Matthew 22:37-39
Then He said to me, “Prophesy over these bones, and say to them, O dry bones, hear the word of the Lord. Thus says the Lord God to these bones: Behold, I will cause breath to enter you, and you shall live." Ezekiel 37:4-5
Riches do not profit in the day of wrath, but righteousness delivers from death. Proverbs 11:4
The angel of the Lord appeared to him in a flame of fire out of the midst of a bush. He looked, and behold, the bush was burning, yet it was not consumed. And Moses said, “I will turn aside to see this great sight, why the bush is not burned.” When the Lord saw that he turned aside to see, God called to him out of the bush, “Moses, Moses!” And he said, “Here I am.” Exodus 3:2-3
Daniel answered and said: “Blessed be the name of God forever and ever, to whom belong wisdom and might. He changes times and seasons; He removes kings and sets up kings; He gives wisdom to the wise and knowledge to those who have understanding." Daniel 2:20-21
Previous slide
Next slide

This website participates in the Amazon Associates program. As an Amazon Associate I earn from qualifying purchases.

© 2021-2024 Wave Walker DSP