series_moving_var_fl()
Applies to: ✅ Azure Data Explorer ✅ Azure Monitor ✅ Microsoft Sentinel
Applies a moving variance filter on a series.
The function series_moving_var_fl()
is a user-defined function (UDF) that takes an expression containing a dynamic numerical array as input and applies on it a moving variance filter.
Syntax
series_moving_var_fl(
y_series,
n [,
center ])
Learn more about syntax conventions.
Parameters
Name | Type | Required | Description |
---|---|---|---|
y_series | dynamic |
✔️ | An array cell of numeric values. |
n | int |
✔️ | The width of the moving variance filter. |
center | bool |
Indicates whether the moving variance is either applied symmetrically on a window before and after the current point or applied on a window from the current point backwards. By default, center is false . |
Function definition
You can define the function by either embedding its code as a query-defined function, or creating it as a stored function in your database, as follows:
Define the function using the following let statement. No permissions are required.
Important
A let statement can't run on its own. It must be followed by a tabular expression statement. To run a working example of series_moving_var_fl()
, see Example.
let series_moving_var_fl = (y_series:dynamic, n:int, center:bool=false)
{
let ey = series_fir(y_series, repeat(1, n), true, center);
let e2y = series_multiply(ey, ey);
let y2 = series_multiply(y_series, y_series);
let ey2 = series_fir(y2, repeat(1, n), true, center);
let var_series = series_subtract(ey2, e2y);
var_series
};
// Write your query to use the function here.
Example
The following example uses the invoke operator to run the function.
To use a query-defined function, invoke it after the embedded function definition.
let series_moving_var_fl = (y_series:dynamic, n:int, center:bool=false)
{
let ey = series_fir(y_series, repeat(1, n), true, center);
let e2y = series_multiply(ey, ey);
let y2 = series_multiply(y_series, y_series);
let ey2 = series_fir(y2, repeat(1, n), true, center);
let var_series = series_subtract(ey2, e2y);
var_series
}
;
let sinewave=(x:double, period:double, gain:double=1.0, phase:double=0.0)
{
gain*sin(2*pi()/period*(x+phase))
}
;
let n=128;
let T=10;
let window=T*2;
union
(range x from 0 to n-1 step 1 | extend y=sinewave(x, T)),
(range x from n to 2*n-1 step 1 | extend y=0.0),
(range x from 2*n to 3*n-1 step 1 | extend y=sinewave(x, T)),
(range x from 3*n to 4*n-1 step 1 | extend y=(x-3.0*n)/128.0),
(range x from 4*n to 5*n-1 step 1 | extend y=sinewave(x, T))
| order by x asc
| summarize x=make_list(x), y=make_list(y)
| extend y_var=series_moving_var_fl(y, T, true)
| render linechart
Output