lionisEX08

Autor: lionis
Data: 14/05/2009

Estudo das funções iacos, iadft e iadftview

iacos

As equações para a função iacos são definidas a seguir:

iadft

As equações da função iadft, para os campos unidimensionais e bidimensionais, são dadas por:

Transformada Discreta de Fourier (TDF)

 1 f = iacos([200,200], 100, pi/2, 0)
 2 F = iadft(f)
 3 Fv = iadftview(F)
 4 adshow(ianormalize(f, [0,255]), title = 'Função iacos')
 5 adshow(ianormalize(Fv, [0,255]), title = 'Transformada Discreta de Fourier da iacos')
 6 
 7 def centerSquare(lenght): #1/4
 8     cellLenght = lenght/8
 9     I = zeros([lenght, lenght])
10     squareLenght = round(float(lenght)/4)
11     squarePosition = round(float(lenght)*3/8)
12     I[squarePosition:squarePosition+squareLenght,squarePosition:squarePosition+squareLenght] = 1
13 
14     return I
15 
16 f = centerSquare(256)
17 F = iadft(f)
18 Fv = iadftview(F)
19 adshow(ianormalize(f, [0,255]), title = 'Quadrado no centro')
20 adshow(ianormalize(Fv, [0,255]), title = 'Transformada Discreta de Fourier do quadrado')
21 
22 def chessTable(lenght): #8x8
23     cellLenght = lenght/8
24     I = zeros([lenght, lenght])
25 
26     for i in range(0, cellLenght):
27         for j in range(0, cellLenght):
28             I[i:lenght:2*cellLenght,j:lenght:2*cellLenght] = 1
29 
30     for i in range(cellLenght,2*cellLenght):
31         for j in range(cellLenght,2*cellLenght):
32             I[i:lenght:2*cellLenght,j:lenght:2*cellLenght] = 1
33 
34     return I
35 
36 f = chessTable(256)
37 F = iadft(f)
38 Fv = iadftview(F)
39 adshow(ianormalize(f, [0,255]), title = 'Tabuleiro de xadrez')
40 adshow(ianormalize(Fv, [0,255]), title = 'Transformada Discreta de Fourier do tabuleiro')

Função iacos

Transformada Discreta de Fourier da iacos

Quadrado no centro

Transformada Discreta de Fourier do quadrado

Tabuleiro de xadrez

Transformada Discreta de Fourier do tabuleiro

Reconstrução da função original

(Exemplo 1) Função cosseno: nota-se que nesse caso, a componente da base é 0, e apenas a componente cosseno de frequência 1 não é nula.

 1 f = array([1,sqrt(2)/2,0,-sqrt(2)/2,-1,-sqrt(2)/2,0,sqrt(2)/2])
 2 F = iadft(f)
 3 Fs = iafftshift(F)
 4 print "Função original f"
 5 print f
 6 print ""
 7 print "TDF"
 8 print F
 9 print ""
10 print "TDF shifted (centralizada)"
11 print Fs
Função original f
[ 1.          0.70710678  0.         -0.70710678 -1.         -0.70710678
  0.          0.70710678]

TDF
[[  0.00000000e+00 +0.00000000e+00j]
 [  4.00000000e+00 +1.25607397e-15j]
 [ -1.25607397e-15 -9.42055475e-16j]
 [ -8.63550852e-16 -1.25607397e-15j]
 [  0.00000000e+00 -1.77635684e-15j]
 [  9.42055475e-16 -2.19812944e-15j]
 [  3.76822190e-15 -2.66915718e-15j]
 [  4.00000000e+00 +9.26354551e-15j]]

TDF shifted (centralizada)
[[  0.00000000e+00+0.j]
 [  9.42055475e-16+0.j]
 [  3.76822190e-15+0.j]
 [  4.00000000e+00+0.j]
 [  0.00000000e+00+0.j]
 [  4.00000000e+00+0.j]
 [ -1.25607397e-15+0.j]
 [ -8.63550852e-16+0.j]]

(Exemplo 2) Será utilizado um array de tamanho 8.

 1 f = array([0,0,0,0,1,1,1,1])
 2 F = iadft(f)
 3 Fs = iafftshift(F)
 4 
 5 print "Função original f"
 6 print f
 7 print ""
 8 print "TDF"
 9 print F
