Vous êtes sur la page 1sur 29

Chapter SIX

(For ECE 115)

Complex Numbers and Applications

Roland Priemer
University of Illinois at Chicago

The complex number is a very useful and important concept in many fields of science and engineering
and especially in almost all areas of electrical engineering. An important distinguishing feature of
MATLAB is its ability to work with the complex data type. In this chapter you will learn about the origin
of complex numbers, how MATLAB can to do arithmetic with complex numbers and how complex
numbers provide a convenient mechanism for representing signals and for system analysis.
Equation Chapter 6 Section 1

6.1 Origin of Complex Numbers

Complex numbers were invented as a resolution of the dilemma that can arise when we want to find the
solution or roots of
f ( x)  a x 2  b x  c  0 (6.1)

where a , b and c are real numbers and f ( x) is a second order polynomial in x .

Assuming that a is not zero, (6.1) can be written as

b c
x2  x  0
a a

 2a 
2
and adding and subtracting b gives
2 2
b  b   b  c
x  x    
2
 0
a  2a   2a  a

This equation can be written as


b2  4 a c
2 2
 b   b  c
 x        (6.2)
 2a   2a  a 4 a2

The steps from (6.1) to (6.2) are called completing the square. Taking the square root of both sides of
(6.2) yields
b b2  4 a c b  b 2  4 a c
x   (6.3)
2a 4 a2 2a
The formula in (6.3) gives the two solutions of (6.1).

The factor, b 2  4 a c , is called the discriminant, and it may be positive, in which case there are
two distinct real roots of (6.1). If the discriminant is zero, then there are two real and equal roots.
Denote the two roots by x1 and x2 , and we can write the polynomial f ( x) as a product of two first
order factors given by
f ( x)  a ( x  x1 ) ( x  x2 )  a ( x 2  ( x1  x2 ) x  x1 x2 )

If the discriminant is negative, can we still write f ( x) as a product of two first order factors? In this
case, let us write (6.3) as

b  b 2  4 a c b  (1)(4 a c  b 2 ) b  1 4 a c  b 2
x  
2a 2a 2a

Since 1 cannot have a real value, it is taken into account with a symbol, such as

j  1 (6.4)

and j 2   1 . Therefore, if the discriminant is negative, then the two roots of (6.1) are given by

b  j 4 a c  b 2
x  (6.5)
2a

and x is called a complex number.

In general, a complex number x is given by

x    j (6.6)

where  , a real number, is called the real part of x , denoted by   Re( x ) , and  , a real number, is
called the imaginary part of x , denoted by   Im( x) . This way of writing a complex number is called
the rectangular form. The set of all complex numbers is denoted by  . A complex number can be a
real number, in which case the imaginary part is zero, and a complex number can be an imaginary
number, in which case the real part is zero. A common operation on a complex number is to change the
sign of the imaginary part. If two complex numbers differ only in the sign of their imaginary parts, then
these two numbers are said to be complex conjugates of each other. The complex conjugate of x in
(6.6) is denoted by x* , and it is given by

x*  (  j  )*    j  (6.7)

 
*
Notice that x*  x . Also notice that the two complex zeros given by (6.5) of a quadratic polynomial
with real coefficients occur as a complex conjugate pair. Let us obtain the product of two first order
factors using a pair of complex conjugate roots to get
( x  (  j  ))( x  (  j  ))  x 2  x  jx   x   2  j  j  x  j    2
 x 2  2 x  ( 2   2 )

As for real roots, the result is a polynomial with real coefficients.

Example 6.1. Let us find the roots of (6.1) for some specific cases.

a) Let a  2 , b   2 and c   12 . With (6.3) we get

2  4  96 2  10
x   3,  2
4 4

Let x1 and x2 denote the roots obtained with the plus sign and minus sign, respectively. Therefore,
x1  3 and x2   2 . With the roots, we can factor the second order polynomial into a product of
two first order factors given by

f ( x)  2 x 2  2 x  12  2 ( x  x1 ) ( x  x2 )  2( x  3)( x  2)

Since x  x1 and x  x2 make f ( x) equal zero, x1 and x2 are called the zeros of f ( x) .

80

60

40
y

20

-20
-6 -4 -2 0 2 4 6 8
x
Figure 6.1. Plot of a quadratic function that has two real zeros.

For another point of view, let us plot f ( x) versus x , which is shown in Figure 6.1. Here we see
that the real zeros of a polynomial are the values of x where the polynomial crosses the abscissa, the x-
axis, where y  0 . The MATLAB program that was used to obtain the plot in Fig. 6.1 is given in
Program 6.1.

% MATLAB program to plot a quadratic function of the form


% y = f(x) = a x^2 + b x + c
% versus x
clear all; clc;
a = 2.0; b = -2.0; c = -12.0; % specifying coefficients
x_begin = -6.0; % specifying the first value of x
x_end = +7.0; % specifying the last value of x
N = 101; % specifying the number of points to be plotted
% using a built in MATLAB function to specify a vector of points
x = linspace(x_begin,x_end,N);
y = a*x.*x + b*x + c; % using element by element multiply
plot(x,y)
grid on
xlabel('x')
ylabel('y')

Program 6.1. MATLAB program to plot a quadratic function of x.

b) Let a 1 , b  2 and c  5 . With (6.3) we get


2  4  20 2  4 1
x    1  j 2,  1  j 2
2 2

where the symbol j is used to mean 1 . Let us verify that x1   1  j 2 and x2   1  j 2 are the
zeros of f ( x) . With x  x1 we get

x12  2 x1  5  (1  j 2)( 1  j 2)  2( 1  j 2)  5


