-
Notifications
You must be signed in to change notification settings - Fork 1
/
detector.jl
52 lines (40 loc) · 1.38 KB
/
detector.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
# This file includes to blocks used in a digital communication system.
export Detector, isml
"""
$TYPEDEF
Baseband optimal detector.
!!! note
If elements of `probs` are equal to each other, than detector detects symbols in the maximum likelihood (ML)
mode. Otherwise, it detects in the maximum a posterior probabilities (MAP) mode.
# Fields
$TYPEDFIELDS
"""
struct Detector{T}
"Basis reference of the detector"
refs::T
"A priori probabilities of the message symbols"
probs::Vector{Float64}
"2 times the power spectral density of channel noise"
N0::Float64
end
Detector(refs) = Detector(refs, fill(1 / length(refs), length(refs)), NaN)
"""
$SIGNATURES
Returns true if `detector` is a maximum likelihood detector, i.e, a priori probabilities of its reference refs are
equal.
"""
isml(detector::Detector) = (probs = detector.probs; all(probs .≈ probs[1]))
(detector::Detector)(rx) = isml(detector) ? mldetect(detector, rx) : mapdetect(detector, rx)
function mapdetect(detector::Detector, rx)
Es = 1 / 2 * energy.(detector.refs)
Pm = detector.N0 * log.(detector.probs)
map(rx) do ri
argmax(map(s -> real(ri ⋅ s), detector.refs) - Es + Pm)
end
end
function mldetect(detector::Detector, rx)
Es = 1 / 2 * energy.(detector.refs)
map(rx) do ri
argmax(map(s -> real(ri ⋅ s), detector.refs) - Es)
end
end