|
1 | 1 | #!/usr/bin/env python |
2 | 2 |
|
3 | 3 | """ |
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 |
5 | 6 | """ |
6 | 7 |
|
7 | 8 | import numpy as np |
8 | 9 |
|
| 10 | + |
9 | 11 | 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 |
12 | 20 |
|
13 | | - :param nAGC: width of window, number of elements. |
14 | | - :type nAGC: integer |
| 21 | + :returns ampAGC: a numpy array of the filtered data. |
15 | 22 |
|
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 | + """ |
20 | 24 |
|
21 | | - """ |
| 25 | + # make sure input array is as expected: |
| 26 | + amp = np.asarray(amp, dtype=np.float32) |
22 | 27 |
|
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") |
29 | 30 |
|
30 | | - nAGC2=nAGC/2 |
31 | | - ampAGC = np.zeros_like(amp) |
32 | | - absamp = np.zeros_like(amp) |
| 31 | + npts = amp.shape[0] |
33 | 32 |
|
34 | | - absamp = np.abs(amp) |
| 33 | + nAGC2 = nAGC / 2 |
| 34 | + ampAGC = np.zeros_like(amp) |
| 35 | + absamp = np.zeros_like(amp) |
35 | 36 |
|
| 37 | + absamp = np.abs(amp) |
36 | 38 |
|
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): |
40 | 42 | if absamp[j] > fmax: |
41 | 43 | fmax = absamp[j] |
42 | | - ampAGC[i] = amp[i]/fmax |
43 | | - |
44 | | - return ampAGC |
| 44 | + ampAGC[i] = amp[i] / fmax |
45 | 45 |
|
| 46 | + return ampAGC |
0 commit comments