HTBasic Help
×
Menu
Index
Autocorrelate
Autocorrelation of a sequence.
 
Loading        LOADSUB ALL FROM "FFT.HTS"
or LOADSUB Autocorrelate FROM "MATHLIB.HTS"
or LOADSUB FROM "MATHLIB.HTS"
 
Usage                INTEGER Logn
REAL A(*),C(*)
CALL Autocorrelate(Logn,A(*),C(*))
 
Description                
Autocorrelate calculates the autocorrelation of the sequence in the array A and returns the result in the array C. Logn is the base-2 logarithm of the number of points in the sequence to be correlated. The array A 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. The number of elements in A 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 for each value of Logn is twice the value given in the table above.
 
The autocorrelation is a measure of a function's similarity to itself as the abscissa is shifted. If a(x) is the function being tested and the interval of interest is x (0,T), and if a is zero outside this interval, then the autocorrelation, c(x), is defined by the relation
Note that, while a(x) is nonzero on the interval x (0,T), c(x) is nonzero on the interval x (-T,T).
 
If the function a is 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) is constant and equal to a([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,-(N-1),...,0,...,N-1}.
 
Autocorrelate returns the values of c([k+½]T/N) in the array C. The first N elements of C represent k = {0,1,...,N-1} and the last N elements in C represent
k = {-N,-(N-1),...,-1}.
 
Errors                
Autocorrelate 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 or C is smaller than the values described above.
 
See Also
Correlate, Convolve, Fft, Power_spectrum, Fft