-- s2n : calculates signal / noise in 2-D spectra
-- before calling this program the user must select a region of noise
-- and select a peak with two marks (a cross of marks)
-- the "signal" value is the height of the highest point within SEARCH ppm from the cross
SEARCH = SEARCH or 0.1
local noise = copy() -- a sample of noise
-- noise.x is the number of points into the region
if noise == nil or noise.x < 2 or noise.y < 2 then
print "you must select a region of noise first!"
return
end
local Yppm = getmarks("h")
if Yppm == nil then
print "you must set an horizontal mark first!"
return
end
local Xppm = getmarks()
if Xppm == nil then
print "you must set a vertical mark first!"
return
end
local N = noise.x * noise.y
local sum = 0
for i = 1,N do
sum = sum + noise[i]
end
local mean = sum / N
sum = 0
for i = 1,N do
local diff = noise[i] - mean
sum = sum + diff * diff
end
local sd = math.sqrt( sum / (N - 1) )
region( Xppm + SEARCH, Xppm - SEARCH, Yppm + SEARCH, Yppm - SEARCH )
local signal = copy()
N = signal.x * signal.y
local max = 0
for i = 1,N do
if signal[i] > max then max = signal[i] end
end
print("signal/noise = "..((max - mean) / sd) )