Fourier Transform

So let's actually do one!

In [45]:
N = 8
M = fromfunction(lambda k,n: exp(2 * pi * 1j * k * n / N), (N,N) )
print M
[[  1.00000000e+00 +0.00000000e+00j   1.00000000e+00 +0.00000000e+00j
    1.00000000e+00 +0.00000000e+00j   1.00000000e+00 +0.00000000e+00j
    1.00000000e+00 +0.00000000e+00j   1.00000000e+00 +0.00000000e+00j
    1.00000000e+00 +0.00000000e+00j   1.00000000e+00 +0.00000000e+00j]
 [  1.00000000e+00 +0.00000000e+00j   7.07106781e-01 +7.07106781e-01j
    6.12323400e-17 +1.00000000e+00j  -7.07106781e-01 +7.07106781e-01j
   -1.00000000e+00 +1.22464680e-16j  -7.07106781e-01 -7.07106781e-01j
   -1.83697020e-16 -1.00000000e+00j   7.07106781e-01 -7.07106781e-01j]
 [  1.00000000e+00 +0.00000000e+00j   6.12323400e-17 +1.00000000e+00j
   -1.00000000e+00 +1.22464680e-16j  -1.83697020e-16 -1.00000000e+00j
    1.00000000e+00 -2.44929360e-16j   3.06161700e-16 +1.00000000e+00j
   -1.00000000e+00 +3.67394040e-16j  -4.28626380e-16 -1.00000000e+00j]
 [  1.00000000e+00 +0.00000000e+00j  -7.07106781e-01 +7.07106781e-01j
   -1.83697020e-16 -1.00000000e+00j   7.07106781e-01 +7.07106781e-01j
   -1.00000000e+00 +3.67394040e-16j   7.07106781e-01 -7.07106781e-01j
    5.51091060e-16 +1.00000000e+00j  -7.07106781e-01 -7.07106781e-01j]
 [  1.00000000e+00 +0.00000000e+00j  -1.00000000e+00 +1.22464680e-16j
    1.00000000e+00 -2.44929360e-16j  -1.00000000e+00 +3.67394040e-16j
    1.00000000e+00 -4.89858720e-16j  -1.00000000e+00 +6.12323400e-16j
    1.00000000e+00 -7.34788079e-16j  -1.00000000e+00 +8.57252759e-16j]
 [  1.00000000e+00 +0.00000000e+00j  -7.07106781e-01 -7.07106781e-01j
    3.06161700e-16 +1.00000000e+00j   7.07106781e-01 -7.07106781e-01j
   -1.00000000e+00 +6.12323400e-16j   7.07106781e-01 +7.07106781e-01j
   -2.69484194e-15 -1.00000000e+00j  -7.07106781e-01 +7.07106781e-01j]
 [  1.00000000e+00 +0.00000000e+00j  -1.83697020e-16 -1.00000000e+00j
   -1.00000000e+00 +3.67394040e-16j   5.51091060e-16 +1.00000000e+00j
    1.00000000e+00 -7.34788079e-16j  -2.69484194e-15 -1.00000000e+00j
   -1.00000000e+00 +1.10218212e-15j  -4.90477700e-16 +1.00000000e+00j]
 [  1.00000000e+00 +0.00000000e+00j   7.07106781e-01 -7.07106781e-01j
   -4.28626380e-16 -1.00000000e+00j  -7.07106781e-01 -7.07106781e-01j
   -1.00000000e+00 +8.57252759e-16j  -7.07106781e-01 +7.07106781e-01j
   -4.90477700e-16 +1.00000000e+00j   7.07106781e-01 +7.07106781e-01j]]

In [64]:
plot(imag(M[:, 7]))
Out[64]:
[<matplotlib.lines.Line2D at 0x10cfba9d0>]
In [6]:
array(100)
Out[6]:
array(100)
In [7]:
?array
In [10]:
?asarray
In [11]:
array([1,2,3])
Out[11]:
array([1, 2, 3])
In [12]:
?arrange
Object `arrange` not found.

In [13]:
n = arange(4)
In [14]:
n
Out[14]:
array([0, 1, 2, 3])
In [15]:
dim(n)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-15-3f0321c9550f> in <module>()
----> 1 dim(n)

NameError: name 'dim' is not defined
In [16]:
shape(n)
Out[16]:
(4,)
In [17]:
?reshape
In [18]:
n
Out[18]:
array([0, 1, 2, 3])
In [19]:
N = len(n)
In [20]:
N
Out[20]:
4
In [21]:
k = n.reshape((1,N))
In [22]:
k
Out[22]:
array([[0, 1, 2, 3]])
In [23]:
shape(k)
Out[23]:
(1, 4)
In [24]:
dot(n,k)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-24-3d4c8eb183eb> in <module>()
----> 1 dot(n,k)

ValueError: objects are not aligned
In [25]:
dot(k,n)
Out[25]:
array([14])
In [26]:
k*n
Out[26]:
array([[0, 1, 4, 9]])
In [27]:
n*k
Out[27]:
array([[0, 1, 4, 9]])
In [28]:
n
Out[28]:
array([0, 1, 2, 3])
In [29]:
j
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-29-ddd5752b5fe6> in <module>()
----> 1 j

NameError: name 'j' is not defined
In [30]:
complex(0,1)
Out[30]:
1j
In [31]:
1j
Out[31]:
1j
In [32]:
i = complex(0,1)
In [42]:
fromfunction
Out[42]:
<function numpy.core.numeric.fromfunction>
In [79]:
x = [0,0,1,1,-1,-1,0,0]
In [80]:
y = dot(M,x)
In [81]:
plot(abs(y[0:N/2])**2)
Out[81]:
[<matplotlib.lines.Line2D at 0x10d51d7d0>]
In [70]:
a = 3+4j
In [71]:
a * conj(a)
Out[71]:
(25+0j)
In [72]:
len(a)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-72-af8c77e09569> in <module>()
----> 1 len(a)

TypeError: object of type 'complex' has no len()
In [73]:
dir(a)
Out[73]:
['__abs__',
 '__add__',
 '__class__',
 '__coerce__',
 '__delattr__',
 '__div__',
 '__divmod__',
 '__doc__',
 '__eq__',
 '__float__',
 '__floordiv__',
 '__format__',
 '__ge__',
 '__getattribute__',
 '__getnewargs__',
 '__gt__',
 '__hash__',
 '__init__',
 '__int__',
 '__le__',
 '__long__',
 '__lt__',
 '__mod__',
 '__mul__',
 '__ne__',
 '__neg__',
 '__new__',
 '__nonzero__',
 '__pos__',
 '__pow__',
 '__radd__',
 '__rdiv__',
 '__rdivmod__',
 '__reduce__',
 '__reduce_ex__',
 '__repr__',
 '__rfloordiv__',
 '__rmod__',
 '__rmul__',
 '__rpow__',
 '__rsub__',
 '__rtruediv__',
 '__setattr__',
 '__sizeof__',
 '__str__',
 '__sub__',
 '__subclasshook__',
 '__truediv__',
 'conjugate',
 'imag',
 'real']
In [74]:
arg(a)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-74-a8eb7616bb38> in <module>()
----> 1 arg(a)

NameError: name 'arg' is not defined
In [75]:
a.arg()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-75-b7f340a25bc7> in <module>()
----> 1 a.arg()

AttributeError: 'complex' object has no attribute 'arg'
In [76]:
abs(a)
Out[76]:
5.0
In []: