function dsn() -- "Display Signal to Noise" -- the name originates from Varian lingo -- requires the selection of a region of pure noise and an horizontal mark -- set the mark on the top the "Signal" local noise = copy() -- a sample of noise -- noise.x is the number of points into the region if noise == nil or noise.x < 2 then print "you must select a region of noise first!" return end local N = noise.x local signal = getmarks("h") if signal == nil then print "you must set an horizontal mark first!" return end local sum = 0 for i = 1,N do sum = sum + noise[i] end 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) ) --[[ print("ppm ="..ppm) print("mean ="..mean) print("sd ="..sd) print("N ="..N) print("signal ="..signal) --]] return (signal - mean) / sd end