Berserk Docs
Scalar FunctionsSeries Functions

series_fir

Applies a Finite Impulse Response (FIR) filter to a series.

An absent element (null) makes the whole result null; fill gaps first with series_fill_forward, series_fill_const or series_fill_linear to choose how they count.

Syntax

series_fir(series, filter, normalize, center)

Parameters

Prop

Type

Returns: dynamic

Examples

Example 1 — Apply a 3-point moving average filter

print series_fir(dynamic([0, 0, 10, 50, 100, 50, 10, 0, 0]), dynamic([1, 1, 1]))
print_0 (dynamic)
[0.0,0.0,3.3333333333333335,20.0,53.333333333333336,66.66666666666667,53.333333333333336,20.0,3.3333333333333335]

Example 2 — Apply a normalized FIR filter

print series_fir(dynamic([0, 0, 10, 50, 100, 50, 10, 0, 0]), dynamic([1, 1, 1]), true)
print_0 (dynamic)
[0.0,0.0,3.3333333333333335,20.0,53.333333333333336,66.66666666666667,53.333333333333336,20.0,3.3333333333333335]

Example 3 — An absent element makes the result null - fill the gaps first to choose how they count.

print series_fir(dynamic([10, 10, null, 10]), dynamic([1, 1]))
print_0 (dynamic)
null

Example 4 — Carry the last known value across the gap, then filter - the usual choice for a metric that was simply not scraped.

print series_fir(series_fill_forward(dynamic([10, 10, null, 10])), dynamic([1, 1]))
print_0 (dynamic)
[5.0,10.0,10.0,10.0]

Example 5 — Treat a gap as a real zero, then filter - use when absent genuinely means none, and note it lowers every window containing the gap.

print series_fir(series_fill_const(dynamic([10, 10, null, 10]), 0.0), dynamic([1, 1]))
print_0 (dynamic)
[5.0,10.0,5.0,5.0]

Example 6 — Interpolate across the gap, then filter.

print series_fir(series_fill_linear(dynamic([10, 10, null, 10])), dynamic([1, 1]))
print_0 (dynamic)
[5.0,10.0,10.0,10.0]

On this page