Demo dftmatrixexamples

Demonstrate the kernel matrix for the DFT Transform.

Imports


In [9]:
import sys,os
%matplotlib inline
ia898path = os.path.abspath('/etc/jupyterhub/ia898_1s2017/')
if ia898path not in sys.path:
    sys.path.append(ia898path)
import ia898.src as ia
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
from numpy.fft import fft2
from numpy.fft import ifft2

Função iadftmatrix

Synopse

Kernel matrix for the 1-D Discrete Fourier Transform DFT.

  • A = iadftmatrix(N)

    • N:Input: Integer, number of points of the DFT.
    • A:Output image, square N x N, complex

In [12]:
def iadftmatrix(N):
    x = np.arange(N).reshape(N,1)
    u = x
    Wn = np.exp(-1j*2*np.pi/N)
    A = (1./np.sqrt(N)) * (Wn ** np.dot(u, x.T))
    return A

Kernel images generated

Imaginary and real parts of the DFT kernel.


In [13]:
A = iadftmatrix(128)

plt.figure(1)
plt.imshow((A.real),cmap='gray')
plt.title('A.real')
plt.colorbar()

plt.figure(2)
plt.imshow((A.imag),cmap='gray')
plt.title('A.imag')
plt.colorbar()


Out[13]:
<matplotlib.colorbar.Colorbar at 0x7f4282defd30>

Four first lines

Four first lines from real and imaginary parts of the kernel matrix. Observe the increasing frequencies of the senoidals (imaginary part) and cossenoidals (real part).


In [7]:
plt.figure(1, figsize=(10,10))

plt.subplot(2,2,1)
plt.title('u = 0')
plt.plot(A.real[0,:], 'r')
plt.plot(A.imag[0,:], 'g')

plt.subplot(2,2,2)
plt.title('u = 1')
plt.plot(A.real[1,:], 'r')
plt.plot(A.imag[1,:], 'g')

plt.subplot(2,2,3)
plt.title('u = 2')
plt.plot(A.real[2,:], 'r')
plt.plot(A.imag[2,:], 'g')

plt.subplot(2,2,4)
plt.title('u = 3')
plt.plot(A.real[3,:], 'r')
plt.plot(A.imag[3,:], 'g')

plt.show()


Showing complex conjugates


In [8]:
plt.figure(1, figsize=(10,10))

plt.subplot(2,2,1)
plt.title('u = 0')
plt.plot(A.real[ 0,:], 'r')
plt.plot(A.imag[ 0,:], 'g')

plt.subplot(2,2,2)
plt.title('u = -1')
plt.plot(A.real[-1,:], 'r')
plt.plot(A.imag[-1,:], 'g')

plt.subplot(2,2,3)
plt.title('u = -2')
plt.plot(A.real[-2,:], 'r')
plt.plot(A.imag[-2,:], 'g')

plt.subplot(2,2,4)
plt.title('u = -3')
plt.plot(A.real[-3,:], 'r')
plt.plot(A.imag[-3,:], 'g')

plt.show()


Reference

Contributions

Luis Antonio Prado, 1st semester 2017