对序列应用有限脉冲响应 (FIR) 滤波器。Applies a Finite Impulse Response (FIR) filter on a series.

此函数接受一个包含动态数值数组的表达式作为输入,并应用一个有限脉冲响应滤波器。The function takes an expression containing a dynamic numerical array as input and applies a Finite Impulse Response filter. 通过指定 filter 系数,该函数可用于计算移动平均值、进行修匀处理和检测更改等。By specifying the filter coefficients, it can be used for calculating a moving average, smoothing, change-detection, and many more use cases. 该函数的输入列包含由滤波器系数组成的动态数组和静/动态数组,并且该函数会对此列应用滤波器。The function takes the column containing the dynamic array and a static dynamic array of the filter's coefficients as input, and applies the filter on the column. 它会输出新的动态数组列,其中包括滤波后的输出。It outputs a new dynamic array column, containing the filtered output.


series_fir(x, filter [, normalize [, center ]])series_fir(x, filter [, normalize [, center ]])


  • x:数值的动态数组单元。x : Dynamic array cell of numeric values. 通常是 make-seriesmake_list 运算符生成的输出。Typically the resulting output of make-series or make_list operators.
  • filter:一个常量表达式,其中包含滤波器的系数(存储为由数值组成的动态数组)。filter : A constant expression containing the coefficients of the filter (stored as a dynamic array of numeric values).
  • normalize:一个可选布尔值,指示是否应将滤波器归一化。normalize : Optional Boolean value indicating whether the filter should be normalized. 即,将其除以系数之和。That is, divided by the sum of the coefficients. 如果滤波器包含负值,则必须将 normalize 指定为 false,否则结果将是 nullIf filter contains negative values, then normalize must be specified as false, otherwise result will be null. 如果未指定,则假定 normalize 采用默认值,具体取决于 filter 中是否存在负值。If not specified, then a default value of normalize is assumed, depending on the presence of negative values in the filter . 如果 filter 包含至少一个负值,则假定 normalize 为 falseIf filter contains at least one negative value, then normalize is assumed to be false.
    归一化是确保系数之和为 1 的一种简便方法。Normalization is a convenient way to make sure that the sum of the coefficients is 1. 这样做以后,滤波器不会对序列进行放大或衰减。Then the filter doesn't amplify or attenuate the series. 例如,可以通过 filter =[1,1,1,1] 和 normalized =true 指定四箱的移动平均值,这比键入 [0.25,,0.25] 更加容易。For example, the moving average of four bins could be specified by filter =[1,1,1,1] and normalized =true, which is easier than typing [0.25,,0.25].
  • center:一个可选布尔值,指示是对某个时段(当前时间点之前和之后)对称地应用滤波器,还是对当前时间点之前的时段应用滤波器。center : An optional Boolean value that indicates whether the filter is applied symmetrically on a time window before and after the current point, or on a time window from the current point backwards. 默认情况下,center 为 false,这适合于流式传输数据的情况,在这种情况下,我们只能对当前的点和较旧的点应用滤波器。By default, center is false, which fits the scenario of streaming data, where we can only apply the filter on the current and older points. 但是,对于即席处理,可以将其设置为 true,使其与时序保持同步。However, for ad-hoc processing you can set it to true, keeping it synchronized with the time series. 请参阅以下示例。See examples below. 此参数用于控制滤波器的群延迟。This parameter controls the filter’s group delay.


  • 通过设置 filter =[1,1,1,1,1] 和 normalize=true(默认值)计算五个点的移动平均值。Calculate a moving average of five points by setting filter =[1,1,1,1,1] and normalize=true (default). 请注意 center=false(默认值)与 true 的效果:Note the effect of center=false (default) vs. true:
range t from bin(now(), 1h)-23h to bin(now(), 1h) step 1h
| summarize t=make_list(t)
| project id='TS', val=dynamic([0,0,0,0,0,0,0,0,0,10,20,40,100,40,20,10,0,0,0,0,0,0,0,0]), t
| extend 5h_MovingAvg=series_fir(val, dynamic([1,1,1,1,1])),
         5h_MovingAvg_centered=series_fir(val, dynamic([1,1,1,1,1]), true, true)
| render timechart

此查询将返回:This query returns:
5h_MovingAvg:5 点移动平均值滤波器。5h_MovingAvg : Five points moving average filter. 峰值经过了修匀处理,并且偏移了 (5-1)/2 = 2 小时。The spike is smoothed and its peak shifted by (5-1)/2 = 2h.
5h_MovingAvg_centered:相同,但通过设置 center=true,峰值会停留在其原始位置。5h_MovingAvg_centered : Same, but by setting center=true, the peak stays in its original location.

序列 fir

  • 若要计算某个点与其前面的点之间的差异,请设置 filter =[1,-1]。To calculate the difference between a point and its preceding one, set filter =[1,-1].
range t from bin(now(), 1h)-11h to bin(now(), 1h) step 1h
| summarize t=make_list(t)
| project id='TS',t,value=dynamic([0,0,0,0,2,2,2,2,3,3,3,3])
| extend diff=series_fir(value, dynamic([1,-1]), false, false)
| render timechart

序列 fir 2