Skip to content

Commit 15ecfc5

Browse files
committed
cleaned up ACG python code
1 parent 4388e15 commit 15ecfc5

File tree

1 file changed

+27
-26
lines changed

1 file changed

+27
-26
lines changed
Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,46 @@
11
#!/usr/bin/env python
22

33
"""
4-
Pure python (and not bery numpy smart) version of the Automatic Gain Control function
4+
Pure python (and not very numpy smart) version of the
5+
Automatic Gain Control function
56
"""
67

78
import numpy as np
89

10+
911
def agc(nAGC, amp):
10-
"""
11-
run an automatic gain control filter onver the input array
12+
"""
13+
run an automatic gain control filter onver the input array
14+
15+
:param nAGC: width of window, number of elements.
16+
:type nAGC: integer
17+
18+
:param amp: input amplitude data
19+
:type amp: 1-d numpy array of float32
1220
13-
:param nAGC: width of window, number of elements.
14-
:type nAGC: integer
21+
:returns ampAGC: a numpy array of the filtered data.
1522
16-
:param amp: input amplitude data
17-
:type amp: 1-d numpy array of float32
18-
19-
:returns ampAGC: a numpy array of the filtered data.
23+
"""
2024

21-
"""
25+
# make sure input array is as expected:
26+
amp = np.asarray(amp, dtype=np.float32)
2227

23-
#make sure input array is as expected:
24-
amp = np.asarray(amp, dtype=np.float32)
25-
if len(amp.shape) != 1:
26-
raise ValueError("amp must be a rank-1 array")
27-
28-
npts = amp.shape[0]
28+
if len(amp.shape) != 1:
29+
raise ValueError("amp must be a rank-1 array")
2930

30-
nAGC2=nAGC/2
31-
ampAGC = np.zeros_like(amp)
32-
absamp = np.zeros_like(amp)
31+
npts = amp.shape[0]
3332

34-
absamp = np.abs(amp)
33+
nAGC2 = nAGC / 2
34+
ampAGC = np.zeros_like(amp)
35+
absamp = np.zeros_like(amp)
3536

37+
absamp = np.abs(amp)
3638

37-
for i in xrange(nAGC2, npts - nAGC2):
38-
fmax=0.0
39-
for j in range(i-nAGC2,i+nAGC2+1):
39+
for i in xrange(nAGC2, npts - nAGC2):
40+
fmax = 0.0
41+
for j in range(i - nAGC2, i + nAGC2 + 1):
4042
if absamp[j] > fmax:
4143
fmax = absamp[j]
42-
ampAGC[i] = amp[i]/fmax
43-
44-
return ampAGC
44+
ampAGC[i] = amp[i] / fmax
4545

46+
return ampAGC

0 commit comments

Comments
 (0)