correlationTest.frink

View or download correlationTest.frink in plain text format


/** This file tests the routines in correlation.frink. */

use correlation.frink

/** Calculate the autocorrelation in a repeating list with sub-patterns.
    This should obtain an offset of 6 being the highest correlation. */

println[autocorrelation[[1,2,1,4,1,8,1,2,1,4,1,8,1,2,1,4,1,8]]]
println[]

// The previous list with a bit of noise.  Hopefully the period will still be 6
println[autocorrelation[[1,2,1,4,1,8,1,2,3,4,1,8,1,2,1,5,1,8]]]
println[]

// Find when the digits in a number repeat themselves.  The precision may have
// to be increased for larger denominators, as 1/n may repeat after as many as
// n-1 digits.
for b = 1 to 200
{
   setPrecision[b*2+10]
   r = autocorrelation[array[chars[toString[1./b]]]]
 //  println[r]
   println["1/$b appears to repeat most strongly after " + r@0@0 + " terms."]
}

println[]

// Calculate the autocorrelation of a sinewave.  The period should be close
// to the number divided by in the "step" below, although if the step is
// small, then the offsets near 1 will be the strongest (as the sine wave is
// shifted very slightly relative to itself.)
setPrecision[15]
c = new array
for i = 0 to 10 pi step (2 pi / 17.1)
   c.push[sin[i]]

println[autocorrelation[c]]


View or download correlationTest.frink in plain text format


This is a program written in the programming language Frink.
For more information, view the Frink Documentation or see More Sample Frink Programs.

Alan Eliasen was born 17649 days, 5 hours, 45 minutes ago.