1  j 2  j 2  ( j 2)( j 2)  2  j 4  5
1  j 4  4  2  j 4  5  0

Similarly, we can verify that x2 is a zero of f ( x) . As with real zeros of f ( x) , f ( x) can be factored
into a product of two first order factors given by

f ( x)  ( x  x1 ) ( x  x2 )  ( x  1  j 2)( x  1  j 2)
 x 2  x  j 2 x  x  1  j 2  j 2 x  j 2  ( j 2)( j 2)
 x2  2x  5

Figure 6.2 shows f ( x) versus x, and we see that f ( x) does not cross the abscissa, because it has
complex zeros.

150

100
y

50

0
-10 -5 0 5 10
x

Fig. 6.2. Plot of a quadratic function that has a pair of complex conjugate zeros.
___________
6.2 Rectangular Form and Complex Arithmetic

Arithmetic with complex numbers is similar to arithmetic with real numbers. Let x1  1  j 1 and
x2   2  j  2 be two complex numbers. Table 6.1 lists several arithmetic properties.

Table 6.1. Properties of rectangular form complex numbers and arithmetic


equal x1  x2 , if 1   2 and 1   2
addition x1  x2  (1   2 )  j ( 1   2 )
subtraction x1  x2  (1   2 )  j ( 1   2 )
multiplication x1 x2  (1  j 1 )( 2  j  2 )  (1 2  1 2 )  j (1 2  1 2 )

x1 x1 x2* (  j 1 )( 2  j  2 ) 1 2  1 2     


  1   j 1 2 2 21 2
division x2 x2 x2 ( 2  j  2 )( 2  j  2 )
*
 2  2
2 2
 2  2
conjugation x 
*
x*
( x1  x2 )  x  x , ( x1 x2 )  x x and  1   1*
* *
1
*
2
* *
1
*
2
 x2  x2

polynomial with f * ( x)  f ( x* ) , for x    j 


real coefficients

In MATLAB it is very easy to work with complex numbers. MATLAB uses the symbols I or j for
1 .

Example 6.2. Using the MATLAB command window, the following statements demonstrate how
convenient it is to use MATLAB for work with complex numbers written in rectangular form.

>> clear all


>> a=j*2 % a is a purely imaginary number
a=
0 + 2.0000i
>> % MATLAB replaces the symbol j with the symbol i
>> b=2-j*3
b=
2.0000 - 3.0000i
>> c=a+b % MATLAB follows the rules of arithmetic given in Table 6.1
c=
2.0000 - 1.0000i
>> d=c*j % this is a multiplication
d=
1.0000 + 2.0000i
MATLAB has several built in functions that work with complex numbers. The following statements
demonstrate some of these functions.

>> e=complex(2,3) % built in MATLAB function complex assigns a complex number to e


e=
2.0000 + 3.0000i
>> f=isreal(e) % built in function isreal checks if e is real, and then sets f to a logic value
f=
0
>> g=conj(e) % built in function conj takes the complex conjugate
g=
2.0000 - 3.0000i
>> h=real(g) % built in function real gets the real part
h=
2
>> p=imag(g) % built in function imag gets the imaginary part
p=
-3
>> q=d/e % division with complex numbers
q=
0.6154 + 0.0769i
>> r=(d*conj(e))/(e*conj(e)) % the denominator is made a real number
r=
0.6154 + 0.0769i
>> % a complex number multiplied by its complex conjugate always produces
>> % a real number
>>

In MATLAB, complex numbers can be elements of matrices. The following statements illustrate some of
the possibilities.

>> clear all


>> A=[j j*2*(1+j) -1+2*j] % the vector A has 3 complex elements
A=
0 + 1.0000i -2.0000 + 2.0000i -1.0000 + 2.0000i
>> A(2) % obtain the second element in the vector
ans =
-2.0000 + 2.0000i
>> % the transpose operation of a complex matrix includes conjugating every element
>> B=[-1 -2+j*2 4-j*5]' % B becomes a column vector
B=
-1.0000
-2.0000 - 2.0000i
4.0000 + 5.0000i
>> c=conj(A)*B % element by element conjugate and then matrix multiply
c=
-11.000 + 6.0000i
>> d=A.*conj(A) % each element of A is multiplied by its complex conjugate
d=
1 8 5
>>
__________

Example 6.3. In this example we will use a MATLAB program to apply the formula given by (6.3). Most
of the programs that we will write serve to illustrate various MATLAB features and operations.
However, when we write an application program that is intended to be used by others or the program
writer at a later time, it is useful to document the program such that its purpose and methods can be
easily determined. The following MATLAB program illustrates preferred program organization. While
we cannot assure with certainty that a program cannot fail, we must always strive to write programs
that provide the user an opportunity to test for the proper functioning of the program and a means to
terminate the program within the program development environment.

