1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
|
program test
parameter(M=2**2)
integer i,j
complex A(2*m),B(2*m),C(2*m),D(2*m)
do i=1,2*M
A(i)=cmplx(1.,2.*i)
B(i)=cmplx(2.,3.*i)
enddo
call conv(A,B,M,C)
print 20,(C(i),i=1,2*M)
20 format('C=',8(F16.8,1X))
call fft1d(A,200,2*M)
call fft1d(B,200,2*M)
do i=1,2*M
D(i)=A(i)*B(i)
enddo
call ifft1d(D,200,2*M)
print 30,(D(i),i=1,2*m)
30 format('S=',8(F16.8,1X))
end
! subroutine pour calculer A*B
subroutine conv(A,B,M,C)
integer i,j,l1,l2
complex A(2*M),B(2*M),C(2*M)
do i=1,2*M
C(i)=(0.,0.)
do l1=1,2*M
C(i)=C(i)+A(i-l1)*B(l1)
enddo
enddo
return
end
! subroutine pour calcule le produit element par element
subroutine wise(AA,BB,MM,CC)
integer i,j,l1,l2
complex AA(2*MM),BB(2*MM),CC(2*MM)
do l1=1,2*MM
CC(i)=AA(i)*BB(i)
enddo
return
end
subroutine ifft1d(z, m, n)
complex z(*)
complex zt,wt,w(2**15)
double precision p
integer n,m,m2
save w, m2
data m2 /-1/
if (m .eq. 0) then
return
endif
C Pass back sin/cos table if not previously initialized.
if (m .ne. m2) then
p = 6.283185307179586d0/n
do k = 1,n/2
C Coefficients for ifft.
w(k) = cmplx(cos(p*(k-1)),sin(p*(k-1)))
C Coefficients for fft.
w(k+n/2) = conjg(w(k))
end do
m2 = m
end if
C Unit stride.
ks = 1
nlast = n
n2 = n
kn2 = ks*n
ie = 1
do k = 1,m
n1 = n2
kn1 = kn2
n2 = n2/2
kn2 = kn2/2
ia = 1
kj = 1
do j = 1,n2
wt = w(ia)
ia = ia + ie
ki = kj
do i = j,n,n1
kl = ki + kn2
zt = z(ki) - z(kl)
z(ki) = z(ki) + z(kl)
z(kl) = wt*zt
ki = ki+kn1
end do
kj = kj+ks
end do
ie = ie+ie
end do
ki = 1
do i = 1,n
z(ki) = z(ki)/float(n)
ki = ki+ks
end do
j = 1
n1 = n - 1
ki = 1
kj = 1
do i=1,n1
if(i.lt.j) then
zt = z(kj)
z(kj) = z(ki)
z(ki) = zt
endif
k = n/2
do while (k.lt.j)
j = j - k
k = k/2
end do
j = j + k
kj = ks*(j-1) + 1
ki = ki + ks
end do
return
end
subroutine fft1d(z,m,n)
complex z(*)
complex zt,wt,w(2**15)
double precision p
integer n,m,m2
save w, m2
data m2 /-1/
if (m .eq. 0) then
return
endif
C Pass back sin/cos table if not previously initialized.
if (m .ne. m2) then
p = 6.283185307179586d0/n
do k = 1,n/2
C Coefficients for ifft.
w(k) = cmplx(cos(p*(k-1)),sin(p*(k-1)))
C Coefficients for fft.
w(k+n/2) = conjg(w(k))
enddo
m2 = m
endif
C Unit stride.
ks = 1
n2 = n
kn2 = ks*n
ie = 1
C Use second half of table.
ia1 = n/2 + 1
do k = 1,m
n1 = n2
kn1 = kn2
n2 = n2/2
kn2 = kn2/2
ia= ia1
kj = 1
do j = 1,n2
wt = w(ia)
ia = ia + ie
ki = kj
do i = j,n,n1
kl = ki + kn2
zt = z(ki) - z(kl)
z(ki) = z(ki) + z(kl)
z(kl) = wt*zt
ki = ki+kn1
end do
kj = kj+ks
end do
ie = ie+ie
end do
j = 1
n1 = n - 1
ki = 1
kj = 1
do i=1,n1
if(i.lt.j) then
zt = z(kj)
z(kj) = z(ki)
z(ki) = zt
endif
k = n/2
do while (k.lt.j)
j = j - k
k = k/2
end do
j = j + k
kj = ks*(j-1) + 1
ki = ki + ks
end do
return
end |
Partager