Skip to content
Permalink
Browse files

Support for binary symmetric channel

  • Loading branch information...
joachimneu committed Jan 20, 2019
1 parent 8cf08d2 commit 1abf36359437897beb007d5fec09c8a641f2b606
Showing with 67 additions and 3 deletions.
  1. +7 −0 src/BridgeCh2DE.jl
  2. +56 −1 src/Channels.jl
  3. +4 −2 src/SimulationUtils.jl
@@ -8,6 +8,7 @@ module BridgeCh2DE
using Polar.Channels
using Polar.DensityEvolution
using Polar.CommunicationsUtils
using Polar.Utils


function channeloutputdistribution(ch::BiAWGNChannel)
@@ -21,4 +22,10 @@ module BridgeCh2DE
return DiscreteDEDistribution{PostPPValue{Tllr,f_map}}(Dict( PostPPValue{Tllr,f_map}(val) => prob for (val, prob) in channeloutputdistribution(ch, Tllr) ))
end

function channeloutputdistribution(ch::BSChannel)
@assert !(ch.p ≈ 0.0)
Δ = ln((1-ch.p)/ch.p)
return DiscreteDEDistribution{FloatValue}(Dict( FloatValue(+Δ) => (1-ch.p), FloatValue(-Δ) => ch.p ))
end

end
@@ -3,7 +3,7 @@ __precompile__()
module Channels

using SpecialFunctions
using Polar.GF2n: GF2Element, toint
using Polar.GF2n: GF2Element, toint, GF2_0, GF2_1, ⊻
using Polar.CommunicationsUtils


@@ -32,6 +32,7 @@ module Channels
export AbstractCommunicationsChannel
export AWGNChannel, BiAWGNChannel
export BEChannel
export BSChannel
export intype, outtype, get_w, get_f, get_llr

abstract type AbstractCommunicationsChannel end
@@ -127,4 +128,58 @@ module Channels
return llr
end


struct BSChannel <: AbstractCommunicationsChannel
p::Float64

function BSChannel(p::Float64)
@assert 0.0 <= p <= 0.5
return new(p)
end
end
intype(::Type{BSChannel}) = BinaryAlphabet
outtype(::Type{BSChannel}) = BinaryAlphabet
function get_w(ch::BSChannel, x::BinaryAlphabet)
function w(y::BinaryAlphabet)::Float64
if x == y
return 1-ch.p
else # x != y
return ch.p
end
end
return w
end
function get_f(ch::BSChannel)
function f(x::BinaryAlphabet)::BinaryAlphabet
if rand() <= ch.p
return x ⊻ GF2_1
else
return x
end
end
return f
end
function get_llr(ch::BSChannel)
if ch.p ≈ 0.0
function llr1(y::BinaryAlphabet)
if y == GF2_0
return +Inf
else # y == GF2_1
return -Inf
end
end
return llr1
else
Δ = ln((1-ch.p)/ch.p)
function llr2(y::BinaryAlphabet)
if y == GF2_0
return +Δ
else # y == GF2_1
return -Δ
end
end
return llr2
end
end

end
@@ -243,7 +243,8 @@ module SimulationUtils
tic!(result, :MLError)
elseif pm_opt == pm_ml
# the list does contain the true data, don't add it
if rand() > 1. / (count(list_pms .== pm_ml) + 0)
# if rand() > 1. / (count(list_pms .== pm_ml) + 0)
if rand() > 1. / (count(x -> x == pm_ml, list_pms) + 0)
tic!(result, :MLError)
end
end
@@ -258,7 +259,8 @@ module SimulationUtils
tic!(result, :MLError)
elseif pm_opt == pm_ml
# the list does not contain the true data, add it
if rand() > 1. / (count(list_pms .== pm_ml) + 1)
# if rand() > 1. / (count(list_pms .== pm_ml) + 1)
if rand() > 1. / (count(x -> x == pm_ml, list_pms) + 1)
tic!(result, :MLError)
end
end

0 comments on commit 1abf363

Please sign in to comment.
You can’t perform that action at this time.