! Test the basic functionality of the amfsync primitive.
!
! @author  Jason Broussard
! @version $Id: test_amfsync.mm,v 1.1 2011/12/06 19:52:00 jwb Exp $
! @since   
!
startmacro
  waveform nnx sf 128k white
  fcalc nnb nnx nnx abs /
  fcalc nnz nnx 4.0 /
  fcalc nww nnz nnb +
  headermod nww xd=1/3.125e6
!  upsample nww 8 nzz
  !much better results would be obtained using newrate or resample...
  thin nww nzz INC=-8
  firwind fw2,LOWPASS,HANNING,128,1e6 2e6 3.125e6
  fdfilt nzz fw2 amftest2

  amfsync amftest2 nout 3.125e6
  
  statistics amftest2 men1 sd1 el1 ,,mx1 mn1 
  statistics nout men2 sd2 el2 ,,mx2 mn2
  assert/text="Verifying number of output elements" el2 eq 131056 then
  calc ddd men1 men2 - abs
  !since the input data is based on whitenoise, this has to be a pretty
  !big margin of error...
  assert/text="Comparing MEAN of input and output file" ddd le 2e-3 then
  calc ddd sd1 sd2 - abs
  assert/text="Comparing SDEV of input and output file" ddd le 2e-1 then
  assert/text="Comparing MAX of input and output file" mx1 eq mx2 then
  assert/text="Comparing MIN of input and output file" mn1 eq mn2 then
   
  
  erase nnx nnb nnz nww fw2 nzz amftest2 nout


endmacro
