1 //-----------------------------------------------------------------------------
2 // Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // See LICENSE.txt for the text of the license.
15 //-----------------------------------------------------------------------------
17 // track min and max peak values (envelope follower)
19 // NB: the min value (resp. max value) is updated only when the next high peak
20 // (resp. low peak) is reached/detected, since you can't know it isn't a
21 // local minima (resp. maxima) until then.
22 // This also means the peaks are detected with an unpredictable delay.
23 // This algorithm therefore can't be used directly for realtime peak detections,
24 // but it can be used as a simple envelope follower.
26 module min_max_tracker(
29 input [7:0] threshold
,
34 reg [7:0] min_val
= 255;
35 reg [7:0] max_val
= 0;
36 reg [7:0] cur_min_val
= 255;
37 reg [7:0] cur_max_val
= 0;
45 if (cur_max_val
>= ({1'b0, adc_d
} + threshold
))
47 else if (adc_d
>= ({1'b0, cur_min_val
} + threshold
))
49 if (cur_max_val
<= adc_d
)
51 else if (adc_d
<= cur_min_val
)
56 if (cur_max_val
<= adc_d
)
58 else if (({1'b0, adc_d
} + threshold
) <= cur_max_val
) begin
61 max_val
<= cur_max_val
;
66 if (adc_d
<= cur_min_val
)
68 else if (adc_d
>= ({1'b0, cur_min_val
} + threshold
)) begin
71 min_val
<= cur_min_val
;