!
! MS = sigma*sqrt(pi/2)*(1+(S/sigma/2)^2)   ! Measured Amplitude
!
! S = sigma*SN                              ! True value
! MS/S = 1/SN*sqrt(pi/2)*(1+(SN/2)^2)       ! Ratio of Measured / True
! MS = S*sqrt(pi/2)*(1+(SN/2)^2)            ! SN is the Signal to Noise
! S = MS/sqrt(pi/2)/(1+(SN/2)^2)
!
define integer nsize moise
let nsize 32000
let moise 1280
define real ap[nsize] sn[moise]
define real re im /like ap
define real amp sigamp /like sn
!
let sn[i] 100*i/moise
for i 1 to moise
  im[j] = noise(j/sn[i]/j)
  re[j] = 1+noise(j/sn[i]/j)
  ap = sqrt(re^2+im^2)
  compute amp[i] mean ap
  compute sigamp[i] rms ap
next
!
clear
!
set box 4 16 3 20
lim * * 0.998 1.012 /var sn amp
set expand 1.25
box
define real sc
for k 1 2  
  pen 0 /weigh 2
  connect sn amp
  draw text -1 -1 "Uncorrected" 1 /char 9
  !
  ! We find this close to Zero
  !! let  sigamp (amp-1.D0)*sn
  !! compute sc median sigamp
  !! exa sc
  !! PAUSE
  let sc 0
  let sigamp amp-sc/sn !! amp-1.0/(2*sn)
!  pen 1 /weight 2
!  connect sn sigamp  
!  draw text -1 -2 "Linear corr." 1 /char 9
  pen 3 /weight 2
  !
  ! And this close to 0.5 
  !! let  sigamp (amp-1.D0)*sn**2
  !! compute sc median sigamp
  !! exa sc
  let sigamp sigamp-0.5/sn**2
  connect sn sigamp
  draw text -1 -3 "2\\und\\d order corr." 1 /char 9
  pen 0
  !
  lim * 10 = = /var sn amp
  set box 16 28 3 20
  box p n
next 
set box 4 28 3 20 
Label "Signal to Noise ratio" /X
label "Measured / True amplitude " /Y
