Implementation of a FIR filter on basic elements
In this example, we will analyze the structure of the FIR filter and analyze the behavior of the filter at different coefficients within it.
The basic filter consists of a delay line and coefficients by which the delayed signal is multiplied, after which the results are added together.
The figure below shows the FIR filter circuit containing 4 coefficients.
Next, we add an auxiliary function of the model and determine the coefficients for several filter runs.
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]:
In [ ]:
К_arr = [0.1 0.2 0.3 0.4; 0.16 0.38 0.38 0.16; 1 2 3 4]
Out[0]:
Let's run the model in a loop, and analyze the results by plotting graphs in the time and frequency domains.
In [ ]:
out_arr = zeros(1001,3)
K, K1, K2, K3, K4 = 0, 0, 0, 0, 0
for i in 1:3
K = К_arr[i,:]
K1, K2, K3, K4 = K[1], K[2], K[3], K[4]
run_model("Basic_FIR_filter") # Запуск модели.
out = collect(simout["Basic_FIR_filter/out"]);
out_arr[:,i] = out.value
end
plot(out_arr)
Out[0]:
In [ ]:
using FFTW
Comp_out = ComplexF64.(out_arr);
spec_out = fftshift(fft(Comp_out));
plot([10log10.(abs.((spec_out/3e6)))], label =["0.1 0.2 0.3 0.4" "0.16 0.38 0.38 0.16" "1 2 3 4"])
ylabel!("Мощность дБВт")
xlabel!("Частота МГц")
Out[0]:
Conclusion
As we can see from the resulting graphs, the filter coefficients affect changes in both signal power and frequency characteristics.