Main Content

localmax

Identify and chain local maxima

    Description

    [lmaxima,indices] = localmax(x) identifies and chains the local maxima in the rows of the matrix x.

    [lmaxima,indices] = localmax(x,initrow) initializes the chaining of local maxima beginning with row initrow.

    [lmaxima,indices] = localmax(x,initrow,regflag) replaces initrow of x with the level-5 approximation (scaling) coefficients obtained with the sym4 wavelet.

    example

    Examples

    collapse all

    Construct a 4-by-4 matrix with local maxima at the following row-column indices: (4,2), (3,3), (2,2), and (1,3). Set initrow to 4 and regflag to false.

    x = ...
        [3 2 5 3
        4 6 3 2
        4 4 7 4
        4 6 2 2];
    [lmaxima,indices] = localmax(x,4,false);
    lmaxima
    lmaxima = 4×4
    
         0     0     2     0
         0     3     0     0
         0     0     2     0
         0     2     0     0
    
    

    Because localmax operates on the absolute values of x, setting x(4,2) = -x(4,2) produces an identical lmaxima.

    x(4,2) = -x(4,2);
    [lmaxima1,indices1] = localmax(x,4,false);
    isequal(lmaxima,lmaxima1)
    ans = logical
       1
    
    

    Determine the local maxima from the CWT of the cuspamax signal using the default Morse wavelet. Plot the CWT coefficient moduli and maxima lines.

    load cuspamax

    Plot the cuspamax signal and notice the shape of the signal near samples 300 and 700. The signal shows a cusp near sample 700.

    plot(cuspamax)
    xlabel("Sample")
    axis tight

    Figure contains an axes object. The axes object with xlabel Sample contains an object of type line.

    Plot the wavelet transform modulus maxima and note the local Holder exponent values at samples 308 and 717.

    Hölder exponent values indicate the strength of the singularities in a signal. Signal locations where the local Hölder exponent is 0 are discontinuous at that location. Locations with Hölder exponents greater than or equal to 1 are differentiable. Hölder exponent values less than but close to 1 indicate that the signal at the location is almost differentiable. The closer the Hölder exponent value is to 0, the stronger the singularity.

    The Hölder exponent at sample 308 is 1.9 and at sample 717 is 0.39. The low Hölder value at sample 717 confirms that the signal is not differentiable and has a fairly strong singularity at that point.

    wtmm(cuspamax,ScalingExponent="local")

    Figure contains an axes object and an object of type uitable. The axes object with title Wavelet Transform Maxima Lines, xlabel Sample, ylabel log2(scale) contains 7 objects of type image, line.

    Input Arguments

    collapse all

    Input data, specified as a matrix. localmax operates on the absolute values of x. Most often, x is a matrix of continuous wavelet transform (CWT) coefficients, and you can use localmax to identify maxima lines.

    Data Types: double
    Complex Number Support: Yes

    Initialization row, specified as an integer. If there are no local maxima in initrow, all rows in lmaxima with indices less than initrow consist of only zeros.

    Regularization flag, specified as a numeric or logical 1 (true) or 0 (false). If regflag to true, the row of x corresponding to initrow is replaced by the level-5 approximation (scaling) coefficients obtained with the sym4 wavelet.

    Output Arguments

    collapse all

    Local maxima chains, returned as a matrix. lmaxima only has nonzero entries at the locations of local maxima in the absolute values of x.

    Linear indices of the nonzero values of lmaxima, returned as a vector. Use ind2sub to convert the linear indices to a matrix row and column indices.

    Algorithms

    localmax determines the value of lmaxima at a local maximum in row R as follows.

    • If R>initRow, the value of lmaxima at a local maximum is 1.

    • If R=initRow, the value of lmaxima at a local maximum is the column index in row R.

    • If R<initRow, the value of lmaxima at a local maximum in row R is the column index of the nearest local maximum in row R+1.

      To illustrate this, if x is:

       3     2     5     3
       4     6     3     2
       4     4     7     4
       4     6     2     2

      lmaxima with initRow = 4 and regflag = false is:

           0     0     2     0
           0     3     0     0
           0     0     2     0
           0     2     0     0

      lmaxima with initRow = 3 and regflag = false is:

           0     0     2     0
           0     3     0     0
           0     0     3     0
           0     1     0     0
    • If the local maximum in row R lies between two local maxima in row R+1, the value of the local maximum in row R is the higher column index in row R+1.

      To illustrate this, if x is:

           0     0     1     0     0     0
           0     1     0     1     0     0

      lmaxima with initRow = 2 and regflag = false is:

           0     0     4     0     0     0
           0     2     0     4     0     0

      lmaxima with initRow = 1 and regflag = false is:

           0     0     3     0     0     0
           0     1     0     1     0     0

    Version History

    Introduced in R2008a

    See Also

    | | | | | | (Signal Processing Toolbox) | (Signal Processing Toolbox) |

    Topics