# Angle Addition Formulas from Euler's Formula

__Introduction__

This is an article to hopefully give a better understanding of the Discrete Fourier Transform (DFT), but only indirectly. The main intent is to get someone who is uncomfortable with complex numbers a little more used to them and relate them back to already known Trigonometric relationships done in Real values. It is essentially a followup to my first blog article "The Exponential Nature of the Complex Unit Circle".

__Polar Coordinates__

The more common way of specifying the location of a point on a plane is using Cartesian coordinates. They are expressed as a pair of real values like $(x,y)$ where the $x$ indicates (by convention) the distance along the horizontal axis of a pair of orthogonal axes. The $y$ value indicates the distance along the vertical axis. The point can be located by either moving along the horizontal axis by $x$ units, and then vertically by $y$ units. Or the other way around. In either case you end up at the same point. In Cartesian coordinates the representation of the point is unique. That means if $(a,b)$ and $(x,y)$ refer to the same point, $x=a$ and $y=b$.

Polar coordinates are different. They specify a point by giving the distance to the origin and the angle of the line segment joining the origin to the point and the horizontal axis. An angle of zero is towards the right, and an angle of 180 degrees, or $\pi$ radians is to the left. 90 degrees, or $\pi/2$ radians is upward. This is also by convention. They are also specified as a coordinate pair, often called $(r,\theta)$.

The first thing to notice is that if the distance to the origin, also called the radius, is zero, then the angle value is meaningless. The second thing to notice is that the representation of a point is not unique. You can negate $r$ and add $\pi$ to the angle and get back to the same point. Or you can add or subtract any multiple of $2\pi$ to the angle and still be referring to the same point.

__Polar to Cartesian Conversion and Back__

From here on in, all angles are assumed to be in radians. If these equations aren't familiar to you, do a search on "Polar to Cartesian" and you will find plenty of reference material. Or you can plot a point in the first quadrant, drop a line segment to the x axis and one to the origin and use your basic Trigonometric definitions. $$ x = r \cdot \cos( \theta ) \tag {1} $$ $$ y = r \cdot \sin( \theta ) \tag {2} $$ The inverse equations can be solved for like this: $$ \begin{aligned} x^2 + y^2 &= r^2 \cdot \cos^2( \theta ) + r^2 \cdot \sin^2( \theta ) \\ &= r^2 \cdot ( \cos^2( \theta ) + \sin^2( \theta ) ) \\ &= r^2 \end{aligned} \tag {3} $$ $$ r = \sqrt{ x^2 + y^2 } \tag {4} $$ By convention, the principal root (the positive one) is chosen. Finding the angle goes like this: $$ \frac{y}{x} = \frac{r \cdot \sin( \theta )}{r \cdot \cos( \theta )} = \tan( \theta ) \tag {5} $$ So you would think: $$ \theta = \tan^{-1} \left( \frac{y}{x} \right) \tag {6} $$ But not so fast. There is a problem dealing with the different quadrants: $(-x,-y)$ will give the same answer as $(x,y)$ though they are clearly $\pi$ radians apart, also known as opposite each other. You can solve this with additional tests, which means "if" statements when programming, or you can use a special function called "atan2". Most programming languages and spreadsheets support such a function though it's name might be slightly different. $$ \theta = \text{atan2} \left( y , x \right) \tag {7} $$ This function takes care of the quadrant locations and returns the correct angle.

__Imaginary Numbers and the Complex Plane__

An imaginary number is a real scalar multiplied by the $\sqrt{-1}$. It's impossible to take the square root of a negative number, you protest. A negative times a negative is positive, and a positive times a positive is also a positive. So how can I multiply something times something and get a negative number? Answer: It takes an imaginary number to do that. As in, "imagine a number that can", not that they don't exist. Well, as much as any Mathematical concept exists. Any such number can have the $\sqrt{-1}$ factored out and then it becomes an ordinary real number. The $\sqrt{-1}$ is usually designated as $i$ by mathematicians and $j$ by electrical engineers. It is not an American/European thing as I said in my first article. This, and all my articles use $i$.

A complex number is the sum of a real number and an imaginary number. So, if $x$ and $y$ are both real, then $x + i y$ is a complex number. It could also be expressed as $x + y i $ since multiplication is commutative. Also by convention, the real part is written before the imaginary part.

