-
Notifications
You must be signed in to change notification settings - Fork 1
/
theoretical.jl
66 lines (53 loc) · 2.34 KB
/
theoretical.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# This file includes the theoretical functions of the ber performance cureves.
export berask, berpam, berpsk, berfsk, berqam, plotber
"""
$SIGNATURES
Returns the probability of symbol error for the snr per bit `γb` and constallation size `M` for ASK and PAM signalling
"""
berask(γb, M) = 2 * (1 - 1 / M) * Q(sqrt(6log2(M) / (M^2 - 1) * dbtoval(γb)))
berpam = berask
"""
$SIGNATURES
Returns the probability of symbol error for the snr per bit `γb` and constallation size `M` for PSK signalling
"""
berpsk(γs, M) = 1 - quadgk(θ -> pθ(θ, dbtoval(γs)), -π/M, π/M)[1]
pθ(θ, γs) = 1 / (2π) * exp(-γs * sin(θ) * sin(θ)) * quadgk(υ -> integrand(υ, γs, θ), 0, Inf)[1]
integrand(υ, γs, θ) = υ * exp(-1 / 2 * (υ - sqrt(2 * γs) * cos(θ))^2)
"""
$SIGNATURES
Returns the probability of symbol error for the snr per bit `γb` and constallation size `M` for FSK signalling
"""
function berfsk(γs, M)
k = log2(M)
pe = 1 / sqrt(2π) * quadgk(x -> (1 - (1 - Q(x))^(M - 1)) * exp(-1/2 * (x - sqrt(2 * dbtoval(γs)))^2), -Inf, Inf)[1]
# # Return probability of symbol error, not probability of bits error
# pb = 2^(k -1) / (2^k - 1) * pe
end
"""
$SIGNATURES
Returns the probability of symbol error for the snr per bit `γb` and constallation size `M` for QAM signalling
"""
function berqam(γb, M)
qval = Q(√(3log2(M) / (M - 1) * dbtoval(γb)))
4 * (1 - 1 / √(M)) * qval * (1 - (1 - 1 / √(M)) * qval)
end
#------------------------ Plots ---------------------------------------
"""
$SIGNATURES
Plots the probability of symbol error versus snr per bit for the signaling `scheme`. `snr_per_bit_range` is the snr per bit range and `krange` is the symbol size of the M-ary signalling where ``M=2^k``.
"""
function plotber(;scheme="ASK", snr_per_bit_range=collect(-4 : 1 : 20), krange = 1 : 4,
pltkwargs...)
# Extract the ber function
schemes = ["ASK", "PSK", "QAM", "FSK"]
scheme in schemes || throw(ArgumentError("Expected `$schemes`, got `$scheme` instead"))
@eval pe_vs_snr = $(Symbol("ber" * lowercase(scheme)))
# Plot
plt = plot(xlabel="γb", ylabel="Pe", title="M-$(scheme)", pltkwargs...)
for k in krange
M = 2^k
γs = k * dbtoval.(snr_per_bit_range)
plot!(snr_per_bit_range, pe_vs_snr.(γs, M), yscale=:log10, label="M=$M")
end
plt
end