View Raw SPL
/*****************************************************************************
*                                                                            *
*   BLOCKMAX.SPL Copyright (C) 2014 DSP Development Corporation              *
*                               All Rights Reserved                          *
*                                                                            *
*   Author:      Randy Race                                                  *
*                                                                            *
*   Synopsis:    non-overlapping block maximum                               *
*                                                                            *
*   Revisions:   13 May 2014  RRR  Creation                                  *
*                                                                            *
*****************************************************************************/


#if @HELP_BLOCKMAX

    BLOCKMAX

    Purpose: Computes a moving non-overlapping block maximum of a series.

    Syntax:  BLOCKMAX(s, n)

               s - A series, the input data.

               n - An integer, the block size to find the maximum.

    Returns: A series, the N point moving block maximum.

    Example:
             W1: 1..12
             W2: blockmax(w1, 2)

             W2 == {2, 4, 6, 8, 10, 12}

    Example:
             W3: 1..12
             W4: blockmax(w1, 3)

             W4 == {3, 6, 9, 12}

    Remarks:
             BLOCKMAX computes the N point non-overlapping block maximum of
             a series. 

             If the block size is not an integral fraction of the
             series length, the end points are not processed.

             See XBLOCKMAX to specify the block size in terms of a duration.

    See Also:
             Blockavg
             Blockmin
             Decimate
             Movmax
             Xblockmax
#endif


/* N point moving block maximum */
blockmax(s, n, flag1 = "", flag2 = "", flag3 = "")
{
        local y;

        if (argc < 2)
        {
                error(sprintf("%s - input series and integer blocksize required", __FUNC));
        }

        /* decimate the N point moving maximum starting at the Nth sample */
        y = movmaximum(s, n, n, n, flag1, flag2, flag3);

        return(y);
}