dsp.PeakFinder

(To be removed) Identify peak values in input signal

Description

The dsp.PeakFinder System object™ counts the number of peak values (maxima, minima, or both) in each column of the real-valued input signal. To qualify as a peak, a point has to be larger (or smaller) than both of its neighboring points. The end points are not considered as peak values. The object can also output the indices and values of the peaks, and a binary array that indicates whether a peak is a maxima or a minima.

To output the peak indices and peak values, set PeakIndicesOutputPort and PeakValuesOutputPort to true, respectively. In addition, you can determine which of the peak values is a maxima or a minima using the polarity matrix. The polarity matrix is a logical array in which a 1 indicates a maxima, and a 0 indicates a minima. To view the polarity matrix, set PeakType to 'Maxima and Minima' and access the fourth output.

Use the MaximumPeakCount property to specify how many peak values to look for in each input signal. The object stops searching the input signal once this maximum number of peak values has been found.

If you set IgnoreSmallPeaks to true, the object no longer detects low amplitude peaks and ignores noise within a threshold value that you define. In this mode, the current value is a maximum if (currentprevious) > threshold and (currentnext) > threshold. The current value is a minimum if (currentprevious) < –threshold and (currentnext) < –threshold.

Note

The dsp.PeakFinder System object will be removed in a future release. To determine the local maxima, use the findpeaks function. To determine the local minima, use the islocalmin function and find the signal values corresponding to the local minima indices that the function determines. For more details, see Compatibility Considerations.

To determine the peak values in an input signal:

  1. Create the dsp.PeakFinder object and set its properties.

  2. Call the object with arguments, as if it were a function.

To learn more about how System objects work, see What Are System Objects? (MATLAB).

Creation

Description

pkFind = dsp.PeakFinder creates a peak finder System object that identifies the peak values (maxima, minima, or both) in an input signal.

pkFind = dsp.PeakFinder(Name,Value) creates a peak finder System object with each specified property set to the specified value. Enclose each property name in single quotes.

Example: delay = dsp.PeakFinder('PeakType','Maxima');

Properties

expand all

Unless otherwise indicated, properties are nontunable, which means you cannot change their values after calling the object. Objects lock when you call them, and the release function unlocks them.

If a property is tunable, you can change its value at any time.

For more information on changing property values, see System Design in MATLAB Using System Objects (MATLAB).

Type of peaks to identify, specified as one of the following:

  • 'Maxima' –– If IgnoreSmallPeaks is set to true, the current value is identified as a maximum if (currentprevious) > threshold and (currentnext) > threshold. Specify threshold in PeakThreshold property. If IgnoreSmallPeaks is set to false, the current value must be larger than both its neighboring points.

  • 'Minima' –– If IgnoreSmallPeaks is set to true, the current value is identified as a minimum if (currentprevious) < –threshold and (currentnext) < –threshold. If IgnoreSmallPeaks is set to false, the current value must be smaller than both its neighboring points.

  • 'Maxima and Minima' –– The object identifies both the maxima and the minima points.

Enable output of the peak indices, specified as either:

  • true –– The object returns the indices of the input signal peak values.

  • false –– The object does not return the indices of the input signal peak values.

Enable output of the peak values, specified as either:

  • true –– The object returns the peak values of the input signal.

  • false –– The object does not return the peak values of the input signal.

Maximum number of peak values to identify in each input signal, specified as an integer greater than or equal to 1. The object stops searching the input signal for peaks once it identifies the maximum number.

Example: 5

Example: 50

Ignore peaks below a threshold, specified as either:

  • false –– The object identifies the current value as a peak, if the current value is larger (or smaller) than both of its neighboring points.

  • true –– The object identifies the current value as a maximum if (currentprevious) > threshold and (currentnext) > threshold. The object identifies the current value as a minimum if (currentprevious) < –threshold and (currentnext) < –threshold.

Threshold below which peaks are ignored, specified as a real scalar greater than or equal to 0 or a vector with all elements greater than or equal to 0. The length of the vector must be equal to the number of channels.

This property identifies the current input value to be a maximum if (current input value – previous input value) > threshold and (current input value – next input value) > threshold. The current value is a minimum if (current input value – previous input value) < –threshold and (current input value – next input value) < –threshold.

Example: 0.2

Example: [0.3 2.4]

Example: [3; 0.4]

Dependencies

