Sign in

username:

password:



Not a member?

Search Online Books



Search tips

Free Online Books

Ads

Chapters

Chapter Contents:

Search Mathematics of the DFT

  

Book Index | Global Index


Would you like to be notified by email when Julius Orion Smith III publishes a new entry into his blog?

  

Complex Number Manipulation

Let's run through a few elementary manipulations of complex numbers in Matlab:

>> x = 1; 
>> y = 2;
>> z = x + j * y

z =
   1 + 2i

>> 1/z

ans =
   0.2 - 0.4i

>> z^2

ans =
  -3 + 4i

>> conj(z)

ans =
   1 - 2i

>> z*conj(z)

ans =
     5

>> abs(z)^2

ans =
    5

>> norm(z)^2

ans =
    5

>> angle(z)

ans =
    1.1071

Now let's do polar form:

>> r = abs(z)

r =
    2.2361

>> theta = angle(z)

theta =
    1.1071

Curiously, $ e$ is not defined by default in Matlab (though it is in Octave). It can easily be computed in Matlab as e=exp(1).

Below are some examples involving imaginary exponentials:

>> r * exp(j * theta)

ans =
   1 + 2i

>> z

z =
   1 + 2i

>> z/abs(z)

ans =
   0.4472 + 0.8944i

>> exp(j*theta)

ans =
   0.4472 + 0.8944i

>> z/conj(z)

ans =
  -0.6 + 0.8i

>> exp(2*j*theta)

ans =
  -0.6 + 0.8i

>> imag(log(z/abs(z)))

ans =
    1.1071

>> theta

theta =
    1.1071

>>
Here are some manipulations involving two complex numbers:
>> x1 = 1;
>> x2 = 2;
>> y1 = 3;
>> y2 = 4;
>> z1 = x1 + j * y1;
>> z2 = x2 + j * y2;
>> z1

z1 =
   1 + 3i

>> z2

z2 =
   2 + 4i

>> z1*z2

ans =
 -10 +10i

>> z1/z2

ans =
   0.7 + 0.1i

Another thing to note about matlab syntax is that the transpose operator ' (for vectors and matrices) conjugates as well as transposes. Use .' to transpose without conjugation:

>>x = [1:4]*j

x =
        0 + 1i   0 + 2i   0 + 3i   0 + 4i

>> x'

ans =
        0 - 1i
        0 - 2i
        0 - 3i
        0 - 4i

>> x.'

ans =
        0 + 1i
        0 + 2i
        0 + 3i
        0 + 4i


Order a Hardcopy of Mathematics of the DFT

Previous: Complex Numbers in Matlab and Octave
Next: Factoring Polynomials in Matlab

written by Julius Orion Smith III
Julius Smith's background is in electrical engineering (BS Rice 1975, PhD Stanford 1983). He is presently Professor of Music and Associate Professor (by courtesy) of Electrical Engineering at Stanford's Center for Computer Research in Music and Acoustics (CCRMA), teaching courses and pursuing research related to signal processing applied to music and audio systems. See http://ccrma.stanford.edu/~jos/ for details.


Comments


No comments yet for this page


Add a Comment
You need to login before you can post a comment (best way to prevent spam). ( Not a member? )