You are on page 1of 7

Fourier Transform

C. C. Esporlas
National Institute of Physics
University of the Philippines
ccesporlas@gmail.com

and the inverse Fourier transform is

1. Introduction
In physics most problems involve functions or
signals that can be expressed or decomposed into a
sum of sinusoidal functions of different frequencies
that can be recombined to obtain the original
function. These signals may be of any form like a
square wave or a Gaussian wave and they can be
represented as the limit of a sum of sinusoidal
functions like a set of continuous oscillations. This
recombination process is a mathematical tool
commonly used in physics is the Fourier analysis.
After decomposition an amplitude and phase is
obtained for each frequency that is basically the
sinusoidal functions which therefore has a value that
can be represented as a complex number.
Fourier analysis has many scientific applications
like in signal and image processing, optics such as
the output of a stellar interferometer, the electron
distribution in an atom obtained from a Fourier
transform of the amplitude of scattered X-rays and
also the wave nature of matter in quantum mechanics.
In most cases, Fourier transform refers to the
transform of functions of a continuous real variable,
such as time. The amplitude and phase of a
sinusoidal component of function depends on the
component's frequency which is the complex part.
However this continuous function can be replaced by
a continuum of discrete values and the integration is
replaced with a summation. This application is
helpful since data is only available at discrete points
in time or space like a continuous sampling which is
more applicable now with the use of computers.

1.1. The Discrete Fourier Transform


From a continuous function we can replace it with a
sequence of discrete complex numbers ar, r = 1,..,N-1
with a Fourier transform of another sequence of
discrete values say bs, s = 1,,N where

bs =

N 1

a
N
r =0

rs

exp 2 i
N

(1)

N 1

rs

b exp 2 i N
N

ar =

(2)

s =0

Using Equations 1 and 2 the signal {a1,,aN-1} is then


decomposed into a sum of oscillations or sinusoidal
functions

bs

cs ( r ) =

exp [ is r ]

(3)

where the frequencies s = 2s/N and for each


frequency is a Fourier coefficient bs = |bs|exp(is) that
contains the amplitude and the phase. Both Equations 1
and 2 can be extended to all integers r and s. Because
exp(2ik)=1 for k, ar and bs are periodic in r and s
respectively, with a period N:

ar = ar + kN , bs = bs + kN

(4)

such that in each sum the index r or s can run through


and interval of length N; all other frequencies are
integer multiples of 1. The largest frequency is
N-1=2(N-1)/N as bN=b0 and therefore cN(r) has the
same functional values as c0(r).
So far only signals with complex values were
considered. Now if all signal ar are real, their Fourier
coefficients bs have a different symmetry:

rs

exp 2 i
N

r =0
N 1
1
r ( s)

=
ar exp 2 i

N
N r =0

= b s .

bs =

N 1

a
N

where b* is the complex conjugate of b. From here we


can conclude that

bs = b* s = bN* s ;
thus, only values b0,,bN/2
bN/2+1,,bN-1 are redundant.

(5)
are

relevant,

and

2. Physics Problem
In this project we are given a time-dependent
voltage probed at N=64 points (sampling) in time
resulting to a discrete set of voltages {Uo,,UN-1}.
And then another sequence {bo,,bN-1} is the Fourier
transform of the voltage signals. This second set of
sequence has the power spectrum |bs|2=|bN-s|2=1 for s
= 8,10,,16, otherwise bs=0. If the voltage
{Uo,,UN-1}signal is real then from Equation 5, bN*
s=b s.
Now, what is asked is how the voltage signal
{Uo,,UN-1}will look like if the phases of the Fourier
coefficients are constant, e.g. bs=1, if bs0 and if
random phases for the non-zero bs, i.e., bs=exp(is)
where the s is random. Next is to find phases (s)
that will result in the lowest possible peak voltage,
i.e. min {s} max r |Ur|.
In order to get an idea of how the voltage signal
will look like, we need to get the inverse Fourier
transform of the different sets of s { s=constant
(e.g. bs=0); s=constant but bs0; s=random0} and
plot it in a U vs. N graph.
For the first and second condition, we simply get a
set of s which is a set of 1s and 0s using the power
spectrum condition and apply an Inverse Fourier
Transform and get the voltage signal {Uo,,UN-1}.
For the second condition, when a specific constant
phase is used, the bs becomes equal to 1 such that all
the bs in the set is equal to 1 and when an Inverse
Fourier is formed, we will get a straight line.
For the third condition we use the equation
bs=exp(is) and setting the s as a random set of
values.
In the next problem, we look for the phases that
give the minimum peak voltage of different voltage
signals having different sets of random phases.
Basically we get a set of voltage points for a single
signal by using a set of random phases. We then get
the Fourier transform of this set of voltage points for
a single signal and then get its peak voltage.
Repeating the same process over again for a number
of times corresponding the number of voltage signals
we get a set of peak voltages and then we get the
maximum of this set of peak voltages. The set of
phases that give this minimum peak voltage will then
be marked.

