XLPack 6.1
Excel VBA Numerical Library Reference Manual
Loading...
Searching...
No Matches

◆ Cfftmf()

Sub Cfftmf ( Lot As  Long,
Jump As  Long,
N As  Long,
C() As  Complex,
Wsave() As  Double,
Info As  Long,
Optional Inc As  Long = 1 
)

One-dimensional complex Fourier transform (multiple sequences)

Purpose
This routine computes the one-dimensional Fourier transform of multiple periodic sequences within a real array. This is referred to as the forward transform or Fourier analysis, transforming the sequence from physical to spectral space.
C(l*jump+k) = (1/N)ΣC(l*jump+j)exp(-2πijk/N) (Σ for j = 0 to N-1) (l = 0 to lot-1, k = 0 to N-1) (i is imaginary unit)
This transform is normalized since a call to Cfftmf followed by a call to Cfftmb (or vice-versa) reproduces the original array subject to algorithmic constraints, roundoff error, etc.
Parameters
[in]LotNumber of sequences to be transformed. (Lot >= 1)
[in]JumpIncrement between the locations, in array C(), of the first elements of two consecutive sequences to be transformed. (Jump >= 1)
[in]NLength of the sequence to be transformed. (N >= 1) (The transform is most efficient when N is a product of small primes)
[in,out]C()Array C(LC - 1) (LC >= (Lot - 1)*Jump + IncC*(N - 1) + 1)
[in] The sequences to be transformed.
[out] The Fourier forward transformed sequences of data.
[in]Wsave()Array Wsave(LWsave - 1) (LWsave >= 2*N + ln(N)/ln(2) + 4)
Work data. Its contents must be initialized with a call to Cfftmi before the first call to Cfftmf or Cfftmb for a given transform length N.
[out]Info= 0: Successful exit.
= -1: The argument Lot had an illegal value. (Lot < 1, or, Lot, Jump, N and Inc are inconsistent)
= -2: The argument Jump had an illegal value. (Jump < 1)
= -3: The argument N had an illegal value. (N < 1)
= -4: The argument C() had an illegal value. (Array C() is not big enough)
= -5: The argument Wsave() had an illegal value. (Array Wsave() is not big enough)
= -7: The argument Inc had an illegal value. (Inc < 1)
[in]Inc(Optional)
Integer increment between the locations, in array C(), of two consecutive elements within the sequence. (Inc >= 1) (default = 1)
Reference
FFTPACK
Example Program
Compute the Fourier transform and backward transform of 2 sequences of 5 random data successively, and compare with the original data sequences.
Sub Ex_Cfftm()
Const N = 5, Lot = 2, Jump = N
Dim Wsave() As Double, C(Lot * N - 1) As Complex, C0(Lot * N - 1) As Complex
Dim LWsave As Long, Info As Long, I As Long, J As Long, K As Long
'-- Initialization
LWsave = 2 * N + Log(N) / Log(2) + 4
ReDim Wsave(LWsave - 1)
Call Cfftmi(N, Wsave, Info)
If Info <> 0 Then GoTo Err
'-- Generate test data
For I = 0 To Lot * N - 1
C(I) = Cmplx(Rnd(), Rnd())
C0(I) = Cmplx(Creal(C(I)), Cimag(C(I)))
Next
'-- Forward transform
Call Cfftmf(Lot, Jump, N, C(), Wsave(), Info)
If Info <> 0 Then GoTo Err
'-- Backward transform
Call Cfftmb(Lot, Jump, N, C(), Wsave(), Info)
If Info <> 0 Then GoTo Err
'-- Print result
For J = 0 To Lot - 1
For I = 0 To N - 1
K = J * Jump + I
Debug.Print "(" & CStr(Creal(C0(K))) & ", " & CStr(Cimag(C0(K))) & ")", "(" & CStr(Creal(C(K))) & ", " & CStr(Cimag(C(K))) & ")", Cabs(Csub(C(K), C0(K)))
Next
Debug.Print
Next
Exit Sub
Err:
Debug.Print "Error in Cfftmi/Cfftmf/Cfftmb: Info =", Info
End Sub
Example Results
(0.661798179149628, 0.545043110847473) (0.661798179149628, 0.545043110847473) 1.57009245868378E-16
(0.403548061847687, 0.740813970565796) (0.403548061847687, 0.740813970565796) 1.24126707662364E-16
(0.678173959255219, 0.956120848655701) (0.678173959255219, 0.956120848655701) 3.14018491736755E-16
(3.96996140480042E-02, 0.474205017089844) (3.96996140480041E-02, 0.474205017089844) 7.85046229341888E-17
(0.802463710308075, 0.859862923622131) (0.802463710308075, 0.859862923622131) 2.48253415324727E-16
(0.748639404773712, 0.33688759803772) (0.748639404773712, 0.33688759803772) 0
(0.495910108089447, 0.185041308403015) (0.495910108089447, 0.185041308403015) 5.55111512312578E-17
(0.806551516056061, 0.312809467315674) (0.806551516056061, 0.312809467315674) 2.28878339926112E-16
(0.369169890880585, 0.412185788154602) (0.369169890880585, 0.412185788154602) 7.85046229341888E-17
(0.8343465924263, 0.351738691329956) (0.8343465924263, 0.351738691329956) 2.22044604925031E-16