%
% EXAMPLE OF PROGRAM ORGANIZATION
%
% Program calc_roots.m
%
% Purpose:
% This program solves for the roots of a quadratic equation
% of the form: a*x^2 + b*x +c = 0. It finds real roots
% and complex roots of the equation.
%
% Program information
% Date Programmer Description
% 2/22/09 R. Priemer Original code, version 1.0
%
% Define variables
% a --coefficient of x^2 term
% b --coefficient of x term
% c --constant term
% disc --discriminant
% i_part --imaginary part
% r_part --real part
% x1 --first root
% x2 --second root
%
clear all; clc;
disp('This program solves for the roots of a quadratic equation');
disp('of the form: a*x^2 + b*x + c = 0.');
disp('To terminate this program,');
disp('enter zero when prompted for the coefficient a');
while 1 % this causes the while loop to execute endlessly
% Prompt user for equation coefficients
a=input('Enter the coefficient a: ');
if a == 0.0
break % user has terminated the while loop and the program
end
b=input('Enter the coefficient b: ');
c=input('Enter the coefficient c: ');
% Find the discriminant
disc=b^2-4*a*c;
% Check the discriminant
if disc > 0 % There are two real roots
d=sqrt(disc);
x1=(-b+d)/(2*a); % first root
x2=(-b-d)/(2*a); % second root
disp('The equation has two real roots:');
fprintf('x1= %f\n', x1); % Using floating point formatted print
fprintf('x2= %f\n', x2);
elseif disc == 0 % There are two real roots
x1=(-b)/(2*a); % x2 = x1
disp('The equation has two repeated real roots:');
fprintf('x1=x2= %f\n', x1);
else % There are two complex conjugate roots
r_part=(-b)/(2*a);
i_part=sqrt(abs(disc))/(2*a);
disp('The equation has two complex conjugate roots:');
fprintf('x1= %f +j %f\n', r_part, i_part);
fprintf('x2= %f -j %f\n', r_part, i_part);
end
end
disp('Program terminated');

Program 6.2. Program to find the roots of a quadratic polynomial.

The methods for formatted output used to print the results from this program are presented in Chapter
13. The execution of this program gives the following results.

This program solves for the roots of a quadratic equation


of the form: a*x^2 + b*x + c = 0.
To terminate this program,
enter zero when prompted for the coefficient a
Enter the coefficient a: 2
Enter the coefficient b: 4
Enter the coefficient c: 6
The equation has two complex conjugate roots:
x1= -1.000000 +j 1.414214
x2= -1.000000 -j 1.414214
Enter the coefficient a: 1
Enter the coefficient b: 2
Enter the coefficient c: 1
The equation has two repeated real roots:
x1=x2= -1.000000
Enter the coefficient a: 0
Program terminated
>>
__________

Example 6.4. For polynomials with degree higher than 4, there are no formulas to find the roots.
However, there are numerical methods for root finding, and MATLAB has a built in function roots to find
the roots of a polynomial and another built in function poly to find the coefficients of a polynomial
given its roots. The following program shows how to use the functions: roots and poly.

% Find the roots of a polynomial


clear all; clc;
disp('To find the roots of: x^N + a_N-1 * x^(N-1) + ... + a_1 * x^1 + a_0')
disp('Enter the polynomial degree and then the coefficients.');
disp('To terminate the program, enter zero degree.'); disp(' ');
while 1;
N=input('Enter polynomial degree: ');
if N > 0
a(1)=1.0; % coefficient of highest power of x
for n=1:N;
disp('Power of x is:'); disp(n-1);
a(N+2-n)=input('Enter coefficient: ');
% roots expects polynomial coefficients in descending power order
end
r=roots(a); % using built in function roots to find the N roots
disp(' ');
disp('The roots of the polynomial are:');
disp(r);
% find polynomial coefficients given the roots
b=poly(r);
disp('The coefficients of the polynomial are:');
disp(b);
else
break; % causes termination of the while loop
end
clear all; % clearing a, r and N from previous while loop execution
end
clear all; % cleaning up work space
disp('Terminated program')

Program 6.3. MATLAB program to find the roots of a polynomial.

The execution of this program gives the following results for the polynomial:
x 5  x 4  2 x 3  3x 2  4 x1  5 x 0 .

To find the roots of: x^N + a_N-1 * x^(N-1) + ... + a_1 * x^1 + a_0
Enter the polynomial degree and then the coefficients.
To terminate the program, enter zero degree.

Enter polynomial degree: 5


Power of x is:
0
Enter coefficient: 5
Power of x is:
1
Enter coefficient: 4
Power of x is:
2
Enter coefficient: 3
Power of x is:
3
Enter coefficient: 2
Power of x is:
4
Enter coefficient: 1

The roots of the polynomial are:


0.7145 + 1.3076i
0.7145 - 1.3076i
-1.2663
-0.5814 + 1.2001i
-0.5814 - 1.2001i

The coefficients of the polynomial are:


1.0000 1.0000 2.0000 3.0000 4.0000 5.0000

Enter polynomial degree: 0


Terminated program
>>
__________

Notice that complex roots appear in complex conjugate pairs. With the roots r (n) ,
n  1, 2,  , N , we can write the polynomial as a product of N first order factors given by
N
f ( x)   ( x  r (n))
n 1

6.3 Polar Form and Complex Arithmetic

There is another way, called the polar form, to arithmetically define a complex number, which in many
circumstances is more convenient to work with than the rectangular form.

A complex number is described by two real numbers. Instead of writing x    j  , we could


write x  ( ,  ) to communicate the real part and the imaginary part of x . However, x  ( ,  ) is
not an arithmetic expression for x . Another way to write an arithmetic expression for a complex
number is based on locating x in a plane, called the complex plane, where  is the distance along the
abscissa, called the real axis, and  is the distance along the ordinate, called the imaginary axis. This is
illustrated in Figure 6.3.
Im (x )


x

x
co m p le x p la n e
x

R e (x )

Fig. 6.3. Complex number located in the complex plane.

The point x can also be located by rotating a line of length, denoted by x , in the
counterclockwise direction from the positive abscissa by an angle, denoted by  x . By projection we
have

  x cos(x) (6.8)

  x sin(x) (6.9)

Summing the squares of (6.8) and (6.9) gives


2  2  x
2

Therefore
x  2  2 (6.10)

and x is called the magnitude of x . Dividing (6.9) by (6.8) gives


 sin(x)

 cos(x)

Therefore
 
x  tan 1   (6.11)
 

and x is called the angle of x . Substituting (6.8) and (6.9) into the rectangular form of (6.6) gives

