Engee documentation
Notebook

Averaging filter

A median filter is a type of digital filter widely used in digital signal and image processing to reduce noise. 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 defines the size of the filter window.

Next, let's define the function of model start and declare several variants of filter window size.

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];

Then 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 amplitude of the signal, this is due to the fact that the input is a sinusoid and on a larger averaging window we find the average between all possible values of the signal, including the maxima and minima of the function, the filter itself works correctly and fulfils its main function.

Blocks used in example