Here is how to generate the Fourier transform of the sine wave in
Eq. () using the numpy
package in Python.
Let's do it in interactive mode. So start by running



Here is a linebyline explanation of the script.

np
as the short
name of the package.

np.arange(N)
generates a vector of integers ranging
from 0
to N1
. More generally,
np.arange(xfirst,xlast,xincr)
generates a vector with
sequential values starting at xfirst
, increasing by
xincr
and ending just before xlast
. The
numbers can be floats, but be careful of roundoff errors. So this
command sets t
equal to the onedimensional array, i.e.
the vector,
.

t
,
component by component, calculating
. So f
is
assigned to be a vector with eight elements. Try the command
print f
to see the result.

np.fft
package has a bunch of Fourier transform
procedures. The one that actually does the Fourier transform is
np.fft.fft
. The command performs the discrete Fourier
transform on f
and assigns the result to ft
.
The Fourier components ft[m]
belong to the discrete
frequencies
.