View Raw SPL
/*****************************************************************************
* *
* BLOCKRMS.SPL Copyright (C) 2023 DSP Development Corporation *
* All Rights Reserved *
* *
* Author: Randy Race *
* *
* Synopsis: Calculates the block moving RMS *
* *
* Revisions: 3 Aug 2023 RRR Creation *
* *
*****************************************************************************/
#if @HELP_BLOCKRMS
BLOCKRMS
Purpose: Computes a moving non-overlapping block RMS of a series.
Syntax: BLOCKRMS(s, n, rampflag)
s - A series, the input data.
n - An integer, the block size to compute the RMS.
rampflag - Optional. An integer, endpoint averaging flag.
0: down
1: up (default)
Returns: A series, the N point moving block RMS.
Example:
W1: 1..12
W2: blockrms(w1, 2)
W2 == {1.581, 3.536, 5.523, 7.517, 9.513, 11.511}
Example:
W3: 1..12
W4: blockrms(w1, 3)
W4 == {2.160, 5.066, 8.042, 11.030}
Remarks:
BLOCKRMS computes the N point non-overlapping moving block RMS
of a series.
If the block size is not an integral fraction of the series
length, the end points are not processed.
See XBLOCKRMS to compute the block size in terms of a duration.
See Also:
Decimate
Movrms
RMS
Xblockrms
#endif
/* block RMS */
ITERATE blockrms(s, n, rampflag = 1, flag1 = "", flag2 = "", flag3 = "")
{
local brms;
/* hurdles */
if (argc < 2)
{
error(sprintf("%s - series and block size required", __FUNC__));
}
if (n < 1) error(sprintf("%s - n must be > 0", __FUNC__));
if (isstring(rampflag))
{
flag2 = flag1;
flag1 = rampflag;
rampflag = 1;
}
/* moving RMS calculation */
brms = movavg(s, n, rampflag, n, n, "rms", flag1, flag2, flag3);
return(brms);
}