10 print ""
11 print "TDF shifted (centralizada)"
12 print Fs
13 mmplot([[f]],['set yrange [-1:2]','set xrange [0:8]'], ptitle='Funcao f(x) original com 8 amostras')
Função original f
[0 0 0 0 1 1 1 1]

TDF
[[  4.00000000e+00 +0.00000000e+00j]
 [ -1.00000000e+00 +2.41421356e+00j]
 [ -4.55247513e-16 -3.14018492e-16j]
 [ -1.00000000e+00 +4.14213562e-01j]
 [  0.00000000e+00 -8.88178420e-16j]
 [ -1.00000000e+00 -4.14213562e-01j]
 [  1.36574254e-15 -1.25607397e-15j]
 [ -1.00000000e+00 -2.41421356e+00j]]

TDF shifted (centralizada)
[[  0.00000000e+00+0.j]
 [ -1.00000000e+00+0.j]
 [  1.36574254e-15+0.j]
 [ -1.00000000e+00+0.j]
 [  4.00000000e+00+0.j]
 [ -1.00000000e+00+0.j]
 [ -4.55247513e-16+0.j]
 [ -1.00000000e+00+0.j]]

Será criado o vetor "newF" para realizar a reconstrução gradativa da função original.

 1 newF = zeros(8,complex)
 2 
 3 newF[0] = abs(F[0,0])
 4 print "TDF a ser reconstruída"
 5 print newF
 6 print "TDF reconstruída apenas com a componente básica"
 7 print iaidft(newF)
 8 mmplot([[iaidft(newF)]],['set yrange [-1:2]','set xrange [0:8]'], ptitle='TDF reconstruida com apenas a componente basica F(0)')
 9 print ""
10 
11 
12 newF[1] = F[1,0]
13 newF[7] = F[7,0]
14 print "TDF a ser reconstruída"
15 print newF
16 print "TDF reconstruída com a componente de frequência 1"
17 print iaidft(newF)
18 mmplot([[iaidft(newF)]],['set yrange [-1:2]','set xrange [0:8]'], ptitle='TDF reconstruida com as componentes F(1) e F(7)')
19 print ""
20 
21 newF[2] = F[2,0]
22 newF[6] = F[6,0]
23 print "TDF a ser reconstruída"
24 print newF
25 print "TDF reconstruída com a componente de frequência 2"
26 print iaidft(newF)
27 mmplot([[iaidft(newF)]],['set yrange [-1:2]','set xrange [0:8]'], ptitle='TDF reconstruida com as componentes F(2) e F(6)')
28 print ""
29 
30 newF[3] = F[3,0]
31 newF[5] = F[5,0]
32 print "TDF a ser reconstruída"
33 print newF
34 print "TDF reconstruída com a componente de frequência 3"
35 print iaidft(newF)
36 mmplot([[iaidft(newF)]],['set yrange [-1:2]','set xrange [0:8]'], ptitle='TDF reconstruida com as componentes F(3) e F(5)')
37 print ""
38 
39 newF[4] = F[4,0]
40 print "TDF a ser reconstruída"
41 print newF
42 print "TDF reconstruída com a componente de frequência 4"
43 print iaidft(newF)
44 mmplot([[iaidft(newF)]],['set yrange [-1:2]','set xrange [0:8]'], ptitle='TDF reconstruida com a componente F(4)')
45 print ""
46 
47 print "Função original=",f
48 print "Função reconstruída"
49 print iaidft(newF)
TDF a ser reconstruída
[ 4.+0.j  0.+0.j  0.+0.j  0.+0.j  0.+0.j  0.+0.j  0.+0.j  0.+0.j]
TDF reconstruída apenas com a componente básica
[[ 0.5+0.j]
 [ 0.5+0.j]
 [ 0.5+0.j]
 [ 0.5+0.j]
 [ 0.5+0.j]
 [ 0.5+0.j]
 [ 0.5+0.j]
 [ 0.5+0.j]]

