# peak2peak

Maximum-to-minimum difference

## Description

example

y = peak2peak(x) returns the difference between the maximum and minimum values in x.

example

y = peak2peak(x,dim) computes the maximum-to-minimum differences of x along dimension dim.

## 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

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 in which 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

## Input Arguments

collapse all

Input signal, specified as a vector, matrix, N-D array, or gpuArray object. For complex-valued inputs, peak2peak identifies the maximum and minimum in complex magnitude. peak2peak then 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 (Parallel Computing Toolbox) objects.

Example: sin(2*pi*(0:255)/4) specifies a sinusoid as a row vector.

Example: sin(2*pi*[0.1;0.3]*(0:39))' specifies a two-channel sinusoid.

Data Types: double | single
Complex Number Support: Yes

Dimension to operate along, specified as a positive integer scalar. 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.

Data Types: double | single

## Output Arguments

collapse all

Maximum-to-minimum difference, returned as a real-valued scalar, vector, matrix, N-D array, or gpuArray object.

## References

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