Engee documentation
Notebook

BER calculation for 8-PSK

The Error Rate Calculation block calculates the bit error rate (BER). Using this block, we can get the BER data for the communication system and analyse the efficiency of our system. In this example, we will look at a simple 8-PSK receiver and transmitter model. It is shown in the figure below.

image_2.png

Next, let's define 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(0.5)
    return model_output
end
Out[0]:
run_model (generic function with 1 method)

Next, we initialise the signal-to-noise ratios for our model and declare the bit error variable.

In [ ]:
EbNoArr = collect(-9:3:9);
Eb_No = 0;
ber = zeros(length(EbNoArr));
BER = 0;

Now let's run the model at different values of signal-to-noise ratio.

In [ ]:
for i in 1:length(EbNoArr)
    Eb_No = EbNoArr[i]
    run_model("8-PSK") # Запуск модели.
    BER = collect(BER)
    ber[i]=BER.value[end][1]
    println("BER: $(ber[i])")
end
Building...
Progress 0%
Progress 21%
Progress 100%
BER: 0.4042624042624043
Building...
Progress 0%
Progress 53%
Progress 100%
BER: 0.351981351981352
Building...
Progress 0%
Progress 43%
Progress 100%
BER: 0.3016983016983017
Building...
Progress 0%
Progress 40%
Progress 100%
BER: 0.20646020646020646
Building...
Progress 0%
Progress 38%
Progress 100%
BER: 0.10556110556110557
Building...
Progress 0%
Progress 34%
Progress 100%
Progress 100%
BER: 0.042624042624042624
Building...
Progress 0%
Progress 20%
Progress 100%
Progress 100%
BER: 0.004329004329004329

Plot BER both from the model and from theoretical calculations.

In [ ]:
using SpecialFunctions
function berawgn_psk(EbNo_dB, M)
    EbNo = 10 .^ (EbNo_dB ./ 10)
    k = log2(M)
    return 2 * erfc.(sqrt.(k .* EbNo) .* sin(π/M)) / k
end
ber_ref = berawgn_psk(EbNoArr, 8)
println("__Eb_No__: $EbNoArr")
println("_ber_ref_: $(round.(ber_ref, digits=3))")
println("ber_model: $(round.(ber, digits=3))")

p1 = plot(EbNoArr, ber_ref, seriestype = :scatter, marker = :rect, label = "Theoretical QPSK", yscale = :log10)
plot!(p1, EbNoArr, ber, seriestype = :scatter, marker = :diamond, label = "Model QPSK")
xlabel!(p1, "Eb/No (dB)")
ylabel!(p1, "BER")
title!(p1, "Bit Error Rate (Log Scale)")
# Второй график: обычный масштаб
p2 = plot(EbNoArr, ber_ref, seriestype = :scatter, marker = :rect, label = "")
plot!(p2, EbNoArr, ber, seriestype = :scatter, marker = :diamond, label = "")
ylabel!(p2, "BER")
title!(p2, "Bit Error Rate (Linear Scale)")

# Общий вывод: два графика рядом
plot(p2, p1, layout = (2, 1), size=(1000,400))
__Eb_No__: [-9, -6, -3, 0, 3, 6, 9]
_ber_ref_: [0.493, 0.426, 0.338, 0.232, 0.124, 0.041, 0.005]
ber_model: [0.404, 0.352, 0.302, 0.206, 0.106, 0.043, 0.004]
Out[0]:

Conclusion

As you can see from this example, the higher the signal to noise ratio, the smaller the error. Here we have shown how to plot BER for a simple model of a communication system and how to apply this method to analyse the system.