The complex plane is a representation of the full set of possible complex numbers. The horizontal axis is used for the real part and the vertical axis is used for the imaginary part. Thus, the point corresponding to the complex number $ x+ i y $ is $(x,y)$ on the plane. Very often the variable $z$ is used to denote a complex number.

Now, let's convert that point to polar coordinates: $$ z = x + i y = r \cos( \theta ) + i r \sin( \theta ) = r \left[ \cos( \theta ) + i \sin( \theta ) \right] \tag {8} $$ That wasn't so hard.

__Euler's Formula__

Now, it's time to bring in Euler's formula, which is: $$ e^{i\theta} = \cos( \theta ) + i \cdot \sin( \theta ) \tag {9} $$ Look at that, the right hand side is just like the polar form of the complex number given in (8). Substituting it in: $$ z = x + i y = r \cdot e^{i\theta} \tag {10} $$ There is the crux of it. Euler's formula is essentially the conversion of polar coordinates to Cartesian coordinates of a complex number. What is remarkable is that the conversion is actually a genuine exponentiation. A fact that will be exploited for the purposes of this article.

The proper mathematical name for finding the angle of a complex number is "arg", as in: $$ \theta = \arg( x + iy ) \tag {11} $$ This is what you should use when doing math. It is also supported in some computing platforms. You may also find it called "angle". When $r>0$, Euler's formula shows it can also be expressed as: $$ \begin{aligned} z &= x + i y = r \cdot e^{i\theta} \\ \ln( z ) &= \ln( x + i y ) = \ln(r) + i \theta \\ \theta &= \frac{ ln( x + i y ) - ln( r ) }{i} = -i \ln \left( \frac{x+iy}{r} \right) = -i \ln \left( \frac{x+iy}{ \sqrt{x^2+y^2} } \right) \end{aligned} \tag {12} $$ This is the complex version of the natural log, which can get confusing so the "arg" name is the preferred one.

Finding the magnitude of a complex value, which is the length of the radius, is expressed mathematically as: $$ \| z \| = \sqrt{ x^2 + y^2 } = | r | \tag {13} $$ The double absolute value bars stand for the magnitude of a complex number, while the single absolute value bars are for real values. That's in math. In programming the magnitude is often implemented as "Abs" with no distinction being made.

__Angle Addition Formulas for Sine and Cosine__

Let's simplify things by setting $r=1$. Now suppose that $\alpha$ and $\beta$ are two real valued angle measurements. Then: $$ \begin{aligned} e^{i(\alpha + \beta)} &= e^{i\alpha} \cdot e^{i\beta} \\ &= \left[ \cos( \alpha ) + i \sin( \alpha ) \right] \cdot \left[ \cos( \beta ) + i \sin( \beta ) \right] \end{aligned} \tag {14} $$ Let's take a moment and see what happens when we multiply two complex numbers. $$ \begin{aligned} ( a + i b ) ( c + i d ) &= a ( c + i d ) + i b ( c + i d ) \\ &= a c + i a d + i b c + i^2 b d \\ &= ( a c - b d ) + i ( a d + b c ) \\ \end{aligned} \tag {15} $$ Notice that the $i^2$ becomes $-1$. Applying the same steps to (14) results in: $$ \begin{aligned} e^{i(\alpha + \beta)} &= \left[ \cos( \alpha ) + i \sin( \alpha ) \right] \cdot \left[ \cos( \beta ) + i \sin( \beta ) \right] \\ &= \left[ \cos( \alpha ) \cos( \beta ) - \sin( \alpha ) \sin( \beta ) \right ] \\ &+ i \left[ \cos( \alpha ) \sin( \beta ) + \sin( \alpha ) \cos( \beta ) \right ] \end{aligned} \tag {16} $$ But, this is also true from Euler's formula: $$ \begin{aligned} e^{i(\alpha + \beta)} &= \cos( \alpha + \beta ) + i \cdot \sin( \alpha + \beta ) \end{aligned} \tag {17} $$ The right hand side are the Cartesian coordinates. Remember the uniqueness of Cartesian representation? This means that: $$ \cos( \alpha + \beta ) = \cos( \alpha ) \cos( \beta ) - \sin( \alpha ) \sin( \beta ) \tag {18} $$ And: $$ \sin( \alpha + \beta ) = \cos( \alpha ) \sin( \beta ) + \sin( \alpha ) \cos( \beta ) \tag {19} $$ Those are your angle addition formulas for Sine and Cosine. Pretty neat, huh?

