The MATLAB Notebook v1.5

advertisement
Random Signals for Engineers using MATLAB and Mathcad
Copyright  1999 Springer Verlag NY
Example 3.5 Characteristic Functions
The characteristic function is used to find the mean and variances of continuous distributions. Even
though it is more complex to use than the moment generation function it is preferred because it can be
shown that the characteristic function exist for all distributions. We will derive the characteristic function
for the uniform, exponential and the Gaussian distribution. The mathematical manipulations can readily be
performed using Matlab.
UNIFORM - This distribution has the form f(x) = 1/ (b - a) and the characteristic function is
syms a b u om
phi = int(exp(i*om*u)*1/(b-a),u,a,b);
pretty(phi)
i exp(i b om)
i exp(i a om)
------------- - ------------om (-b + a)
om (-b + a)
Matlab maintains the exponential with complex argument.
Differentiation of () and substitution of  = 0 results in the E[X].
We begin the process by differentiation. When we attempt to substitute  = 0 we find that we have a zero
over zero case and this requires the expansion of the numerator by a Taylor series to cancel  in the
denominator and avoid the singularity as   0
phip=diff(phi,om)
phip =
-b*exp(i*b*om)/om/(-b+a)-i*exp(i*b*om)/om^2/(-b+a)+a*exp(i*a*om)/om/(b+a)+i*exp(i*a*om)/om^2/(-b+a)
When we attempt to substitute  we find that we have a zero over a zero and this requires that we use
L'Hopitals rule, which avoids the singularity as we take the limit as 

EX=-i*limit(phip,om,0)
EX =
-i*(1/2*i*a+1/2*i*b)
EX=simplify(EX);
pretty(EX)
1/2 a + 1/2 b
The second moment is similarly formed from the expanded terms
phipp=diff(phi,om,2);
EX2=(-1)*limit(phipp,om,0)
EX2 =
1/3*a^2+1/3*b*a+1/3*b^2
The second moment after multiplication by (-i)2 becomes
E[X2] =
EX2=simplify(EX2);
pretty(EX2)
2
1/3 a
2
+ 1/3 b a + 1/3 b
The variance is now using the standard formula VAR[X] = E[X 2] - E[X]2 =
VARX=EX2-EX^2
VARX=simple(VARX);
pretty(VARX)
VARX =
1/3*a^2+1/3*b*a+1/3*b^2-(1/2*a+1/2*b)^2
2
1/12 (-b + a)
This is the same result as example 3.3
EXPONENTIAL - This distribution has the form f(x) = and the characteristic function is
syms lam
gt=sym('lam>0');
maple('assume',gt);
phi = int(exp(i*om*u)*lam*exp(-lam*u),u,0,inf);
pretty(phi)
lam~
------------i om + lam~
In this reduction, Matlab evaluated the integral with infinite limits directly. Maple used the information
that lam >0 to be able to evaluate the integral at the infinite limits. The moments are computed by
differentiation
phip=diff(phi,om)
phip =
i*lam/(-i*om+lam)^2
EX=-i*limit(phip,om,0);
EX=simplify(EX);
E[X]=
pretty(EX)
1
---lam~
phipp=diff(phi,om,2)
phipp =
-2*lam/(-i*om+lam)^3
EX2=(-1)*limit(phipp,om,0);
EX2=simplify(EX2);
E[X2]=
pretty(EX2)
2
----2
lam~
VARX=EX2-EX^2;
VARX=simple(VARX);
pretty(VARX)
1
----2
lam~
This is in agreement with example 3.2
GAUSSIAN - The characteristic function for the gaussian is used in many contexts and we derive it here
syms sig
f=exp(-1/2*((u-a)/sig)^2);
pretty(f)
2
(u - a)
exp(- 1/2 --------)
2
sig~
We have no normalized the function by
obtained the final result
2     . We will perform the normalization when we have
gt=sym('sig>0');
maple('assume',gt);
phi=int(f*exp(i*om*u),u,-inf,inf);
pretty(phi)
2
1/2
1/2
exp(1/2 i om (2 a + i om sig~ )) 2
sig~ pi
This integral can be evaluated directly by Matlab. We must not use the Fourier transform because the
characteristic function is defined using the positive sign for the complex exponent. It is instructive to
recognize the substitutions that have to be performed to evaluate this integral. First we change variable
from u to v using Matlab to solve for u with v= u-a
syms v
fc=exp(-i*om*u);
arg=f*fc;
arg=expand(arg);
arg=simplify(arg);
pretty(arg)
2
2
2
u - 2 u a + a + 2 i om u sig~
exp(- 1/2 --------------------------------)
2
sig~
We substitute for u in the kernel of the integral
arg = subs(arg,u,v+a);
arg=expand(arg);
pretty(arg)
2
v
exp(- 1/2 -----)
2
sig~
----------------------exp(i om v) exp(i a om)
Complete the square for the exponent and factor the expression
arg= -1/2/sig^2*v^2-i*om*v + om^2*sig^2/2
arg =
-1/2/sig^2*v^2-i*om*v+1/2*om^2*sig^2
The first three terms are factored
solve(arg)
ans =
[ -i*om*sig^2]
[ -i*om*sig^2]
We can verify that the numerator is a perfect square. Combining the results obtain the normalizing factor
fac=int(exp(-1/2*((v-i*om*sig^2)/sig)^2),v,-inf,inf);
pretty(fac)
1/2
2
1/2
sig~ pi
Integrating using Matlab or recognizing the gaussian normalization integral we have
phi=phi/fac;
pretty(phi)
2
exp(1/2 i om (2 a + i om sig~ ))
This is the same as evaluated above
The mean and variance are simply obtained
phip=diff(phi,om)
phip =
(1/2*i*(2*a+i*om*sig^2)-1/2*om*sig^2)*exp(1/2*i*om*(2*a+i*om*sig^2))
EX=-i*limit(phip,om,0);
EX=simplify(EX);
pretty(EX)
a
phipp=diff(phi,om,2);
EX2=(-1)*limit(phipp,om,0);
EX2=simplify(EX2)
EX2 =
sig^2+a^2
VARX=EX2-EX^2;
VARX=simple(VARX)
VARX =
sig^2
These moments agree with example 3.3

Download