to downsample :wave :factor

make "msg [downsampling factor must be an integer greater than 1]
;;catch "d.error [print "msg]

;; check that factor is a positive integer
test less? factor 1
if not less? 1 factor [ 
  print msg
  stop
]



make "owave (array (count wave)/factor 0)

make "i 0
make "j 0
repeat count wave [

  test equal? (modulo i factor) 0
  iftrue [
   setitem j owave (item i wave)
   make "j j+1
  ]
  make "i i+1
]

output owave

end

bury [downsample]
