After initializing, the peak valley processing algorithm alternates searching for peaks and valleys based on the user-defined hysteresis. There are three states of the algorithm - initialize, peak search and valley search.
- Initialize: The algorithm tracks the minimum and maximum input values until the difference between them exceeds the hysteresis level. If the minimum value precedes the maximum value, the minimum is the first stored valley and the algorithm switches to Peak search. If the maximum value precedes minimum value, the maximum is the first stored peak and the algorithm switches to Valley search.
- Peak search: The algorithm tracks the maximum value as a candidate peak and minimum value as a candidate valley. When the difference between the candidate values exceeds the hysteresis level, the candidate peak value is stored. The algorithm switches to Valley search.
- Valley search: The algorithm tracks the minimum value as a candidate valley and maximum value as a candidate peak. When the difference between the candidate values exceeds the hysteresis level, the candidate valley value is stored. The algorithm switches to Peak search.