-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpeaks.pro
69 lines (65 loc) · 1.51 KB
/
peaks.pro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
;+
; NAME:
; PEAKS
;
;
; PURPOSE:
; Find the peaks in a vector (spectrum) which lie
; NSIG above the standard deviation of all peaks in
; the spectrum
;
; CALLING SEQUENCE:
; result = peaks(y, nsig [,npk])
;
;
; INPUTS:
; Y - Vector (usually a spectrum) in which you want to
; locate peaks.
; NSIG - Number of sigma above the standard deviation of
; all peaks to search.
;
; OUTPUTS:
;
; RESULT - Vector holding the indecies of the peaks in Y
;
;
; OPTIONAL OUTPUTS:
;
; NPK - The number of peaks located
;
; NOTES:
;
; NSIG is NOT the number of sigma above the noise in the spectrum.
; It's instead a measure of the significance of a peak. First, all
; peaks are located. Then the standard deviation of the peaks is
; calculated using ROBUST_SIGMA (see Goddard routines online). Then
; peaks which are NSIG above the sigma of all peaks are selected.
;
; EXAMPLE:
;
; IDL> y = randomn(seed,2000)
; IDL> pk = peaks(y,2)
; IDL> plot,y
; IDL> oplot,pk,y[pk],ps=2
;
; MODIFICATION HISTORY:
;
;-
function peaks,y,nsig,dum,level=level,count=npk
on_error,2
d0 = y - shift(y,1)
d1 = y - shift(y,-1)
pk = where(d0 gt 0 and d1 gt 0,npk)
if keyword_set(level) then begin
bigind = where(y[pk] gt level, npk)
return,pk[bigind]
endif
if n_elements(nsig) gt 0 then begin
yp = y[pk]
mn = robust_mean(yp,4)
sig = robust_sigma(yp)
bigind = where(yp gt mn + nsig*sig, npk)
if npk gt 0 then big = pk[bigind] else big = -1
endif else big = pk
return,big
end