HTBasic Help
×
Menu
Index
Correlate
Correlation of two sequences.
 
Loading        LOADSUB ALL FROM "FFT.HTS"
or LOADSUB FROM "MATHLIB.HTS"
or LOADSUB Correlate FROM "MATHLIB.HTS"
 
Usage                INTEGER Logn
REAL A(*),B(*),C(*),S(*)
CALL Correlate(Logn,A(*),B(*),C(*),S(*))
 
Description                
Correlate calculates the correlation of the sequences in the arrays A and B and places the result in the array C. Logn is the base-2 log of the number of points in the sequences to be correlated. The arrays A and B must have at least 2Logn elements and the array C must have at least 2Logn+1 elements; if they have more than the required number of elements, the extra elements are ignored and unmodified. S is a scratch array of at least the size of C. It contains nothing useful after the function has run, but is needed to store intermediate results within the function. The number of elements in A and B denoted by each permitted value of Logn is shown in the table below:
 
Logn                No. Elements (2Logn)
2                4
3                8
4                16
5                32
6                64
7                128
8                256
9                512
10                1024
11                2048
12                4096
13                8192
14                16384
 
 
The number of elements required in C and S for each value of Logn is twice the value given in the table above. S is used internally by Correlate and contains no usefule data after Correlate has run.
 
Correlation is a measure of two functions' similarities to each other as the abscissa is shifted. If a(x) and b(x) are the functions being tested, if the interval of interest is x (0,T), and if a and b are zero outside this interval, the correlation, c(x) of f and g is defined by the relation
Note that, while a(x) and b(x) are nonzero on the interval x (0,T), c(x) is nonzero on the interval x (-T,T).
 
If the functions a and b are only defined at regularly-spaced discrete points x = [k+½]T/N, k = {0,1,2,...,N-1}, the integration can be approximated by assuming that a(x) and b(x) are constant and equal to a([k+½]T/N) and b([k+½]T/N) between x = kT/N and x = (k+1)T/N. The expression above can then be replaced by
 In this case, c([k+½]T/N) is defined for k = {-(N-1),...,0,...,N-1}.
 
Correlate returns the values of c([k+½]T/N) in the array C. The first N elements in C represent k = {0,1,...,N-1} and the last N elements in C represent k = {-N,-(N-1),..,-1}.
 
Errors                
Correlate causes an HTBasic error if its arguments are not of the types shown in the USAGE section, above, if Logn is not between 2 and 15, inclusive, or if the size of A, B, or C is smaller than the values described above.
 
See Also
Autocorrelate, Convolve, Corr, Fft, Power_spectrum