__Circular Dependencies__

It is important to note that this is not a derivation of these formulas, merely a confirmation. The derivation chain goes like this.

1) Cosine angle addition formula from distances on the unit circle

2) Sine angle addition formula from the cosine formula

3) Derivatives of Sine and Cosine from the angle addition formulas and limits

4) Taylor series for Sine and Cosine from the Derivatives

5) Euler's formula from Taylor series

6) Cosine and Sine angle addition formulas from Euler's formula

There is no "7) Goto 3".

__Multiplying Two Complex Numbers Polar Style__

Suppose we have $z_1$, $z_2$, and $z_3$ where the last one is the product of the first two. $$ z_3 = z_1 \cdot z_2 \tag {20} $$ You may have heard the rule: "When you multiply two complex numbers the angles are added and the magnitudes are multiplied." First, let's prove it: $$ \begin{aligned} r_3 e^{i \theta_3 } &= r_1 e^{i \theta_1 } \cdot r_2 e^{i \theta_2 } \\ &= r_1 r_2 \cdot e^{i (\theta_1 + \theta_2) } \end{aligned} \tag {21} $$ Now, let's see if it really works. (Have you any doubts?)

Let $z_1 = 3 + i 4$ and $z_2 = 5 + i 12$. $$ z_1 \cdot z_2 = ( 15 - 48 ) + i ( 36 + 20 ) = -33 + i 56 = z_3 \tag {22} $$ $$ \begin{aligned} \| z_1 \| &= \sqrt{ 3^2 + 4^2 } = \sqrt{ 9 + 16 } = \sqrt{ 25 } = 5 \\ \| z_2 \| &= \sqrt{ 5^2 + 12^2 } = \sqrt{ 25 + 144 } = \sqrt{ 169 } = 13 \\ \| z_3 \| &= \sqrt{ (-33)^2 + 56^2 } = \sqrt{ 1089 + 3136 } = \sqrt{ 4225 } = 65 \\ \end{aligned} \tag {23} $$ Yeah, I picked Pythagorean triples for $z_1$ and $z_2$ to make the numbers come out nice. But look, the result is also a Pythagorean triple. The mind boggles. Back to the verification. $ 5 \cdot 13 = 65 $. Check.

Now let's look at the angles, they aren't so clean. Here is a little Gambas code to do the calculations:

Dim z1, z2, z3 As Complex z1 = 3 + 4i z2 = 5 + 12i z3 = z1 * z2 Print "|z1| = "; Abs(z1) Print "|z2| = "; Abs(z2) Print "|z3| = "; Abs(z3) Print Print "arg(z1) = "; z1.Arg(), Deg(z1.Arg()) Print "arg(z2) = "; z2.Arg(), Deg(z2.Arg()) Print "arg(z3) = "; z3.Arg(), Deg(z3.Arg()) Print Print "z3 = "; z3 Print Print "atan2( 4, 3) = "; ATan2(4, 3) Print "atan2(12, 5) = "; ATan2(12, 5) Print "atan2(56,-33) = "; ATan2(56, -33)And these are the results:

|z1| = 5 |z2| = 13 |z3| = 65 arg(z1) = 0.92729521800161 53.130102354156 arg(z2) = 1.17600520709514 67.3801350519596 arg(z3) = 2.10330042509675 120.510237406116 z3 = -33+56i atan2( 4, 3) = 0.92729521800161 atan2(12, 5) = 1.17600520709514 atan2(56,-33) = 2.10330042509675It doesn't matter whether radians or degrees, the angles still add up.

__Conclusion__

This article should have made you more comfortable with complex numbers and their representation in both Cartesian and Polar form. These concepts are essential to understanding many DSP concepts and the DFT (Discrete Fourier Transform) in particular. The phrase "One complex number can be rotated by multiplying it by another" should make sense. If it doesn't, reread the article and play around with numbers until it does.

__A Dedication__

This article is dedicated to a certain Miss MB, who obviously never heeded "Girls aren't supposed to like math." You go, girl!

__About Gambas__

