|
|
◆ Rfft2f()
| Sub Rfft2f |
( |
L As |
Long, |
|
|
M As |
Long, |
|
|
R() As |
Double, |
|
|
Wsave() As |
Double, |
|
|
Info As |
Long |
|
) |
| |
Two-dimensional real Fourier transform
- Purpose
- This routine computes the two-dimensional Fourier transform of a periodic sequence within a real array. This is referred to as the forward transform or Fourier analysis, transforming the sequence from physical to spectral space. The full complex transform is given by:
c(j,k) = (1/lm)ΣΣR(l1,m1)exp(-2πi(j*l1/L+k*m1/M)) (1st Σ for l1 = 0 to L-1, 2nd Σ for m1 = 0 to M-1) (j = 0 to L-1, k = 0 to M-1) (i is imaginary unit)
This transform is normalized since a call to Rfft2f followed by a call to Rfft2b (or vice-versa) reproduces the original array subject to algorithmic constraints, roundoff error, etc.
- Parameters
-
| [in] | L | Number of elements to be transformed in the first dimension of the two-dimensional array R(). (L >= 1) (The transform is most efficient when L is a product of small primes) |
| [in] | M | Number of elements to be transformed in the second dimension of the two-dimensional array R(). (M >= 1) (The transform is most efficient when M is a product of small primes) |
| [in,out] | R() | Array R(LR1 - 1, LR2 - 1) (LR1 >= L, LR2 >= M)
[in] The two dimensional real sequence data to be transformed. [out] The Fourier forward transformed two dimensional complex sequence data c(i,j) (i = 0 to l-1, j = 0 to m-1). The complex transform of the real sequence data has conjugate symmetry. That is, c(i,j) = conj(c(l-i,m-j)), so only half the transform is computed and packed back into the original array R() as shown in the further details below. |
| [in] | Wsave() | Array Wsave(LWsave - 1) (LWsave >= L + 3*M + ln(L)/ln(2) + 2*ln(M)/ln(2) + 12)
Work data. Its contents must be initialized with a call to Rfft2i before the first call to Rfft2f or Rfft2b for a given transform length L and M. |
| [out] | Info | = 0: Successful exit.
= -1: The argument L had an illegal value. (L < 1)
= -2: The argument M had an illegal value. (M < 1)
= -3: The argument R() is invalid. (Array R() is not big enough)
= -4: The argument Wsave() is invalid. (Array Wsave() is not big enough) |
- Further Details
- Let a(i,j) = re(c(i,j)) and b(i,j) = im(c(i,j)), then the packed data of the forward transform are stored in R() as following examples:
l = m = 4
a(0,0)* a(0,1) b(0,1) a(0,2)*
R(i,j) = a(1,0) a(1,1) a(1,2) a(1,3)
b(1,0) b(1,1) b(1,2) b(1,3)
a(2,0)* a(2,1) b(2,1) a(2,2)*
l = m = 5
a(0,0)* a(0,1) b(0,1) a(0,2) b(0,2)
a(1,0) a(1,1) a(1,2) a(1,3) a(1,4)
R(i,j) = b(1,0) b(1,1) b(1,2) b(1,3) b(1,4)
a(2,0) a(2,1) a(2,2) a(2,3) a(2,4)
b(2,0) b(2,1) b(2,2) b(2,3) b(2,4)
*: Imaginary part = 0
The remaining c(i,j) for i = (L+1)/2 to L-1 and j = 0 to M-1 can be obtained via the conjugate symmetry. For even L, c(L/2,j) = conj(c(L/2,M-j).
- Reference
- FFTPACK
- Example Program
- Compute the two-dimensional Fourier transform and backward transform of 4 rows x 4 columns random data sequence successively, and compare with the original data sequence.
Sub Ex_Rfft2()
Const L = 4, M = 4
Dim Wsave() As Double, R(L - 1, M - 1) As Double, R0(L - 1, M - 1) As Double
Dim LWsave As Long, Info As Long, I As Long, J As Long
'-- Initialization
LWsave = L + 3 * M + Log(L) / Log(2) + 2 * Log(M) / Log(2) + 12
ReDim Wsave(LWsave - 1)
Call Rfft2i(L, M, Wsave, Info)
If Info <> 0 Then GoTo Err
'-- Generate test data
For I = 0 To L - 1
For J = 0 To M - 1
R(I, J) = Rnd()
R0(I, J) = R(I, J)
Next
Next
'-- Forward transform
Call Rfft2f(L, M, R(), Wsave(), Info)
If Info <> 0 Then GoTo Err
'-- Backward transform
Call Rfft2b(L, M, R(), Wsave(), Info)
If Info <> 0 Then GoTo Err
'-- Print result
For J = 0 To M - 1
For I = 0 To L - 1
Debug.Print R0(I, J), R(I, J), R(I, J) - R0(I, J)
Next
Debug.Print
Next
Exit Sub
Err:
Debug.Print "Error in Rfft2i/Rfft2f/Rfft2b: Info =", Info
End Sub
- Example Results
0.805006325244904 0.805006325244904 0
0.204303324222565 0.204303324222565 0
0.446774303913116 0.446774303913116 0
0.939462721347809 0.939462721347809 0
0.215638399124146 0.215638399124146 0
0.995530605316162 0.995530605316162 0
0.468557119369507 0.468557119369507 0
0.22608757019043 0.22608757019043 0
0.71610301733017 0.71610301733017 0
0.69307678937912 0.69307678937912 0
0.922678887844086 0.922678887844086 0
0.193300426006317 0.193300426006317 0
0.955126643180847 0.955126643180847 0
0.324254155158997 0.324254155158997 0
0.939402937889099 0.939402937889099 0
0.747899651527405 0.747899651527405 0
|