Engee documentation
Notebook

The averaging filter

An averaging filter is a type of digital filter widely used in digital signal and image processing to reduce noise levels. The median filter is a nonlinear FIR filter.

In this example, we will look at its simplified implementation and see how well it works. The figure below shows the model of the implemented filter.

image.png

In this model, the window parameter determines the size of the filtering window.

Next, we will define the function of launching the model and declare several options for the dimension of the filtering window.

In [ ]:
# Подключение вспомогательной функции запуска модели.
function run_model( name_model)
    
    Path = (@__DIR__) * "/" * name_model * ".engee"
    
    if name_model in [m.name for m in engee.get_all_models()] # Проверка условия загрузки модели в ядро
        model = engee.open( name_model ) # Открыть модель
        model_output = engee.run( model, verbose=true ); # Запустить модель
    else
        model = engee.load( Path, force=true ) # Загрузить модель
        model_output = engee.run( model, verbose=true ); # Запустить модель
        engee.close( name_model, force=true ); # Закрыть модель
    end
    sleep(5)
    return model_output
end
Out[0]:
run_model (generic function with 1 method)
In [ ]:
window_arr = Int64[10,20,100,1e3];

Next, let's run this model in a loop with different parameters of the averaging window and compare the results.

In [ ]:
out_arr = zeros(1001,4)
window = 0;
for i in 1:4  
    window = window_arr[i]
    run_model("Averaging_filter") # Запуск модели.
    out = collect(simout["Averaging_filter/out"]);
    out_arr[:,i] = out.value
end 

plot(out_arr, label=["окно = 10" "окно = 20" "окно = 100" "окно = 1000"])
Building...
Progress 100%
Building...
Progress 100%
Building...
Progress 100%
Building...
Progress 100%
Out[0]:

Conclusion

As we can see from the resulting graph, the larger the thinning window, the lower the signal amplitude, this is due to the fact that a sine wave is applied to the input and with a larger averaging window we find averages between all possible signal values, including the maxima and minima of the function, the filter itself works correctly and performs its main function.

Blocks used in example