Determine whether each value of input signal is local minimum or maximum
The Peak Finder block counts the number of local extrema in each column of the real-valued input signal. The block outputs the number of local extrema at the Cnt port. You can also configure the block to output the extrema indices, the extrema values, and a binary indicator of whether or not the extrema are maxima or minima.
To qualify as an extrema, a point has to be larger (or smaller) than both of its neighboring points. Thus, end points are never considered extrema.
If you select the Output peak indices check box, the Idx port
appears on the block. The block outputs the extrema indices at the Idx port. If
Index base is set to
Zero, the block
outputs zero-based extrema indices. If Index base is set to
One, the block outputs one-based extrema indices.
If you select the Output peak values check box, the Val port
appears on the block. The block outputs the extrema values at the Val port. If you
select either of these check boxes and set the Peak type(s) to
Maxima and Minima, the Pol port also appears on the
block. If the signal value is a maximum, the block outputs a 1 at the Pol ("Polarity")
port. If the signal value is a minimum, the block outputs a 0 at the Pol port.
Use the Maximum number of peaks to find parameter to specify how many extrema to look for in each input signal. The block stops searching the input signal once this maximum number of extrema has been found.
If you select the Ignore peaks within threshold of neighboring values check box, the block no longer detects low-amplitude peaks. This feature allows the block to ignore noise within a threshold value that you define. Enter a threshold value for the Threshold parameter. Now, the current value is a maximum if (current – previous) > threshold and (current – next) > threshold. The current value is a minimum if (current – previous) < –threshold and (current – next) < –threshold.
Consider the input vector
[9 6 10 3 4 5 0 12]
The table below shows the analysis made by the Peak Finder block. Note that the first and last input signal values are not considered:
|Previous, current, and next values|
9 6 10
6 10 3
10 3 4
3 4 5
4 5 0
5 0 12
|Current value if it is an extremum|
|Index of current value if it is an extremum|
|Polarity of current value if it is an extremum|
For this example, the outputs at the block ports are:
[1 2 3 5 6]
[6 10 3 5 0]
[0 1 0 1 0]
The Overflow mode parameter can affect the output of the block when the input is fixed point. Consider the following model:
In this model, the settings in the Constant block are:
Constant value —
Interpret vector parameters as 1–D — not selected
Sampling mode —
Sample time —
Output data type —
Word length —
Fraction length —
The settings in the Peak Finder blocks are:
Peak type(s) —
Output peak indices — not selected
Output peak values — selected
Maximum number of peaks to find —
Ignore peaks within threshold of neighboring values — selected
Overflow mode —
Wrap for Peak Finder Wrap,
Saturate for Peak Finder Saturate
Setting the Overflow mode parameter of the Peak Finder Wrap
Wrap causes the calculations (current – previous) > threshold and (current – next) > threshold to wrap on overflow, thereby causing the maximum to be
Specify whether you are looking for maxima, minima, or both.
Specify the base of the extrema indices as either:
Zero (default) –– The first
index starts with 0. For example, consider an input vector
[-1.5, 0.5, 0]. The peak value of this vector is 0.5 and the
index of this peak value is 1.
One –– In this setting, the
first index starts with 1. The index of the peak value in
[-1.5, 0.5, 0] is 2.
Select this check box if you want the block to output the extrema indices at the Idx port.
Select this check box if you want the block to output the extrema values at the Val port.
Enter the number of extrema to look for in each input signal. The block stops searching the input signal for extrema once the maximum number of extrema has been found. The value of this parameter must be an integer greater than or equal to one.
Select this check box if you want to eliminate the detection of peaks whose amplitudes are within a specified threshold of neighboring values.
Enter your threshold value. This parameter appears if you select the Ignore peaks within threshold of neighboring values check box.
When you select the Ignore peaks within threshold of neighboring values check box, the Fixed-point operational parameters section appears.
When you select this parameter, the block saturates the result of its
fixed-point operation. When you clear this parameter, the block wraps
the result of its fixed-point operation. For details on
wrap, see overflow
mode for fixed-point operations.
Supported Data Types
Generated code relies on
memset functions (
string.h) under certain