This property applies only when you set IgnoreSmallPeaks to true.

Fixed-Point Properties

Rounding method, specified as 'Floor', which is equivalent to truncation. The setting rounds the result of a calculation to the closest representable number in the direction of negative infinity.

The overflow action for fixed-point operations, specified as one of the following:

  • 'Wrap' –– The object wraps the result of its fixed-point operations.

  • 'Saturate' –– The object saturates the result of its fixed-point operations.

For more details on overflow actions, see overflow mode for fixed-point operations.

Usage

Description

cnt = pkFind(input) returns the number of peak values (minima, maxima, or both) in the input signal. Each column of the input is treated as a separate channel.

[cnt,idx] = pkFind(input) returns the number of peak values, cnt, and peak indices, idx, in the input signal.

To access the peak indices output, set the PeakIndicesOutputPort property to true.

pkFind = dsp.PeakFinder('PeakType','Maxima', ...
'PeakIndicesOutputPort',true);
...
[cnt,idx] = pkFind(input);

[___,val] = pkFind(input) returns the peak values val in the input signal.

To access the peak values output, set the PeakValuesOutputPort property to true.

pkFind = dsp.PeakFinder('PeakType','Maxima', ...
'PeakValuesOutputPort',true);
...
[cnt,idx,val] = pkFind(input);

[___,pol] = pkFind(input) returns the peak value polarity pol in input signal. The polarity is 1 for maxima and 0 for minima.

To access the polarity output, set the PeakType property to 'Maxima and Minima', and the PeakIndicesOutputPort property to true.

pkFind = dsp.PeakFinder('PeakType','Maxima and Minima', ...
'PeakIndicesOutputPort',true);
...
[cnt,idx,val,pol] = pkFind(input);

Input Arguments

expand all

Data input whose peak values are detected by the object, specified as a vector or matrix containing at least three rows.

Example: [9 6 10 3 5 5 0 12; 9 6 1 13 4 1 0 12]'

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fi

Output Arguments

expand all

Number of peak values, returned as a scalar or a row vector of length equal to the number of channels in the data input.

Example: [4 3]

Data Types: uint32

Indices of the peak values in the input signal, returned as a column vector or matrix. The size of the peak indices output is the same as that of the input. All nonzero elements represent peak indices.

Example: [1 2 3 6 0 0 0 0 0 0; 2 3 6 0 0 0 0 0 0 0]'

Dependencies

To enable this output, set the PeakIndicesOutputPort property to true.

Data Types: uint32

Peak values in the input signal, returned as a column vector or matrix.

Example: [6 10 3 0 0 0 0 0 0 0; 1 13 0 0 0 0 0 0 0 0]'

Dependencies

To access the peak values output, set the PeakValuesOutputPort property to true.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fi

Peak value polarity in input signal, returned as a column vector or matrix of logical 1s and 0s. The polarity is 1 for maxima and 0 for minima.

Example: [0 1 0 0 0 0 0 0 0 0; 0 1 0 0 0 0 0 0 0 0]'

Data Types: logical

Object Functions

To use an object function, specify the System object as the first input argument. For example, to release system resources of a System object named obj, use this syntax:

release(obj)

expand all

stepRun System object algorithm
releaseRelease resources and allow changes to System object property values and input characteristics
resetReset internal states of System object

Examples

Determine Local Maxima and Minima

Note: If you are using R2016a or an earlier release, replace each call to the object with the equivalent step syntax. For example, obj(x) becomes step(obj,x).

Determine whether each value of an input signal is a local maximum or minimum.

pkFind = dsp.PeakFinder;
pkFind.PeakIndicesOutputPort = true;
pkFind.PeakValuesOutputPort = true;

x1 = [9 6 10 3 4 5 0 12]';

Find the peaks of each input [prev;cur;next]: {[9;6;10],[6;10;3],...}

[cnt1, idx1, val1, pol1] = pkFind(x1)
cnt1 = uint32
    5
idx1 = 10x1 uint32 column vector

   1
   2
   3
   5
   6
   0
   0
   0
   0
   0

val1 = 10×1

     6
    10
     3
     5
     0
     0
     0
     0
     0
     0

pol1 = 10x1 logical array

   0
   1
   0
   1
   0
   0
   0
   0
   0
   0

Compatibility Considerations

expand all

Warns starting in R2019b

Extended Capabilities

See Also

Functions

Blocks

Introduced in R2012a