Gambas is a Linux based (as of this writing) dialect of BASIC development platform, loosely based on (but a huge improvement over) Microsoft's VB5 and VB6. I encourage all programmers, novice to expert, to check it out.

Technical details:

The version in my distro (3.1.1) is way out of date. The latest is 3.12.2

PPA: gambas-team/gambas3

__References__

[1] Dawg, Cedron, The Exponential Nature of the Complex Unit Circle

- Comments
- Write a Comment Select to add a comment

Hi Cedron. In your Polar Coordinates section you wrote: "You can negate r and add π to the angle and get back to the same point." Is it possible to have a negative-valued radius in polar coordinates?

I think it is considered in bad form to leave a value like that. Similar to how $\frac{1}{\sqrt{2}}$ should be converted to $\frac{\sqrt{2}}{2}$ and $\frac{1}{1+i}$ should be converted to $\frac{1-i}{2}$.

But for sure (I resisted saying "Absolutely"), otherwise you couldn't say things like: "What does the graph of $ r = \sin( \theta ) $ look like?"

The essence of the article is (15) and (16) as a way to remember the angle addition formulas in a clutch. You can also think:$$ real = real \cdot real - imag \cdot imag $$ $$ imag = real \cdot imag + imag \cdot real $$

You can also note that $ r = \text{sgn}( x ) \cdot \sqrt{ x^2 + y^2 } $ solves the $ \tan^{-1} $ quandary (Added: You still have to deal with $x=0$ separately).

Ced

Hi Cedron. Your March 17 reply makes me think I didn't ask my question is a clear enough way. My question, in different words, is: "If I have a complex number represented in polar form, is it possible for the radius of that polar-form number to be negative?"

Sure $(-1, \pi/2) $ is just as valid as $( 1, 3\pi/2)$ for the same point.

In order to achieve uniqueness in representation, the typical restriction is $ r > 0 $ and $ 0 <= \theta < 2 \pi $ and if $r=0$ make $\theta=0$. In which case the latter one is the "correct" one.

Does that clarify it?

Hi Cedron.

In your last March 17 reply you seem to be saying that a complex number, represented in polar form, can have a negative-valued magnitude. But it seems to me that your Eq. (13) specifies that all complex number magnitudes be positive-only in value.

If a complex number's magnitude represents a "length" on the complex plane, I'm trying to figure out what on earth does a "negative length" mean.

Hi Rick,

For polar coordinates, think of the "r" value as lying on a "r-axis", which is rotated by "$\theta$" radians (or degrees, if you are using that). So you can think of the $\theta$-axis as being wrapped around the unit circle. There is no problem having a negative value for "r" in this situation, and its meaning is clear. Under (4), I specifically state that "r" is chosen as positive by convention. If you choose the negative root, then the appropriate $\theta$ has to be chosen as well.

Magnitudes, on the other hand, are a distance measurement and are therefore non-negative. So, when you calculate the magnitude and arg of a complex number, they can be interpreted as (mapped to) polar coordinates, but they are not the same thing.

"r" is not always a magnitude though. Changing the name of the variable to make the point clearer:

$$ z = k e^{i \theta} = -k e^{i (\theta + \pi)} $$

Indeed, any multiple of $i2\pi$ could be added in the exponent on either side and the equation will still be true. All refer to the same point on the complex plane. There is no restriction that says the scalar has to be positive.

In this case, I don't know whether k is positive, negative, or zero. That's why the absolute value bars are there around "r" in (14), and for this example:

$$ \|z\| = |k| $$

Due to the lack of uniqueness, when the cartesion form ($x+iy$) is converted to the polar form($re^{i\theta}$) by the equations given in the article, it is "a" conversion, not "the" conversion, and "r" is chosen to be positive by convention, and "$\theta$" as the angle to a positive "r".

Equation 12 doesn't disregard the real part of the logarithm; shouldn't it be $\operatorname{Im} \ln (x+iy)$ ?

Good catch, thanks. I fixed it slightly differently and kept it all under (12) so as to not disturb the numbering.

To post reply to a comment, click on the 'reply' button attached to each comment. To post a new comment (not a reply to a comment) check out the 'Write a Comment' tab at the top of the comments.

Registering will allow you to participate to the forums on ALL the related sites and give you access to all pdf downloads.