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

◆ Cosqmf()

Sub Cosqmf ( 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 quarter cosine transform (multiple sequences)

Purpose
This routine computes the one-dimensional Fourier transform of multiple sequences within a real array, where each of a sequence is a cosine series with odd wave numbers. This is referred to as the forward transform or Fourier analysis, transforming the sequence from physical to spectral space.
R(l*jump+k) = R(l*jump)/N + (2/N)ΣR(l*jump+j)cos(πj(2k+1)/(2n)) (Σ for j = 1 to N-1) (l = 0 to lot-1, k = 0 to N-1)
This transform is normalized since a call to Cosqmf followed by a call to Cosqmb (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 >= 2*N + ln(N)/ln(2) + 4)
Work data. Its contents must be initialized with a call to Cosqmi before the first call to Cosqmf or Cosqmb 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 cosine transform and backward transform of 2 sequences of 5 random data successively, and compare with the original data sequences.
Sub Ex_Cosqm()
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 = 2 * N + Log(N) / Log(2) + 4
ReDim Wsave(LWsave - 1)
Call Cosqmi(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 Cosqmf(Lot, Jump, N, R(), Wsave(), Info)
If Info <> 0 Then GoTo Err
'-- Backward transform
Call Cosqmb(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 Cosqmi/Cosqmf/Cosqmb: Info =", Info
End Sub
Example Results
0.470751464366913 0.470751464366913 5.55111512312578E-17
0.689472317695618 0.689472317695618 0
0.256393253803253 0.256393253803253 1.11022302462516E-16
0.323879957199097 0.323879957199097 1.11022302462516E-16
0.504171311855316 0.504171311855316 0
0.752542853355408 0.752542853355408 2.22044604925031E-16
0.827191412448883 0.827191412448883 0
0.581456184387207 0.581456184387207 0
7.15305209159851E-02 7.15305209159852E-02 5.55111512312578E-17
0.280201554298401 0.280201554298401 -5.55111512312578E-17