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

◆ Rfftmf()

Sub Rfftmf ( Lot As  Long,
Jump As  Long,
N As  Long,
R() As  Double,
Wsave() As  Double,
Info As  Long,
Optional Inc As  Long = 1 
)

One-dimensional real 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.
R(l*Jump) = (1/N)ΣR(l*Jump+j) (Σ for j = 0 to N-1) (l = 0 to Lot-1)
R(l*Jump+2k-1) = (2/N)ΣR(l*Jump+j)cos(2πjk/N) (Σ for j = 0 to N-1) (l = 0 to Lot-1, k = 1 to Nh)
R(l*Jump+2k) = (2/N)ΣR(l*Jump+j)sin(2πjk/N) (Σ for j = 0 to N-1) (l = 0 to Lot-1, k = 1 to Nh)
R(l*Jump+N-1) = (1/N)Σ(-1)^j R(l*Jump+j) (only if N is even) (Σ for j = 0 to N-1) (l = 0 to Lot-1)
(If N is even, Nh = N/2-1. If N is odd, Nh = (N-1)/2)
This transform is normalized since a call to Rfftmf followed by a call to Rfftmb (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 R(), 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]R()Array R(LR - 1) (LR >= (Lot - 1)*Jump + Inc*(N - 1) + 1)
[in] The sequences to be transformed.
[out] The Fourier forward transformed sequences of data.
[in]Wsave()Array Wsave(LWsave - 1) (LWsave >= N + ln(N)/ln(2) + 4)
Work data. Its contents must be initialized with a call to Rfftmi before the first call to Rfftmf or Rfftmb 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 R() had an illegal value. (Array R() 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 R(), 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_Rfftm()
Const N = 5, Lot = 2, Jump = N
Dim Wsave() As Double, R(Lot * N - 1) As Double, R0(Lot * N - 1) As Double
Dim LWsave As Long, Info As Long, I As Long, J As Long, K As Long
'-- Initialization
LWsave = N + Log(N) / Log(2) + 4
ReDim Wsave(LWsave - 1)
Call Rfftmi(N, Wsave, Info)
If Info <> 0 Then GoTo Err
'-- Generate test data
For I = 0 To Lot * N - 1
R(I) = Rnd()
R0(I) = R(I)
Next
'-- Forward transform
Call Rfftmf(Lot, Jump, N, R(), Wsave(), Info)
If Info <> 0 Then GoTo Err
'-- Backward transform
Call Rfftmb(Lot, Jump, N, R(), 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 R0(K), R(K), R(K) - R0(K)
Next
Debug.Print
Next
Exit Sub
Err:
Debug.Print "Error in Rfftmi/Rfftmf/Rfftmb: Info =", Info
End Sub
Example Results
0.774740099906921 0.774740099906921 1.11022302462516E-16
0.014017641544342 0.014017641544342 -5.55111512312578E-17
0.76072359085083 0.76072359085083 0
0.814490020275116 0.814490020275116 0
0.709037899971008 0.709037899971008 0
4.53527569770813E-02 4.53527569770813E-02 2.08166817117217E-17
0.414032697677612 0.414032697677612 0
0.862619340419769 0.862619340419769 1.11022302462516E-16
0.790480017662048 0.790480017662048 1.11022302462516E-16
0.373536169528961 0.373536169528961 0