Documentation

# peak2peak

Maximum-to-minimum difference

## Syntax

```Y = peak2peak(X) Y = peak2peak(X,DIM) ```

## Description

`Y = peak2peak(X)` returns the difference between the maximum and minimum values in `X`. By default, `peak2peak` operates along the first array dimension of `X` with size greater than 1. For example, if `X` is a row or column vector, `Y` is a real-valued scalar. If `X` is an N-by-M matrix with N > 1, `Y` is a 1-by-M row vector containing the maximum-to-minimum differences of the columns of `X`.

`Y = peak2peak(X,DIM)` computes the maximum-to-minimum differences of `X` along the dimension, `DIM`.

## Input Arguments

 `X` Real- or complex-valued input vector, matrix, or `gpuArray` object. By default, `peak2peak` acts along the first array dimension of `X` with size greater than 1. For complex-valued inputs, `peak2peak` identifies the maximum and minimum in absolute value. `peak2peak` subtracts the complex number with the minimum modulus from the complex number with the maximum modulus. See Run MATLAB Functions on a GPU (Parallel Computing Toolbox) and GPU Support by Release (Parallel Computing Toolbox) for details on `gpuArray` objects. `DIM` Dimension for maximum-to-minimum difference. The optional `DIM` input argument specifies the dimension along which to compute the maximum-to-minimum differences. Default: First array dimension with size greater than 1

## Output Arguments

 `Y` Maximum-to-minimum difference. For vectors, `Y` is a real-valued scalar. For matrices, `Y` contains the maximum-to-minimum differences computed along the specified dimension, `DIM`. By default, `DIM` is the first array dimension with size greater than 1.

## Examples

collapse all

Compute the maximum-to-minimum difference of a 100 Hz sinusoid sampled at 1 kHz.

```t = 0:0.001:1-0.001; x = cos(2*pi*100*t); y = peak2peak(x)```
```y = 2 ```

Compute the maximum-to-minimum difference of a complex exponential with a frequency of $\pi /4$ rad/sample.

Create a complex exponential with a frequency of $\pi /4$ rad/sample. Find the peak-to-peak difference.

```n = 0:99; x = exp(1j*pi/4*n); y = peak2peak(x)```
```y = 0.0000 + 1.4142i ```

Create a matrix where each column is a 100 Hz sinusoid sampled at 1 kHz with a different amplitude. The amplitude is equal to the column index.

Compute the maximum-to-minimum differences of the columns.

```t = 0:0.001:1-0.001; x = cos(2*pi*100*t)'*(1:4); y = peak2peak(x)```
```y = 1×4 2 4 6 8 ```

Create a matrix where each row is a 100 Hz sinusoid sampled at 1 kHz with a different amplitude. The amplitude is equal to the row index.

Compute the maximum-to-minimum differences of the rows specifying the dimension equal to 2 with the DIM argument.

```t = 0:0.001:1-0.001; x = (1:4)'*cos(2*pi*100*t); y = peak2peak(x,2)```
```y = 4×1 2 4 6 8 ```

## References

[1] IEEE® Standard on Transitions, Pulses, and Related Waveforms, IEEE Standard 181, 2003.