x  x cos(x)  j x sin(x)  x (cos(x)  j sin(x)) (6.12)

Now, let us consider the power series expansion for the exponential function e j , and we get
( j )0 ( j )1 ( j  ) 2 ( j  )3 ( j  )4 ( j  )5
e j       
0! 1! 2! 3! 4! 5!
1 2 3 4 5
 1 j   j   j 
1! 2! 3! 4! 5!

Gathering real and imaginary parts gives

 2 4   1 3 5 
e j
 1       j     (6.13)
 2! 4!   1! 3! 5! 

The real part of (6.13) is the power series expansion for cos( ) , and the imaginary part of (6.13) is the
power series expansion for sin( ) . Now, (6.13) becomes

e j   cos( )  j sin( ) (6.14)

which is called Euler's identity.

With Euler's identity, the expression for the complex number given in (6.12) becomes

x  x e j x (6.15)

This way of writing a complex number is call the polar form. With (6.10) and (6.11) we can convert a
complex number from rectangular to polar form, and with (6.8) and (6.9) we can convert a complex
number from polar to rectangular form. Table 6.2 lists several arithmetic properties of complex
numbers written in polar form.

Table 6.2. Properties of polar form complex numbers and arithmetic


equal x1  x2 , if x1  x2 and x1  x2

addition x1  x2 , must convert to rectangular form


subtraction x1  x2 , must convert to rectangular form
multiplication x3  x1 x2  x1 x2 e j ( x1  x2 ) , x3  x1 x2 and x3  x1  x2

x1 x x
x3   1 e j ( x1  x2 ) , x3  1 and x3  x1  x2
division x2 x2 x2

conjugation x 
*
j x  jx x*
x x e , x  x e
*
, ( x1 x2 )  x x
* *
1
*
2 and  1   1*
 x2  x2

polynomial with f * ( x)  f ( x* ) , for x  x e jx


real coefficients

Example 6.5. The following statements illustrate how convenient it is to work in MATLAB with complex
numbers written in polar form.

>> clear all


>> a=3*exp(j*pi/2) % the angle of a is pi/2 radians, which places a on the imaginary axis
a=
0.0000 + 3.0000i
>> b=exp(j*pi) % the angle of b is pi, which places b on the negative real axis
b=
-1.0000 + 0.0000i
>> c=a*b
c=
-0.0000 - 3.0000i
>>% magnitude of c equals the magnitude of a times the magnitude of b
>> % angle of c is pi/2 plus pi
>> angle_c = angle(c) % using the MATLAB built in function angle
angle_c =
-1.5708
>> magnitude_c = abs(c) % using the MATLAB built in function abs
magnitude_c =
3
>> v=[j*pi/2 j*pi j*2*pi]
v=
0 + 1.5708i 0 + 3.1416i 0 + 6.2832i
>> w=exp(v) % a complex matrix can be the argument of a built in function
w=
0.0000 + 1.0000i -1.0000 + 0.0000i 1.0000 - 0.0000i
>>
__________

6.4 Application of Euler’s Identity

Euler’s identity in (6.14) can be written in several different ways. If we replace  in (6.14) by
  , then we get
e  j  cos( )  j sin(  )  cos( )  j sin( ) (6.16)

Comparing (6.14) and (6.16) shows that conjugating a complex number changes the sign of its
angle. If we add (6.14) and (6.16), then we get
e j  e  j
cos( )  (6.17)
2

With (6.17) we can write cos( ) as the sum of two complex conjugate exponential functions. If
we subtract (6.16) from (6.14), then we get

e j  e j e j  e  j e j (  /2)  e j e j (   /2)
sin( )   
j2 2e j /2 2
(6.18)
e j (  /2)  e j (  /2)
  cos(   / 2)
2

With (6.18) we can write sin( ) as the sum of two complex conjugate exponential functions. Equations
(6.16), (6.17) and (6.18) are also called Euler’s identity.

Example 6.6. Let us verify Euler’s identities with the following MATLAB statements.

>> theta=pi/3; % this is 60 degrees


>> a=cos(theta)
a=
0.5000
>> b=sin(theta)
b=
0.8660
>> c=(exp(j*theta)+exp(-j*theta))/2
c=
0.5000
>> d=(exp(j*theta)-exp(-j*theta))/(j*2)
d=
0.8660
>>
__________

Consider the sine function given by


x( ) = sin( )

where  , the independent variable, is expressed in radians. When  goes through a change of 2 
radians, then x will repeat itself, or
x ( )  x(  r 2  )

for all integers r and any  . We say that 2  is the period of x ( ) .

Now, let us work with a sinusoidal function of time (time is expressed in seconds) given by
x(t )  A cos(0 t   ) (6.19)

where 0 (expressed in radians/sec) is called the frequency of x (t ) , A , a positive number, is called the
amplitude of x (t ) , and  is called the phase angle of x (t ) . Like sin( ) , this function will repeat itself
when 0 t goes through a change of 2  , where t is now the variable. The time interval, T0 , over
which x (t ) repeats itself is called the period of x (t ) , and we write

x(t )  x(t  T0 ) (6.20)


This means that
A cos (0 t   )  A cos(0 (t  T0 )   )  A cos(0 t  0 T0   )

This requires that: 0 T0  2  , and we can get 0 from knowing T0 with


2
0 
T0
We also express the frequency with f 0  1/ T0 cycles/sec (Hertz, abbreviated to Hz).

Example 6.7. Below is a program to plot the signal given in (6.19). This example also shows how to
place more than one plot in a figure with the built in MATLAB function subplot.

clear all; clc;


