Engee documentation
Notebook

Realisation of low-pass and high-pass filters

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

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

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

image.png

Next, to run the model we apply the auxiliary function.

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 analyse the recorded results by plotting the signals in 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 see from the data presented in the time domain, the main differences between the data at the output of the upper and lower frequency filters are differences in the amplitude of signals and non-uniformity of oscillatory impulses, this trend we observe when using the upper frequency 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 spectra of signals we see that the filters work correctly.

Conclusion

In this example we have analysed the differences between high pass filters and low pass filters using the same coefficients in both cases, thus showing that the differences between these filters in terms of implementation are quite small.

Blocks used in example