
list tests
 test1
 test2
 test3
end

# test using even samples
macro test1
 $PASS = 1
 break -auto off

 local P PI
 $PI = 3.14159265359
 $P  = 15.0

 create t 0 100
 set f = sin(2*$PI*t/$P)
 periodogram t f 5 50 period power

 peak -q period power

 if (abs ($peakpos - $P) > 0.5)
   $PASS = 0
 end
end

# test using random samples
macro test2
 $PASS = 1
 break -auto off

 local P PI
 $PI = 3.14159265359
 $P  = 15.0

 create x 0 100
 set t = 100 * rnd(x) 
 set f = sin(2*$PI*t/$P)
 periodogram t f 5 50 period power

 # lim -n 0 t f; clear; box; plot -x 2 -pt 2 t f
 # lim -n 1 period power; clear; box; plot period power

 peak -q period power

 if (abs ($peakpos - $P) > 0.5)
   $PASS = 0
 end
end

# test using random samples, higher frequency
macro test3
 $PASS = 1
 break -auto off

 local P PI
 $PI = 3.14159265359
 $P  = 2.0

 create x 0 100
 set t = 100 * rnd(x) 
 set f = sin(2*$PI*t/$P)

 periodogram t f 1 10 period power

 # lim -n 0 t f; clear; box; plot -x 2 -pt 2 t f
 # lim -n 1 period power; clear; box; plot period power

 peak -q period power

 if (abs ($peakpos - $P) > 0.05)
   $PASS = 0
 end
end

# test using random samples, offset start
macro test4
 $PASS = 1
 break -auto off

 local P PI
 $PI = 3.14159265359
 $P  = 15.0

 create x 500 800
 set t = 300 * rnd(x) + 500
 set f = sin(2*$PI*t/$P)

 periodogram t f 2 30 period power

  lim -n 0 t f; clear; box; plot -x 2 -pt 2 t f
  lim -n 1 period power; clear; box; plot period power

 peak -q period power

 if (abs ($peakpos - $P) > 0.05)
   $PASS = 0
 end
end