amplitude = 2.0; % specify amplitude
phase = pi/4.0; % specify phase angle
f0 = 2.0; % specify frequency in Hz
w0 = 2.0*pi*f0; % convert frequency to rad/sec
T0 = 1.0/f0; % find the period, the time of one cycle
N = 101; % plot N points of the signal
total_time = 2*T0; % plot over two periods
t = linspace(0.0,total_time,N); % use linspace to set up time points
x = amplitude*cos(w0*t + phase); % evaluate signal for each time point
% organizing plots into 2 rows and 1 column
subplot(2,1,1); plot(t,x) % placing the first plot
xlabel('time - seconds')
ylabel('signal unit')
grid on
x = amplitude*cos(2*w0*t + phase); % double the frequency
subplot(2,1,2); plot(t,x) % placing the second plot
xlabel('time - seconds')
ylabel('signal unit')
grid on

Program 6.4. Program that demonstrates using subplot.


2
signal unit

-2
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
time - seconds
2
signal unit

-2
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
time - seconds

Figure 6.4. Placement of two plots in one figure.


__________

The behavior of most of the machines, devices and systems that engineers design is inherently
cyclical, which is usually described using sinusoidal functions. However, it is much more convenient to
work with exponential functions. This is possible through Euler’s identity. Applying (6.17) to (6.19) gives

e j (0t  )  e j (0t  )
x(t )  A cos(0 t   )  A
2 (6.21)
A j j0t A  j  j0t X j0t X *  j0t
 e e  e e  e  e
2 2 2 2
where X  Ae j is called the phasor of x (t ) . Therefore, x (t ) has been written as the sum of two
complex conjugate exponential functions.

Example 6.7. The following MATLAB statements and table verify (6.21).

>> A=2.0; % specify the amplitude