3. Algorithm
To implement the computations needed we use
Python which already has a library for the Fourier
transform.

For the first and second problem, we define the


Fourier transform sequence from N=64 voltage probes.
b=scipy.zeros(N)

This gives us an array of 64 zeros and to manipulate


the values in order to match the power spectrum of the
sequence, we use a for statement to choose which
values we want to change with some value.
for i in range(8,17,2):

For problem1:
b[i]= 1
b[N-i]= 1

For problem 2: use bs=exp(is),


bs=int(abs(scipy.exp(1j*scipy.rand()*360)))
b[i]=bs
b[N-i]=scipy.conjugate(bs)

where scipy.rand() outputs a random number


between 0 and 1 and multiplying it with 360 we get a
random phase in degrees. The scipy.conjugate()
implements the b*=b-s=bN-s to get only the real parts of
the function. Now, to get the Inverse Fourier
Transform we use
voltage_points=scipy.fftpack.ifft(b)

This is what we now plot to get the voltage signal. To


plot we get
x=scipy.linspace(0,N-1,N)
pylab.plot(x,voltage_points,'b',label=')
scipy.linspace()gives the attributes for the x-axis
such as the start and end value and spacing of values.
This then gives the values for the x-axis and for the yaxis we get the values from the inverse Fourier
transform. Here we are showing the voltage signal
since we are showing the amplitudes at certain test
points for a series of sampling intervals.
In problem3, we basically do the same process but do
it over and over again for a number of times to get a
different voltage signal with a different set of phases.
#get values of b and phi respectively
for r in xrange(R3):
for n in range(0,N3-1):
for i in range(8,17,2):
phi=scipy.rand()*360
b3[i]=int(abs(scipy.exp(1j*phi)))
b3[N3-i]=scipy.conjugate(b3[i])
#store generated and used phi values
phis.append(phi)

For R3 times (equal to number of voltage signals) we


get a set of phases (phis) and store it in an empty array
phi[].

We get Fourier transform of set of b values and plot


it.

4. Results
For part1 the voltage signal looks like this:

U=scipy.real(scipy.fftpack.ifft(b3))
pylab.plot(x3,U,'g',label=')

Then make a two dimensional array of the U value


and the respective phi value used.
for j in range(N3-1):
setU=[U[j],phis[j]]
#print setU

Find the maximum U value for one voltage signal


from N probes:
Figure 1Voltage Signal with Constant Phases
for j in range(N3):
maximum=max(U)
if U[j]==maximum:
imax=[U[j],phis[j]]
#print imax
#print maximum

For part2

We store obtained maximum U value in an array.


maxU.append(maximum)

Get the minimum of the set of maximum U values


from R voltage signals
for r in xrange(R3):
minmaxU=min(maxU)

We store the minimum of the set of maximum U


values and the corresponding phi used in a two
dimensional array
for j in range(N3):
if U[j]==minmaxU:
minU=[U[j],phis[j]]
print minU

Figure 2Voltage Signal with Random Phases


For part 3

Then show the minimum of the maximum U values


print minmaxU

minmax here is the minimum peak voltage and to


get the set of phases we get minU.

Figure 3Voltage Signals with Different Sets of


Random Phases
Here we can see that the minimum at about 0.03 but
the phase angles are always changing since the phases
are generated randomly.

[2] W. Kinzel and G. Reents. Physics by computer.


Springer. 1998

Figure 4Peak Voltages


Here we can see that the minimum peak voltage
occurs between 0.05 and 0.04 but this also varies due
to the generation of phases.
If we compare the first (red) and second (blue) graph
we can see that they are in phase but at some times
the second one is at out phase also due to the random
generation of the phases.

If the number of probes are increased the more


defined the graph becomes.

References
[1] Mathematical Methods for Physicists by Arfken
and Weber

Source Code:
#############################################################################################
#
# Applied Physics 155
# Project 1: Fourier Transform
#
# Name: Project1_FourierTransform_Esporlas.py
# By: Cindy Liza C. Esporlas
# Date: December 13, 2007
# Description: This outputs the plot of a voltage signal using the set of Fourier
#
coefficients b (with problem1: constant phases, problem2: random phases)
#
where these coefficients are the Fourier transform of a set of voltage
#
values obtained from a number of probes N. This only gives approximation
#
since the the voltage values are taken from a discrete number of sources.
#
This also outputs an approximate minimum of the voltage peaks and the set of
#
phase angles that give these values.
#############################################################################################
import scipy, scipy.special, scipy.fftpack, pylab
N=64
x=scipy.linspace(0,N-1,N)
#problem 1
pylab.figure(1)
b1=scipy.zeros(N)
for i in range(8,17,2):
b1[i]=1
b1[N-i]=1
part1=scipy.fftpack.ifft(b1)
pylab.plot(x,part1,'r-',label='Voltage Signal with Constant Phases')
pylab.axis('tight')
pylab.xlabel('Voltage Signal Probes (N)')
pylab.ylabel('Voltage Sequence(U)')
#problem 2
pylab.figure(2)
b2=scipy.zeros(N)
for i in range(8,17,2):
bs=int(abs(scipy.exp(1j*scipy.rand()*360)))
b2[i]=bs
b2[N-i]=scipy.conjugate(bs)
part2=scipy.fftpack.ifft(b2)
pylab.plot(x,part2,'b',label='Voltage Signal with Random Phases')
pylab.axis('tight')
pylab.xlabel('Voltage Signal Probes (N)')
pylab.ylabel('Voltage Sequence(U)')

#problem 3

pylab.figure(3)
pylab.axis('normal')
pylab.xlabel('Voltage Signals (R3)')
pylab.ylabel('Voltage Sequence(U)')

N3=100 #number of probes for one voltage signal


R3=100 #number of voltage signals
raxis=scipy.linspace(0,R3-1,R3)
x3=scipy.linspace(0,N3-1,N3)
b3=scipy.zeros(N3)
#create empty arrays to store maxU and phi values
phis=[]
maxU=[]
#get values of b and phi respectively
for r in xrange(R3):
for n in range(0,N3-1):
for i in range(8,17,2):
phi=scipy.rand()*360
b3[i]=int(abs(scipy.exp(1j*phi)))
b3[N3-i]=scipy.conjugate(b3[i])
#store generated and used phi values
phis.append(phi)
#get Fourier transform of set of b values
U=scipy.real(scipy.fftpack.ifft(b3))
pylab.plot(x3,U,'g',label='Voltage Signals with Different Sets of Random Phases')
#make a two dimensional array of the U value and the respective phi value used
for j in range(N3-1):
setU=[U[j],phis[j]]
#print setU
#Find the maximum U value for one voltage signal from N probes
for j in range(N3):
maximum=max(U)
if U[j]==maximum:
imax=[U[j],phis[j]]
#print imax
#print maximum
#store obtained maximum U value in an array
maxU.append(maximum)

#make a plot of the maximum U values


pylab.figure(4)
pylab.axis('normal')
pylab.xlabel('Voltage Signal(R)')
pylab.ylabel('Peak Voltage Values(maxU)')
pylab.plot(raxis,maxU,'mo',label='Peak Voltages')

#Get the minimum of the set of maximum U values from R voltage signals
for r in xrange(R3):
minmaxU=min(maxU)
#store the minimum of the set of maximum U values and the corresponding phi used in a two dimensional array
for j in range(N3):
if U[j]==minmaxU:
minU=[U[j],phis[j]]
print minU
#show the minimum of the maximum U values
print minmaxU
pylab.show()

You might also like