Engee documentation
Notebook

Implementation of low- and high-pass filters

This demonstration shows the implementations of two filters defined by the following difference equations:

  1. Low-pass filter: y(n) = 0.5x(n) + 0.5x(n-1) (averaging)
  2. High-pass filter: y(n) = 0.5x(n) - 0.5x(n-1) (finite difference)

The figure below shows a model from which we can see that common coefficients are given for filters and their main differences are contained in the last adder.

image.png

Next, we'll use an auxiliary function to run the model.

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

run_model("hipass_lopass") # Запуск модели.
Building...
Progress 25%
Progress 100%
Progress 100%
Progress 100%
Out[0]:
Dict{String, DataFrames.DataFrame} with 2 entries:
  "hipass" => 20001×2 DataFrame…
  "lopass" => 20001×2 DataFrame

Let's analyze the recorded results by plotting the signals in the time and frequency domains.

In [ ]:
hipass = collect(simout["hipass_lopass/hipass"]);
lopass = collect(simout["hipass_lopass/lopass"]);

plot(hipass.time[1:500], [hipass.value[1:500], lopass.value[1:500]],label=["Фильтр нижних частот" "Фильтр верхних частот"])
Out[0]:

As we can see based on the data presented in the time domain, the main differences between the data at the output of the high- and low-pass filters are differences in the amplitude of the signals and the unevenness of the oscillatory pulses, which we observe when using high-pass filters.

In [ ]:
using FFTW

Comp_hipass = ComplexF64.(hipass.value);
Comp_lopass = ComplexF64.(lopass.value);

spec_hipass = fftshift(fft(Comp_hipass));
spec_lopass = fftshift(fft(Comp_lopass));

x = [10log10.(abs.((spec_hipass/3e6))),10log10.(abs.((spec_lopass/3e6)))];
plot(x, label =["Фильтр нижних частот" "Фильтр верхних частот"])
ylabel!("Мощность дБВт")
xlabel!("Частота МГц")
Out[0]:

Based on the signal spectra, we can see that the filters are working correctly.

Conclusion

In this example, we have analyzed the differences between high-pass filters and low-pass filters using the same coefficients in both cases, thereby showing that there are quite few differences between these filters in terms of implementation.

Blocks used in example