>> w=2*pi; % specify a frequency of 1 cycle/second
>> phase=pi/4; % specify a phase
%
>> % evaluate the sinusoid over just a quarter of a cycle
%
>> t=[0:0.025:0.25]; % evaluate only 11 points
>> x=A*cos(w*t+phase); % evaluate trigonometric function
>> X=(A)*exp(j*phase); % specify phasor
>> x_exponential=(X/2)*exp(j*w*t)+(conj(X))/2*exp(-j*w*t);
>> table=[t' x' x_exponential']; % give results in three columns
>> % the first column is time
>> % the second column is the trigonometric expression
>> % the third column is the complex exponential expression
table =
0 1.4142 1.4142
0.0250 1.1756 1.1756
0.0500 0.9080 0.9080
0.0750 0.6180 0.6180
0.1000 0.3129 0.3129
0.1250 0.0000 0.0000
0.1500 -0.3129 -0.3129
0.1750 -0.6180 -0.6180
0.2000 -0.9080 -0.9080
0.2250 -1.1756 -1.1756
0.2500 -1.4142 -1.4142
__________

6.5 Fourier Series

Practical periodic signals do not have a simple function representation. However, such signals can be
represented with a series sum of complex exponential functions, called a Fourier series.

Let s1 (t )  sin( 0 t ) . The frequency 0 is given by 0  2 / T0 , where T0 is the period of


s1 (t ) . Now, consider the time function
s2 (t )  sin(2 0 t )

This time function will go through two cycles over the time range T0 , and the period of s2 (t ) is given by
2  / (2 0 )  T0 / 2

Although the period of s2 (t ) is T0 / 2 , s2 (t ) also repeats itself every T0 sec, over which it goes through
two cycles. In general we can say that the function of time given by

sk (t )  bk sin(k 0 t )

for k  1, 2, ...,  , where bk is the amplitude, repeats itself every T0 / k secs, and over the time range
T0 , sk (t ) goes through k cycles. Similarly, the cosine function given by

ck (t )  ak cos(k 0 t )

for k  1, 2, ...,  , where ak is the amplitude, repeats itself every T0 / k secs, and over the time range
T0 , ck (t ) goes through k cycles.

Therefore, if we sum all sine and cosine functions as defined above, we get


x(t )  a0   [a
k 1
k cos(k 0 t )  bk sin(k 0 t )] (6.22)
and then x (t ) will also repeat itself every T0 secs, because for each k the cosine and sine functions go
through an integer number of cycles over the time range T0 secs. Since the average value of the sine
and cosine terms is zero, a0 is included to account for the average value of x (t ) . We say that x (t ) is a
periodic function, since for all t we have
x(t )  x(t  T0 )

and x (t ) given (6.22) is called a trigonometric Fourier series. The frequency given by 0  2  / T0 is
called the fundamental frequency of x (t ) . If the Fourier series (sum of sinusoidal functions) is to have
the same period as x (t ) , then all sinusoidal functions in the Fourier series must have frequencies given
by k 0 rad/sec, where k is an integer.

Given any kind of a practical periodic signal x (t ) , we can find the ak and bk coefficients such
that x (t ) can be written as a Fourier series. These coefficients, called the trigonometric Fourier series
coefficients, are found with

T0 T0
2 1
ak 
T0  x(t ) cos(k
0
0 t ) dt , a0 
T0  x(t ) dt
0
(6.23)

T0
2
bk 
T0  x(t ) sin(k
0
0 t ) dt (6.24)

Example 6.8. Let us apply (6.22) to represent the sawtooth wave x (t ) shown in Figure 6.5. The period

x (t)

t - sec
-2 -1 1 2 3

Figure 6.5. A sawtooth wave.

of this x (t ) is T0  1 sec. The fundamental frequency is 0  2 / T0  2 rad/sec. A period of x (t )


can be any part of x (t ) over a time range of t0  t  t0  T0 sec for any time point t0 . Over the time
range 0.25  t  0.75 , the signal x (t ) can be written as x (t )  t  0.25 . Let us use this part of
x(t ) to evaluate (6.23) and (6.24). With (6.23) and (6.24) we get
0.75
1 1
a0  
1 0.25
(t  0.25) dt 
2
 k 
0.75 sin  
2  2 , k 1, 2, 
ak  
1 0.25
(t  0.25) cos(2k t ) dt  
k
 k 
0.75 cos  
2  2 , k 1, 2, 
bk  
1 0.25
(t  0.25) sin(2k t ) dt  
k

These coefficients are used in the following MATLAB program to evaluate the Fourier series.

% This program uses a given set of trigonometric Fourier series coefficients


% to evaluate a Fourier series over three periods of the function.
T0=1.0; % the period of the function
w0=2*pi/T0; % the fundamental frequency
N=3001; % evaluate function for 3001 time points
t=linspace(-T0,2*T0,N);
K=10; % using only ten terms in the Fourier series
k=1:K; % a vector for the Fourier series coefficient index values
a0=0.5; % the average value of the function
% find all trigonometric Fourier series coefficients
ak=-sin(k*pi/2)./(pi*k); % element by element division of two vectors
bk=-cos(k*pi/2)./(pi*k); % element by element divide
for n=1:N
x(n)=a0+ak*cos(2*pi*k*t(n))'+bk*sin(2*pi*k*t(n))';
end
plot(t,x)
grid on
xlabel('time - sec')
ylabel('signal value')

Program 6.5. Program to construct a signal with a Fourier series.

1.2

0.8
signal value

0.6

0.4

0.2

-0.2
-1 -0.5 0 0.5 1 1.5 2
time - sec

Figure 6.6a. Reconstructed signal using K=10 terms in the Fourier series.
1.2

0.8
signal value

0.6

0.4

0.2

-0.2
-1 -0.5 0 0.5 1 1.5 2
time - sec

Figure 6.6b. Reconstructed signal using K=100 terms in the Fourier series.

The oscillation about the discontinuity is called Gibbs’ oscillation. The time duration of Gibbs’ oscillation
goes to zero as the number of terms used in the Fourier series increases. However, the amplitude of the
oscillation does not go to zero.
__________

The Fourier series expression for x (t ) can be written in another way. Based on Euler’s identity
we have that
e jk0t  e jk0t
cos(k 0 t ) 
2
and

e jk0t  e  jk0t
sin(k 0 t ) 
j2
Therefore, the Fourier series in (6.22) for x (t ) becomes


e jk0t  e jk0t e jk0t  e jk0t
x(t )  a0   [ak  bk ]
k 1 2 j2

ak  jbk  jk0t  ak  jbk jk0t
 a0  
k 1 2
e 
k 1 2
e

Now, let X k be defined by

ak  j bk
, k  1, 2, 3, 
Xk  (6.25)
2
Since according to (6.23), a k  ak , and according to (6.24), b k   bk , we have

a k  j b k a  j bk
X k   k  X k* , k  1, 2, 3,  (6.26)
2 2

Now, x (t ) can be written as


   
x(t )  a0   X k* e jk0t   X k e jk0t  a0   X k e jk0 t   X k e jk0t (6.27)
k 1 k 1 k 1 k 1

which becomes

x(t )   Xk
k 
e jk0t (6.28)

where the X k , called the complex Fourier series coefficients, are found by substituting (6.23) and (6.24)
into (6.25) to get
T0

Xk  1
 x(t ) e jk0t dt (6.29)
T0 0

for k  0, 1, ...,  . The Fourier series in (6.28) is called the complex exponential Fourier series.

The idea of writing a time function or signal in terms of a sum of sinusoidal functions is a very
fundamental concept that is widely applied in engineering. In view of (6.25), the X k are in general
complex numbers, which we can write in polar form to get

X k  X k e j X k

Since X  k  X k* , then X  k  X k , which makes X k an even function of k , and X  k   X k ,


which makes X k is an odd function of k . Substituting the polar form for X k into (6.28) gives


x(t )  
k 
X k e j X k e jk t0

 j 20t  j0t j0t j 20t


   X 2 e  j X 2 e  X 1 e  j X1 e  X 0  X 1 e j X1 e  X 2 e j X 2 e 

With Euler’s identity this becomes


x(t )  X 0  2 X k cos(k0t  X k ) (6.30)
k 1

This shows that 2 X k gives the amplitude and X k gives the phase of the sinusoidal contribution to
x (t ) at the frequency   k0 rad/sec.

Example 6.9. To assess the nature of a signal x (t ) , the amplitude and phase of each sinusoidal function
that contributes to x (t ) is plotted versus the frequency of the sinusoidal function. For the periodic
signal x (t ) given in Example 6.8, (6.29) gives the complex Fourier series coefficients, which results in
0.75
1 1 j ( k 1) /2
Xk  
1 0.25
(t  0.25)e  jk 2 t dt 
2 k
e , k 0

1
 , k 0
2

Figure 6.8 shows the amplitudes of the sinusoidal contributions to x (t ) versus the frequency of the
sinusoid. This plot is called the magnitude spectrum.

0.5

0.4
Magnitude

0.3

0.2

0.1

0
-10 -8 -6 -4 -2 0 2 4 6 8 10
frequency index k

Figure 6.8. Magnitude spectrum of the sawtooth wave.

The following program uses the complex Fourier series coefficients to plot the magnitude spectrum of
the sawtooth wave.

clear all; clc;


K=20; %
freq_index=[-K:1:K];
% find complex Fourier series coefficients
X0=0.5
for k=1:K
X_pos_k(k)=exp(j*(k+1)*pi/2)/(k*2*pi);
X_neg_k(k)=conj(X_pos_k(k));
end
% organize Fourier series coefficients for k = -K, ..., -1, 0, 1, ..., K
X=[fliplr(X_neg_k), X0, X_pos_k]; % flipping X_neg_k
X_mag=abs(X); % get magnitude of complex Fourier series coefficients
stem(freq_index,X_mag); % draw a stem plot
grid on
xlabel('frequency index k')
ylabel('Magnitude')

Program 6.6. Using complex Fourier series coefficients to find and plot the magnitude spectrum.
_____________

In this section we saw how convenient it is in MATLAB to use complex exponential functions for
representing a periodic signal. In several of the following chapters this approach to signal
representation will be extended to include aperiodic continuous time signals, discrete time periodic
signals and aperiodic discrete time signals.
6.6 Complex Impedance

The complex exponential function also plays an important role in linear system analysis and design. To
see how readily MATLAB can be involved in this, Euler’s identity will be applied to AC circuit analysis.
Then, with MATLAB we will analyze circuits for the sinusoidal response to sinusoidal inputs. Before we
proceed, let us consider the electrical devices used to build circuits. Figure 6.9 shows the passive
components: resistor, capacitor and inductor.

i(t) i(t) i(t)


v(t) R v(t) C v(t) L

Figure 6.9. Passive electrical circuit components: R, L and C and current and voltage references.

For the inductor, the voltage-current relationship is

di (t )
v(t )  L (6.31)
dt
Suppose the current is some sinusoidal function, i (t )  A cos(t   ) . Then, the phasor I for the
current is given by

I  Ae j

According to (6.31), the voltage across the inductor becomes

v(t )   A L sin(t   )  A L cos(t     / 2)

and therefore, the phasor V for the inductor voltage v (t ) is given by

V  A L e j (  /2)  j L Ae j
With the voltage and current phasors we have
V  j L I  Z L I (6.32)

The term Z L  j L , which relates the inductor current phasor to the inductor voltage phasor is called
the impedance of an inductor. If we use instead the current-voltage relationship given by
1
L
i (t )  v(t ) dt
then we get the phasor relationship given by
1 1
I  V  V (6.33)
j L ZL
For AC circuit analysis, we have changed the time-domain derivative relationship between the inductor
voltage and inductor current into a frequency-domain algebraic relationship between the inductor
voltage phasor and the inductor current phasor.

For the capacitor, the current-voltage relationship is given by


dv(t )
i (t )  C (6.34)
dt

Suppose the voltage is some sinusoidal function, v (t )  A cos(t   ) . Then, the phasor V for the
voltage is given by

V  Ae j

With a further development similar to that for the inductor, we get

I  jC V (6.35)

and

1
V  I  ZC I (6.36)
jC

The term Z C  1/ jC , which relates the capacitor current phasor to the capacitor voltage phasor, is
called the impedance of the capacitor.

For the resistor, the voltage-current relationship is v (t )  R i (t ) , and, since this is an


instantaneous relationship, the relationship between the resistor voltage phasor and the resistor current
phasor is given by
V  R I  ZR I (6.37)

where Z R  R is called the impedance of the resistor.

In (6.32), (6.36) and (6.37) we see that multiplying a current phasor by an impedance produces a
voltage phasor. These equations show that if we are only interested to solve the integral-differential
equations that result from applying Kirchhoff’s laws to linear circuits for the steady-state response to
sinusoidal inputs, then we can immediately convert these equations to complex algebraic equations in
terms of current phasors, voltage phasors and impedances.

6.7 AC Circuit Analysis

AC circuit analysis is concerned with finding the steady-state sinusoidal response of a linear circuit to a
sinusoidal input. Since MATLAB can work with the complex data type, applying MATLAB to AC circuit
analysis is similar to applying MATLAB to resistive circuit analysis.
As a general example, consider the RLC circuit shown in Figure 6.10, where the input is the
voltage given by

vs (t )  A cos(t   )

The amplitude A and phase  determine the phasor Vs of vs (t ) , and the frequency  will be
assigned values over a range to see how the circuit responds differently, depending on the frequency of
the input.
C L

vs (t) i(t) R v(t)

Figure 6.10. Series connected RLC circuit.

To find the steady-state sinusoidal current, let us do a mesh analysis of the circuit, and apply
Kirchhoff’s voltage law. Summing the voltage drops around the mesh gives

1 di(t )
vs (t ) 
C  i (t ) dt  L
dt
 R i (t )  0 (6.38)

Since vs (t ) is a sinusoid, then in steady-state i (t ) must also be a sinusoid given by


i (t )  I cos( t  I ) , where I  I e jI is the phasor of i (t ) . Replacing vs (t ) and i (t ) by their
Euler identity equivalents results in

1 1 1 1 *  jt
 (Vs e jt  Vs*e  jt )  ( Ie jt  I e )
2 2C j j
L R
( j Ie jt  j I *e  jt )  ( Ie jt  I *e  jt )  0
2 2
Rearranging this equation gives
1 1
(Vs  I  j LI  RI ) e jt  (Vs  I  j LI  RI )* e  jt  0
jC jC

which must be true for all t . Therefore, we require that

1
Vs  I  j LI  RI  0 (6.39)
jC

The time domain sum of voltage drops in (6.38) have been replaced by the sum of phasor voltage drops
in (6.39) resulting in an algebraic equation for the current phasor giving
1
Vs  (  j L  R ) I  Z ( j ) I (6.40)
jC

or

1 jC
I  Vs  Vs  Y ( j ) Vs
1
 j L  R 1   LC  j RC
2

jC

Notice that when  2  1/ ( LC ) , then I  Vs / R , as if the capacitor and inductor are equivalent to an
ideal conductor. If we plot Y ( j ) and Y ( j ) versus  we see how the circuit modifies the
amplitude and phase of the input voltage vs (t ) to obtain the amplitude and phase of the current i (t ) .

With (6.37) the phasor V for the voltage v (t ) is given by

j RC
V  RI  Vs  H ( j ) Vs (6.41)
1  LC 2  j RC

Since H ( j 0)  0 and H ( j)  0 , H ( j ) behaves like a band-pass filter as   0   .

Example 6.9. With the complex arithmetic capability of MATLAB we can easily assess the performance
of the circuit given in Figure 6.10 for different values of the circuit components. Let R  33  ,
L  10 mH and C  0.11  F . The following MATLAB program finds H ( j ) , and plots the magnitude.
We see in Figure 6.11 that H ( j ) has the characteristic of a band-pass filter.

clear all; clc;


R=33; % resistor value
L=10*10^-3; % inductor value
C= 0.11*10^-6; % capacitor value
f=linspace(0,5.0*10^4,1001); % frequency range
w=2.0*f; % vector of frequencies
H_num=j*w*R*C; % transfer function numerator for all frequencies in w
H_den=1-L*C*w.*w+j*w*R*C; % transfer function denominator
H=H_num./H_den; % element by element complex divide
plot(f,abs(H)); % plot band-pass filter magnitude
grid on
xlabel('Hz')
ylabel('H magnitude')

Program 6.7. Find and plot the magnitude frequency response.


1

0.9

0.8

0.7
e

0.6
gn d
itu

0.5
Hma

0.4

0.3

0.2

0.1

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
Hz 4
x 10

Figure 6.11. Magnitude frequency response of the RLC circuit.


__________

Example 6.10. Let us apply the complex impedance concept to the circuit given in Figure 6.12, and find
the response v (t ) to the input vs (t ) .

L1 L2

vs(t) i1(t) C i2(t) R v(t)

Figure 6.12. Circuit of a third order Butterworth low-pass filter.

The component values are: L1  3 / 2 H , L2  1/ 2 H , C  4 / 3 F and R  1  . Suppose


the input is the sum of two sinusoids given by

vs (t )  2 cos(2 f1t   / 4)  3cos(2 f 2t   / 6)

where f1  0.2 Hz and f 2  2 Hz. The input is shown in Figure 6.13. This input was plotted with the
following program.
clear all; clc;
f1=0.2; w1=2*pi*f1; f2=2.0; w2=2*pi*f2;
T_total=2/f1; % specify total time
N=5001;
t=linspace(0,T_total,N);
vs=2*cos(w1*t-pi/4)+3*cos(w2*t-pi/6);
plot(t,vs)
grid on
xlabel('time - sec')
ylabel('input')
Program 6.8. Find and plot the input .
5
input

-5
0 1 2 3 4 5 6 7 8 9 10
time - sec

Figure 6.13. Voltage input.

Now we will replace each circuit component by its impedance and each sinusoidal current and
sinusoidal voltage by its phasor resulting in the frequency domain circuit shown in Figure 6.14. Since the
given circuit is a linear system, we can find the steady-state response to vs (t ) by finding the response to
each sinusoidal component in vs (t ) and then sum these responses.

jwL 1 jwL 2

1 I2
Vs I1 R V
jwC

Figure 6.14. Frequency domain circuit.

In the frequency domain, the Kirchhoff voltage law (KVL) equations for the circuit meshes are
given by

1
Vs  j L1 I1  ( I1  I 2 )  0 (6.42)
jC

1
( I 2  I1 )  j L2 I 2  RI 2  0 (6.43)
jC

We must solve (6.42) and (6.43) with   1 to find the phasor I 2 , and then the contribution to v (t )
due to the first component in vs (t ) can be found, and then again with   2 to find the contribution
to v (t ) due to the second component in vs (t ) . This is done by the following MATLAB program, and the
result is shown in Figure 6.15, where we see that the high frequency component of vs (t ) has been
significantly attenuated (filtered) by the circuit.
% AC analysis of third order Butterworth filter
%
L1=3/2; L2=1/2; C=4/3; R=1; % specify circuit component values
f1=0.2; f2=2.0; % frequencies of components of the input signal
w=2*pi*[f1 f2];
Vs=[2*exp(-j*pi/4) 3*exp(-j*pi/6)]; % phasors of the two input components
T_total=2/f1; N=1001; % plot output over 2 cyles of the first input component
t=linspace(0,T_total,N);
v=zeros(1,N); % initialize the output voltage vector to zero
for k=1:2 % analyze the circuit for each input component frequency
% find impedances
ZL1=j*w(k)*L1;
ZL2=j*w(k)*L2;
ZC=1/(j*w(k)*C);
Z=[ZL1+ZC -ZC; ... % set up the impedance matrix Z
-ZC ZC+ZL2+R];
V=[Vs(k) 0]'; % mesh voltage vector
Y=inv(Z); % invert the impedance matrix
I=Y*V; % solve for the mesh current phasor vector
% I(2) is the phasor of the current in mesh 2 for the frequency w(k)
V(k)=R*I(2); % phasor of output component
v=v+abs(V(k))*cos(w(k)*t+angle(V(k))); % contribution to output
end
plot(t,v)
grid on
xlabel('t - sec')
ylabel('output voltage')

Program 6.9. MATLAB program for AC circuit analysis.

0.5
output voltage

-0.5

-1
0 1 2 3 4 5 6 7 8 9 10
t - sec
Figure 6.15. Output of the low-pass filter.
___________

Vous aimerez peut-être aussi