View Raw SPL
/*****************************************************************************
*                                                                            *
*   MOVMIN.SPL  Copyright (C) 2022 DSP Development Corporation               *
*                               All Rights Reserved                          *
*                                                                            *
*   Author:      Randy Race                                                  *
*                                                                            *
*   Synopsis:    Calculates the centered moving minimum                      *
*                                                                            *
*   Revisions:    9 Nov 2022  RRR  Creation                                  *
*                                                                            *
*****************************************************************************/

#if @HELP_MOVMIN

    MOVMIN

    Purpose: Calculates the centered moving minimum of a series.

    Syntax:  MOVMIN(series, n, "nanflag", "edgeflag")

                  series - A series, the input.

                       n - An integer, the block size.

                "naflag" - Optional. A string, the NA handling method.

                            "includenan" : include NA values (default)

                               "omitnan" : ignore NA values

              "edgeflag" - Optional. A string, the edge processing flag.

                               "full" : process all segments (default)

                            "discard" : ignore partial segments 

                             "shrink" : shrink the segment size to actual
                                        number of samples at the edge
                                        segments  

    Returns: A series or table.

    Example:
             W1: {1, 2, 4, 7}
             W2: movmin(w1, 3)

             returns the series {1, 1, 2, 4}

    Example:
             W1: {1, 2, 4, 7}
             W3: movmin(w1, length(w1), "discard")

             W3[1] == min(w1) == 1

    Remarks:   
             See XMOVMIN to specify the interval N as a duration.

             See MOVAVG for details on NAFLAG and EDGEFLAG.

    See Also:
             Blockavg
             Max
             Movavg
             Movminimum
             Movminimum
             Xblockmax
             Xmovmin
#endif


/* centered moving minimum */
movmin(s, n, flag1 = "", flag2 = "", flag3 = "")
{
        local y;

        if (argc < 2) error(sprintf("%s - series and integer required", __FUNC__));

        y = movminimum(s, n, 1, "omitnan", "center", flag1, flag2, flag3);

        return(y);
}