TDF a ser reconstruída
[ 4.+0.j         -1.+2.41421356j  0.+0.j          0.+0.j          0.+0.j
  0.+0.j          0.+0.j         -1.-2.41421356j]
TDF reconstruída com a componente de frequência 1
[[ 0.25000000 +0.00000000e+00j]
 [-0.10355341 +2.35513869e-16j]
 [-0.10355341 +5.29906205e-16j]
 [ 0.24999998 +3.53270803e-16j]
 [ 0.75000000 -4.31775426e-16j]
 [ 1.10355341 -1.33457859e-15j]
 [ 1.10355341 -1.60934477e-15j]
 [ 0.75000002 -7.06541606e-16j]]

TDF a ser reconstruída
[  4.00000000e+00 +0.00000000e+00j  -1.00000000e+00 +2.41421356e+00j
  -4.55247513e-16 -3.14018492e-16j   0.00000000e+00 +0.00000000e+00j
   0.00000000e+00 +0.00000000e+00j   0.00000000e+00 +0.00000000e+00j
   1.36574254e-15 -1.25607397e-15j  -1.00000000e+00 -2.41421356e+00j]
TDF reconstruída com a componente de frequência 2
[[ 0.25000000 -1.96261557e-16j]
 [-0.10355341 +0.00000000e+00j]
 [-0.10355341 +7.26167762e-16j]
 [ 0.24999998 +5.49532361e-16j]
 [ 0.75000000 -6.28036983e-16j]
 [ 1.10355341 -1.57009246e-15j]
 [ 1.10355341 -1.41308321e-15j]
 [ 0.75000002 -5.10280049e-16j]]

TDF a ser reconstruída
[  4.00000000e+00 +0.00000000e+00j  -1.00000000e+00 +2.41421356e+00j
  -4.55247513e-16 -3.14018492e-16j  -1.00000000e+00 +4.14213562e-01j
   0.00000000e+00 +0.00000000e+00j  -1.00000000e+00 -4.14213562e-01j
   1.36574254e-15 -1.25607397e-15j  -1.00000000e+00 -2.41421356e+00j]
TDF reconstruída com a componente de frequência 3
[[  9.81307787e-17 -1.96261557e-16j]
 [ -1.77846450e-08 -3.92523115e-17j]
 [ -2.23517418e-08 +6.28036983e-16j]
 [ -1.77846440e-08 +8.63550852e-16j]
 [  1.00000000e+00 -1.05981241e-15j]
 [  1.00000002e+00 -1.33457859e-15j]
 [  1.00000002e+00 -1.13831703e-15j]
 [  1.00000002e+00 -1.25607397e-15j]]

TDF a ser reconstruída
[  4.00000000e+00 +0.00000000e+00j  -1.00000000e+00 +2.41421356e+00j
  -4.55247513e-16 -3.14018492e-16j  -1.00000000e+00 +4.14213562e-01j
   0.00000000e+00 -8.88178420e-16j  -1.00000000e+00 -4.14213562e-01j
   1.36574254e-15 -1.25607397e-15j  -1.00000000e+00 -2.41421356e+00j]
TDF reconstruída com a componente de frequência 4
[[  9.81307787e-17 -2.74766180e-16j]
 [ -1.77846450e-08 +7.85046229e-17j]
 [ -2.23517418e-08 +5.10280049e-16j]
 [ -1.77846440e-08 +9.42055475e-16j]
 [  1.00000000e+00 -1.13831703e-15j]
 [  1.00000002e+00 -1.21682166e-15j]
 [  1.00000002e+00 -1.25607397e-15j]
 [  1.00000002e+00 -1.17756934e-15j]]

Função original= [0 0 0 0 1 1 1 1]
Função reconstruída
[[  9.81307787e-17 -2.74766180e-16j]
 [ -1.77846450e-08 +7.85046229e-17j]
 [ -2.23517418e-08 +5.10280049e-16j]
 [ -1.77846440e-08 +9.42055475e-16j]
 [  1.00000000e+00 -1.13831703e-15j]
 [  1.00000002e+00 -1.21682166e-15j]
 [  1.00000002e+00 -1.25607397e-15j]
 [  1.00000002e+00 -1.17756934e-15j]]