Вы находитесь на странице: 1из 23

POLAR CODES OVER WIRELESS FADING CHANNELS

SIDDHARTH DANGI, ARJUN SINGH


ABSTRACT. We investigate the performance of polar codes over
wireless fading channels. We measure the potential coding and
diversity gains by modelling the channel as a BSEC (binary sym-
metric erasure channel). In effect, we treat deep fades as erasures
and other error events as causing bit ips.
Polar codes, introduced by Erdal Arikan, are a class of codes that
achieve the symmetric capacity I(W) of any binary-input discrete
memoryless channel (B-DMC), while maintaining complexity O(N log N)
for both encoding and decoding. Given N independent and iden-
tical copies of a B-DMC W, a polar code synthesizes a second set
of N channels {W
(i)
N
} with the property that, when N is large, ap-
proximately NI(W) of these channels have a symmetric capacity
of 1, and approximately N (1I(W)) channels have a symmetric
capacity of 0. One can then send data only through those channels
with a symmetric capacity of 1.
1. BACKGROUND
1.1. Channel Parameters. The two channel parameters of interest
are the symmetric capacity
I(W)

yY

xX
1
2
W(y|x) log
W(y|x)
1
2
W(y|0) +
1
2
W(y|1)
and the Bhattacharyya parameter
Z(W)

yY
_
W(y|0)W(y|1).
These parameters are measures of rate and reliability, respectively.
I(W) is the highest rate at which reliable communication is possible
across W using the inputs of W with equal frequency. Z(W) is an
upper bound on the probability of MAP decision error when W is
used to transmit a single bit (a-priori equiprobable).
1.2. Polar Encoding. A polar encoder for block length N = 2
n
is
dened recursively as shown in gure 1. First, the input vector u
N
1
is transformed into s
N
1
, where s
2i1
= u
2i1
u
2i
and s
2i
= u
2i
, for
1
2 SIDDHARTH DANGI, ARJUN SINGH
1 i
N
2
. Next, the operator R
N
is applied, which is a reverse
shufe operation that produces v
N
1
= (s
1
, s
3
, ...s
N1
, s
2
, s
4
, ..., s
N
).
Finally, v
N/2
1
and v
N
N/2+1
are fed recursively into encoders for block
length
N
2
.
FIGURE 1. Polar encoder structure for block length N
Depending on the choice of code rate R, a subset of the indices,
denoted as A, is chosen such that the set of bits {u
i
, i A} do
not contain data. Instead, these bits will be xed, and known at the
receiver in advance. Accordingly, these bits are known as the frozen
bits, and the set A is known as the frozen set. See section ?? for
more background on the choice of both the frozen set and the frozen
bits. Since the encoding structure as dened above is linear, a polar
POLAR CODES OVER WIRELESS FADING CHANNELS 3
encoder for block length N can be represented simply by the matrix
equation x = uG
N
. As an example, when N = 4, the matrix is
G
4
=
_

_
1 0 0 0
1 0 1 0
1 1 0 0
1 1 1 1
_

_
If a rate of
1
2
is desired, one could for instance freeze indices 1 and 3.
Setting the frozen bits to 0 would then give the following encoding
representation:
x = (u
2
, u
4
)
_
1 0 1 0
1 1 1 1
_
+ (0, 0)
_
1 0 0 0
1 1 0 0
_
1.2.1. Choice of Frozen Set. For the polar encoder and decoder, the
frozen set should be chosen to include the indices for which corre-
sponding newly synthesized channels have either the
highest symmetric capacities (closest to 1)
lowest Bhattacharyya parameters (closest to 0)
As shown in [1], both methods achieve symmetric capacity. The sec-
ond method, however, gives an explicit bound on the probability of
block error (independent of the code rate):
P(block error) = O(N

1
4
)
Furthermore, in the initial set of N channels are binary erasure chan-
nels (BECs), there exist nice recursive formulas for calculating the
Bhattacharyya parameters of the newly synthesized channels as fol-
lows:
Z
_
W
(2j1)
N
_
= 2Z
_
W
(j)
N/2
_
Z
_
W
(j)
N/2
_
2
Z
_
W
(2j)
N
_
= Z
_
W
(j)
N/2
_
2
If the initial set of identical channels are not BECs, one do the follow-
ing:
1. Calculate the symmetric capacity I(W) of one of the initial
channels W.
2. Treat the initial channels as BECs with erasure probabilities
1 I(W).
3. Use the above recursive formulas to approximate the Bhat-
tacharyya parameters for the newly synthesized channels.
4 SIDDHARTH DANGI, ARJUN SINGH
1.3. Polar Decoding. Many of the coding results in [1] are derived
assuming a successive cancellation (SC) decoder that generates its
decision u
N
1
, in the order i from 1 to N, as follows:
u
i

_
u
i
if i A
c
h
i
(y
N
1
, u
i1
i
), if i A
In the above expression, the h
i
are decision functions that are dened
as:
h
i
(y
N
1
, u
i1
i
)
_
0, if
W
(i)
N
(y
N
1
, u
i1
1
|0)
W
(i)
N
(y
N
1
, u
i1
1
|1)
1
1, otherwise
Because these decisions are not formed using the ML rule (since they
treat future frozen bits as unknown), the SC decoder above is subop-
timal. In exchange, however, the following recursive formulas can
be used for efcient computation of the decision functions:
W
(2i1)
2N
_
y
2N
1
, u
2i2
1
|u
2i1
_
=

u
2i
1
2
W
(i)
N
_
y
N
1
, u
2i2
1,o
u
2i2
1,e
|u
2i1
u
2i
_

W
(i)
N
_
y
2N
N+1
, u
2i2
1,e
|u
2i
_
W
(2i)
2N
_
y
2N
1
, u
2i1
1
|u
2i
_
=
1
2
W
(i)
N
_
y
N
1
, u
2i2
1,o
u
2i2
1,e
|u
2i1
u
2i
_

W
(i)
N
_
y
2N
N+1
, u
2i2
1,e
|u
2i
_
Furthermore, one can still achieve the symmetric capacity using this
suboptimal decoding strategy.
POLAR CODES OVER WIRELESS FADING CHANNELS 5
2. IMPLEMENTATION
For our experiments, we simulated a Rayleigh fading channel in
MATLAB. Our channel had two paths, with a delay spread of T
d
=
10 s, and a Doppler spread of D
s
= 100 Hz. We implemented an
OFDM system using QPSK modulation, with a bandwidth of W =
1.25 MHz and N
c
= 128 subcarriers.
3. RESULTS
4. CONCLUSION
doesnt work well because we treat a channel as a BSEC when it
is, in fact, NOT.
6 SIDDHARTH DANGI, ARJUN SINGH
REFERENCES
[1] E. Arikan. Channel polarization: A method for constructing capacity-
achieving codes for symmetric binary-input memoryless channels. CoRR,
abs/0807.3917, 2008.
POLAR CODES OVER WIRELESS FADING CHANNELS 7
5. SIMULATION CODE
f unct i on coded bi t s = pol ar encoder ( bi t s )
N = l engt h ( bi t s ) ;
bi t s = reshape ( bi t s , 2 ,N/2) ;
bi t s ( : , 1 ) = mod( bi t s ( : , 1 ) + bi t s ( : , 2 ) , 2) ;
i f (N == 2)
coded bi t s = [ bi t s ( : , 1 ) ; bi t s ( : , 2 ) ] ;
e l s e
coded bi t s = [ pol ar encoder ( bi t s ( : , 1 ) ) ; pol ar encoder (
bi t s ( : , 2 ) ) ] ;
end
end
8 SIDDHARTH DANGI, ARJUN SINGH
% f unct i on decoded bi t s = pol ar decoder ( y , i nf o i ndi c es ,
pmf W)
%
% N = l engt h ( y) ;
% y = c as t ( y , i nt 32 ) ;
% i nf o i ndi c e s = c as t ( i nf o i ndi c es , i nt 32 ) ;
% decoded bi t s = zeros (N, 1 ) ;
% f or i = i nf o i ndi c es
% i f ( i == 1)
% l r = p W m( 1 , y , 0 , 0 , N, pmf W( 1 , 1) , pmf W( 1 , 0) ) /
p W( 1 , y , 0 , 1 , N, pmf W( 1 , 1) , pmf W( 1 , 0) ) ;
% e l s e
% l r = p W m( i , y , c as t ( decoded bi t s ( 1 : i 1) , i nt 32 )
, 0 ,N, pmf W( 1 , 1) , pmf W( 1 , 0) ) /p W( i , y , c as t (
decoded bi t s ( 1 : i 1) , i nt 32 ) , 1 ,N, pmf W( 1 , 1) , pmf W( 1 ,
0) ) ;
% end
% l r
% decoded bi t s ( i ) = l r < 1;
%
% end
%
% end
f unct i on [ decoded bi t s hadnan] = pol ar decoder ( y ,
f rozen i nds , pmf W)
N = l engt h ( y) ;
decoded bi t s = zeros (N, 1 ) ;
hadnan = f a l s e ;
f or i = 1 :N
i f ( any ( f r ozen i nds == i ) )
decoded bi t s ( i ) = 0; % assume a l l f rozen bi t s are 0
e l s e
i f ( i == 1)
%l r 2 = p W m( 1 , y , 0 , 0 , N, pmf W( 1 , 1) , pmf W( 1 ,
0) ) /p W m( 1 , y , 0 , 1 , N, pmf W( 1 , 1) , pmf W( 1 ,
0) ) ;
%l r = p W( 1 , c as t ( y , i nt 32 ) , 0 , 0 ,N, pmf W( 1 , 1)
, pmf W( 1 , 0) ) /p W( 1 , c as t ( y , i nt 32 ) , 0 , 1 ,N,
pmf W( 1 , 1) , pmf W( 1 , 0) ) ;
l nl r = p Wln( 1 , c as t ( y , i nt 32 ) , 0 , 0 ,N, pmf W( 1 ,
1) , pmf W( 1 , 0) ) p Wln( 1 , c as t ( y , i nt 32 )
, 0 , 1 ,N, pmf W( 1 , 1) , pmf W( 1 , 0) ) ;
i f i snan ( l nl r )
hadnan = t r ue ;
end
%i f i snan ( l r ) && i snan ( l nl r )
POLAR CODES OVER WIRELESS FADING CHANNELS 9
% di sp ( hadnan f or l r but not l nl r ) ;
%end
e l s e
%l r 2 = p W m( i , y , decoded bi t s ( 1 : i 1) , 0 ,N, pmf W
( 1 , 1) , pmf W( 1 , 0) ) /p W m( i , y , decoded bi t s
( 1 : i 1) , 1 ,N, pmf W( 1 , 1) , pmf W( 1 , 0) ) ;
%l r = p W( c as t ( i , i nt 32 ) , c as t ( y , i nt 32 ) , c as t
( decoded bi t s ( 1 : i 1) , i nt 32 ) , 0 ,N, pmf W( 1 ,
1) , pmf W( 1 , 0) ) /p W( c as t ( i , i nt 32 ) , c as t (
y , i nt 32 ) , c as t ( decoded bi t s ( 1 : i 1) , i nt 32
) , 1 ,N, pmf W( 1 , 1) , pmf W( 1 , 0) ) ;
l nl r = p Wln( c as t ( i , i nt 32 ) , c as t ( y , i nt 32 )
, c as t ( decoded bi t s ( 1 : i 1) , i nt 32 ) , 0 ,N,
pmf W( 1 , 1) , pmf W( 1 , 0) ) p Wln( c as t ( i ,
i nt 32 ) , c as t ( y , i nt 32 ) , c as t ( decoded bi t s
( 1 : i 1) , i nt 32 ) , 1 ,N, pmf W( 1 , 1) , pmf W( 1 ,
0) ) ;
i f i snan ( l nl r )
hadnan = t r ue ;
end
%i f i snan ( l r ) && i snan ( l nl r )
% di sp ( hadnan f or l r but not l nl r ) ;
%end
end
%decoded bi t s ( i ) = 1 ( l r >= 1) ;
decoded bi t s ( i ) = l nl r < 0;
end
end
end
10 SIDDHARTH DANGI, ARJUN SINGH
f unct i on symbol s out = dec l ar e er as ur es ( bi t s out , h out ,
t hreshol d , bi t s per symbol )
h mag = abs ( h out ) ;
e r a s e d bi t i ndi c e s = h mag < t hreshol d ;
%dummy = repmat ( i ndi ces bel ow t hr eshol d , bi t s per symbol
, 1) ;
%e r a s e d bi t i ndi c e s = reshape (dummy, bi t s per symbol
l engt h ( h mag) , 1) ;
symbol s out = and ( e r as e d bi t i ndi c e s , bi t s out ) + 1
e r a s e d bi t i ndi c e s ;
POLAR CODES OVER WIRELESS FADING CHANNELS 11
f unct i on [ bi t s out , h hat r epeat ed dei nt er l eaved , h hat ]
= of dm rayl ei gh channel ( bi t s i n , SNR, W, Nc , Doppler , M
, i nt er l eave , i nt e r l e ave l e ngt h )
% MQAM
modulator = modem. qammod( M , M, InputType , bi t ) ;
demodulator = modem. qamdemod( modulator ) ;
% Fi gure out how many t i mes we need t o loop
bi t s per of dm bl ock = l og2 (M) Nc ;
num ofdm blocks = l engt h ( b i t s i n ) /
bi t s per of dm bl ock ;
i f mod( l engt h ( b i t s i n ) , bi t s per of dm bl ock ) = 0
er r or ( [ The number of i nput bi t s ( , num2str ( l engt h (
b i t s i n ) ) , ) must be a mul t i pl e of l og2 (M) Nc ( ,
num2str ( bi t s per of dm bl ock ) , ) ] ) ;
end
bi t s out = zeros ( l engt h ( b i t s i n ) , 1) ;
h hat = zeros ( num ofdm blocksNc , 1) ;
% Path del ays and gai ns
Taus = [ 0 1e 5] ;
As = [ 0 3];
f c = 1e9 ;
% Cycl i c pr ef i x = del ay spread W + a smal l buf f er
L = c e i l ( Taus ( end) W) + 2;
% Channel i n i t i a l i z a t i o n
chan = rayl ei ghchan (1/W, Doppler , Taus , As ) ;
chan . St orePat hGai ns = t r ue ;
chan . Res et Be f or eFi l t e r i ng = f a l s e ;
% i nt e r l e ave
i f ( i nt e r l e ave )
num j unk bi t s = mod( i nt e r l e ave l e ngt h mod( l engt h (
b i t s i n ) , i nt e r l e ave l e ngt h ) , i nt e r l e ave l e ngt h ) ;
b i t s i n = [ b i t s i n ; zeros ( num j unk bi ts , 1 ) 2];
tmp len = l engt h ( b i t s i n ) ;
b i t s i n = reshape ( bi t s i n , tmp len/
i nt er l eave l engt h , i nt e r l e ave l e ngt h ) ;
b i t s i n = reshape ( bi t s i n , tmp len , 1 ) ;
b i t s i n = b i t s i n ( b i t s i n = 2) ;
end
ofdm symbols = modulate ( modulator , b i t s i n ) ;
ofdm symbols out = zeros ( l engt h ( ofdm symbols ) , 1) ;
12 SIDDHARTH DANGI, ARJUN SINGH
f or i =1: num ofdm blocks
d hat i n = ofdm symbols ( ( i 1)Nc+1: i Nc) ;
d = i f f t ( d hat i n ) ;
% Cycl i c pr ef i x
x = [ d( NcL+2: Nc , : ) ; d ] ;
% Add Noise
y = f i l t e r ( chan , x ) ;
y = awgn( y , SNR, 3. 0103) ;
a = chan . PathGains ( 1 , : ) ;
h = zeros ( Nc , 1) ;
f or i i =(chan . Channel Fi l t erDel ay +1) : L
htmp = 0 ;
f or j j = 1 : l engt h ( Taus )
htmp = htmp + a ( j j ) s i nc ( i i 1 Taus ( j j ) W)
exp( 1 j 2 pi f c Taus ( j j ) ) ;
end
h( i i +chan . Channel Fi l t erDel ay ) = htmp;
end
h hat ( ( i 1)Nc+1: i Nc) = f f t ( h) ;
% St r i p c yc l i c pr ef i x , f f t , and det ec t
d hat out = f f t ( y( L: end) ) . /
h hat ( ( i 1)Nc+1: i Nc) ;
ofdm symbols out ( ( i 1)Nc+1: i Nc) = d hat out ;
end
bi t s out = demodulate ( demodulator , ofdm symbols out ) ;
dummy = repmat ( h hat , l og2 (M) , 1) ;
h hat r epeat ed = reshape (dummy, l og2 (M) l engt h ( h hat ) , 1) ;
h hat r epeat ed dei nt er l eaved = h hat r epeat ed ;
% uni nt e r l e ave
i f ( i nt e r l e ave )
num j unk bi t s = mod( i nt e r l e ave l e ngt h mod( l engt h (
bi t s out ) , i nt e r l e ave l e ngt h ) , i nt e r l e ave l e ngt h ) ;
bi t s out = [ bi t s out ; zeros ( num j unk bi ts , 1 ) 2];
tmp len = l engt h ( bi t s out ) ;
POLAR CODES OVER WIRELESS FADING CHANNELS 13
bi t s out = reshape ( bi t s out , i nt er l eave l engt h ,
tmp len/i nt e r l e ave l e ngt h ) ;
bi t s out = reshape ( bi t s out , tmp len , 1 ) ;
bi t s out = bi t s out ( bi t s out = 2) ;
h hat r epat ed dei nt er l eaved = [
h hat r epeat ed dei nt er l eaved ; zeros ( num j unk bi ts ,
1) +I nf ] ;
h hat r epeat ed dei nt er l eaved = reshape (
h hat r epeat ed dei nt er l eaved , i nt er l eave l engt h ,
tmp len/i nt e r l e ave l e ngt h ) ;
h hat r epeat ed dei nt er l eaved = reshape (
h hat r epeat ed dei nt er l eaved , tmp len , 1 ) ;
h hat r epeat ed dei nt er l eaved =
h hat r epeat ed dei nt er l eaved (
h hat r epeat ed dei nt er l eaved = I nf ) ;
end
end
14 SIDDHARTH DANGI, ARJUN SINGH
f unct i on [ ber , capaci t y ] = si mul at e ever yt hi ng (SNR,
num blocks )
bsec P W = @( e p , f p ) @( y , x ) e p ( ( y == 1 && x == 0) + (
y == 1 && x == 1) ) . . .
+ f p ( ( y == 0 && x == 1) + ( y ==
1 && x == 0) ) . . .
+ ( 1 e p f p ) ( ( y == 0 && x
== 0) + ( y == 1 && x == 1) ) ;
Nc = 128;
W = 1. 25 e6 ;
Doppler = 100;
M = 4 ;
bi t s per symbol = l og2 (M) ;
bl ock l engt h = 512;
er as ur e t hr es hol d = . 4 ;
[ f l i p pr oba bi l i t y , er as ur e pr obabi l i t y ] = si m r ayl ei gh (SNR,
W, Nc , Doppler , M, er as ur e t hr es hol d ) ;
er as ur e pr obabi l i t y = er as ur e pr obabi l i t y 1. 2
f l i p pr o b a b i l i t y = f l i p pr o b a b i l i t y 1. 2
P W bsec = bsec P W( er as ur e pr obabi l i t y ,
f l i p pr o b a b i l i t y ) ;
capaci t y = I W( P W bsec )
eq er as ur e pr obabi l i t y = 1capaci t y ;
Zs = zeros ( bl ock l engt h , 1) ;
f or i =1: bl ock l engt h
Zs ( i ) = Z W( i , bl ock l engt h , eq er as ur e pr obabi l i t y ) ;
end
[ val s , i ndi c es ] = s or t ( Zs ) ;
num i nf o bi t s = f l oor ( capaci t y bl ock l engt h ) ;
i nf o i ndi c e s = i ndi c es ( 1 : num i nf o bi t s ) ;
%i nf o i ndi c e s = s or t ( i nf o i ndi c e s ) ;
f r ozen i ndi c es = i ndi c es ( num i nf o bi t s +1: end) ;
gl obal map;
map = j ava . ut i l . Hashtabl e ;
%% Si mul at i on
% Frozen bi t s are 0
i nf o b i t s = zeros ( num i nf o bi t s num blocks , 1) ;
i nput bi t s = zeros ( bl ock l engt h num blocks , 1) ;
coded bi t s = zeros ( bl ock l engt h num blocks , 1) ;
f or i =1: num blocks
f i r s t b i t i n de x = ( i 1) bl ock l engt h + 1;
POLAR CODES OVER WIRELESS FADING CHANNELS 15
l a s t b i t i nde x = i bl ock l engt h ;
f i r s t i nf o i nde x = ( i 1) num i nf o bi t s + 1;
l a s t i nf o i nde x = i num i nf o bi t s ;
pol ar i nput = zeros ( bl ock l engt h , 1) ;
t mp i nf o bi t s = round( rand ( num i nf o bi t s , 1) ) ;
pol ar i nput ( i nf o i ndi c e s ) = t mp i nf o bi t s ;
i nput bi t s ( f i r s t b i t i n de x : l a s t b i t i nde x ) =
pol ar i nput ;
i nf o b i t s ( f i r s t i nf o i nde x : l a s t i nf o i nde x ) =
t mp i nf o bi t s ;
coded bi t s ( f i r s t b i t i n de x : l a s t b i t i nde x ) =
pol ar encoder ( pol ar i nput ) ;
end
t i c
[ out put coded bi t s , h out ] = of dm rayl ei gh channel (
coded bi t s , SNR, W, Nc , Doppler , M) ;
di sp ( Chan ) ;
t oc
[ output symbol s ] = dec l ar e er as ur es ( out put coded bi t s ,
h out , er asur e t hr eshol d , bi t s per symbol ) ;
out put i nf o bi t s = zeros ( num i nf o bi t s num blocks , 1) ;
out put bi t s = zeros ( bl ock l engt h num blocks , 1) ;
nan i ndi ces = [ ] ;
f or i =1: num blocks
f i r s t b i t i n de x = ( i 1) bl ock l engt h + 1;
l a s t b i t i nde x = i bl ock l engt h ;
f i r s t i nf o i nde x = ( i 1) num i nf o bi t s + 1;
l a s t i nf o i nde x = i num i nf o bi t s ;
t i c
[ pol ar out put hadnan] = pol ar decoder ( output symbol s (
f i r s t b i t i n de x : l a s t b i t i nde x ) , f r ozen i ndi ces ,
P W bsec ) ;
di sp ( Dec )
t oc
i f hadnan
di sp ( hadnan ) ;
nan i ndi ces = [ nan i ndi ces i ] ;
end
out put bi t s ( f i r s t b i t i n de x : l a s t b i t i nde x ) =
pol ar out put ;
out put i nf o bi t s ( f i r s t i nf o i nde x : l a s t i nf o i nde x ) =
pol ar out put ( i nf o i ndi c e s ) ;
end
% f or i =num blocks : 1: 1
16 SIDDHARTH DANGI, ARJUN SINGH
% f i r s t b i t i n de x = ( i 1) bl ock l engt h + 1;
% l a s t b i t i nde x = i bl ock l engt h ;
% f i r s t i nf o i nde x = ( i 1) num i nf o bi t s + 1;
% l a s t i nf o i nde x = i num i nf o bi t s ;
% i f any ( i == nan i ndi ces )
% coded bi t s ( f i r s t b i t i n de x : l a s t b i t i nde x ) = [ ] ;
% out put coded bi t s ( f i r s t b i t i n de x : l a s t b i t i nde x )
= [ ] ;
% i nf o b i t s ( f i r s t i nf o i nde x : l a s t i nf o i nde x ) = [ ] ;
% out put i nf o bi t s ( f i r s t i nf o i nde x : l a s t i nf o i nde x
) = [ ] ;
% end
% end
num chan errors = sum( coded bi t s = out put coded bi t s )
num erasures = sum( output symbol s == 1)
[ j unk , ber ] = b i t e r r ( out put i nf o bi t s , i nf o b i t s ) ;
f i gur e ;
hold on ;
er r or i dx uns cal ed = f i nd ( out put coded bi t s = coded bi t s ) ;
er r or i dx = c e i l ( er r or i dx uns cal ed/bi t s per symbol ) ;
pl ot ( abs ( h out ) , , LineWidth , 1)
pl ot ( er r or i dx , abs ( h out ( er r or i dx ) ) , r . )
pl ot ( ones ( l engt h ( h out ) , 1) er asur e t hr eshol d , g ,
LineWidth , 1)
POLAR CODES OVER WIRELESS FADING CHANNELS 17
f unct i on output = Z W( i , N, p erasure )
i f (mod( i , 2 ) == 1)
i f ( i == 1) && (N == 1)
output = p erasure ;
e l s e
tmpZ = Z W( c e i l ( i /2) , N/2 , p erasure ) ;
output = 2 tmpZ tmpZ 2 ;
end
e l s e
output = Z W( i /2 , N/2 , p erasure ) 2 ;
end
end
18 SIDDHARTH DANGI, ARJUN SINGH
f unct i on output = I W( pmf W)
output = 0 ;
X = [ 0 , 1 ] ;
Y = [ 0 , 1 , 1] ;
f or y = Y
f or x = X
tmp = pmf W( y , x ) ;
i f ( tmp = 0)
output = output + tmp l og2 ( tmp/( 0. 5pmf W( y
, 0 ) + 0. 5pmf W( y , 1 ) ) ) ;
end
end
end
output = 0. 5 output ;
end
POLAR CODES OVER WIRELESS FADING CHANNELS 19
# i ncl ude mex . h
# i ncl ude <math . h>
# i ncl ude <i ostream>
# i ncl ude <sstream>
# i ncl ude <map>
# i ncl ude <l i mi t s >
//# def i ne MEMOIZE 4
//
usi ng st d : : numer i c l i mi t s ;
usi ng st d : : cout ;
usi ng st d : : endl ;
st d : : map<st d : : s t r i ng , double> map;
st d : : map <st d : : s t r i ng , double> : : i t e r a t o r hmi ter ;
double p W( i nt i , i nt y , i nt u hat , i nt u, i nt N, double
pe , double pf ) ;
void mexFunction ( i nt nlhs , mxArray pl hs [ ] , i nt nrhs , const
mxArray prhs [ ] )
{
i nt i = mxGetScalar ( prhs [ 0 ] ) ;
i nt yf = ( i nt ) mxGetPr ( prhs [ 1 ] ) ;
i nt u hat f = ( i nt ) mxGetPr ( prhs [ 2 ] ) ;
i nt u = mxGetScalar ( prhs [ 3 ] ) ;
i nt N = mxGetScalar ( prhs [ 4 ] ) ;
double pe = mxGetScalar ( prhs [ 5 ] ) ;
double pf = mxGetScalar ( prhs [ 6 ] ) ;
double output = 4 ;
i nt y = ( i nt ) mxCalloc ( mxGetNumberOfElements ( prhs [ 1 ] ) ,
s i ze of ( i nt ) ) ;
i nt u hat = ( i nt ) mxCalloc ( mxGetNumberOfElements ( prhs
[ 2 ] ) , s i ze of ( i nt ) ) ;
i nt i i ;
f or ( i i = 0 ; i i < mxGetNumberOfElements ( prhs [ 2 ] ) ; i i ++) {
u hat [ i i ] = u hat f [ i i ] ;
}
f or ( i i = 0 ; i i < mxGetNumberOfElements ( prhs [ 1 ] ) ; i i ++) {
y[ i i ] = yf [ i i ] ;
}
double out = p W( i , y , u hat , u, N, pe , pf ) ;
pl hs [ 0 ] = mxCreateDoubleScalar ( out ) ;
}
i nl i ne i nt xorr ( i nt uhat , i nt s i ze )
{
i nt r e t val = ( i nt ) mxCalloc ( s i ze /2 , s i ze of ( i nt ) ) ;
20 SIDDHARTH DANGI, ARJUN SINGH
i nt i ;
f or ( i = 0 ; i < s i ze /2; i ++) {
r e t val [ i ] = uhat [ 2 i ] uhat [ 2 i +1] ;
}
ret urn r e t val ;
}
i nl i ne i nt s pl i t ( i nt y , i nt si ze , i nt bottom) {
i nt r e t val = ( i nt ) mxCalloc ( si ze , s i ze of ( i nt ) ) ;
i nt i ;
f or ( i = 0 ; i < s i ze ; i ++) {
r e t val [ i ] = y[ s i ze bottom + i ] ;
}
ret urn r e t val ;
}
i nl i ne i nt evens ( i nt u hat , i nt s i ze ) {
i nt r e t val = ( i nt ) mxCalloc ( s i ze /2 , s i ze of ( i nt ) ) ;
i nt i ;
f or ( i = 0 ; i < s i ze /2; i ++) {
r e t val [ i ] = u hat [ 2 i +1] ;
}
ret urn r e t val ;
}
i nl i ne double el n ( double x )
{
i f ( x == 0) {
ret urn numeri c l i mi t s <double >: : quiet NaN ( ) ;
} e l s e {
ret urn l og ( x ) ;
}
}
i nl i ne double elnsum( double x , double y)
{
i f ( x < ( y l og ( 1 e200 ) ) ) {
ret urn y ;
}
i f ( y < ( x l og ( 1 e200 ) ) ) {
ret urn x ;
}
i f ( i snan ( x ) ) {
ret urn y ;
} e l s e i f ( i snan ( y) ) {
ret urn x ;
POLAR CODES OVER WIRELESS FADING CHANNELS 21
}
i f ( x > y) {
double di f f = y x ;
i f ( ! f i n i t e ( exp ( di f f ) ) ) {
ret urn ( x > y ? x : y) ;
}
ret urn x + el n ( 1 + exp ( di f f ) ) ;
} e l s e {
double di f f = x y ;
i f ( ! f i n i t e ( exp ( di f f ) ) ) {
ret urn ( x > y ? x : y) ;
}
ret urn y + el n ( 1 + exp ( di f f ) ) ;
}
}
i nl i ne double el nproduct ( double x , double y)
{
i f ( i snan ( x ) | | i snan ( y) ) {
ret urn numeri c l i mi t s <double >: : quiet NaN ( ) ;
} e l s e {
ret urn x + y ;
}
}
double p W( i nt i , i nt y , i nt u hat , i nt u, i nt N, double
pe , double pf ) {
//FILE f i l e = fopen(/Users/arj un/bl ah . t t t t t , a ) ;
// i f ( f i l e == NULL) {
// pr i nt f ( er r or opening f i l e ) ;
//}
//f pr i nt f ( f i l e , %d %d\n , i , N) ;
//f c l os e ( f i l e ) ;
double output ;
# i f de f MEMOIZE
st d : : st r i ngst r eam ss ;
ss << i ;
f or ( i nt i i i = 0 ; i i i < i 1; i i i ++) {
ss << y[ i i i ] << u hat [ i i i ] ;
}
ss << y[ i 1] ;
f or ( i nt i i i = i ; i i i < N; i i i ++) {
ss << y[ i i i ] ;
}
ss << u << N << pe << pf ;
22 SIDDHARTH DANGI, ARJUN SINGH
st d : : s t r i ng key = ss . s t r ( ) ;
hmi ter = map. f i nd ( key ) ;
i f ( hmi ter ! = map. end ( ) ) {
output = hmiter>second ;
ret urn output ;
}
# endi f
i f ( i % 2 == 1) {
i f ( i == 1) {
i f (N == 1) {
// output = ( y [ 0 ] == 1) ? pe : ( ( u ! = y [ 0 ] ) ? pf :
( 1 pe pf ) ) ;
output = ( y [ 0 ] == 1) ? el n ( pe ) : ( ( u ! = y [ 0 ] ) ?
el n ( pf ) : el n ( 1 pe pf ) ) ;
} e l s e {
//output = . 5 ( ( p W( 1 , s pl i t ( y , N/2 , 0) , u hat ,
u, N/2 , pe , pf ) p W( 1 , s pl i t ( y , N/2 , 1) , u hat
, 0 , N/2 , pe , pf ) ) +
// (p W( 1 , s pl i t ( y , N/2 , 0) , u hat , !
u, N/2 , pe , pf ) p W( 1 , s pl i t ( y , N/2 , 1) , u hat
, 1 , N/2 , pe , pf ) ) ) ;
double f i r s t t e r m = el nproduct (p W( 1 , s pl i t ( y , N
/2 , 0) , u hat , u, N/2 , pe , pf ) , p W( 1 , s pl i t ( y ,
N/2 , 1) , u hat , 0 , N/2 , pe , pf ) ) ;
double second term = el nproduct (p W( 1 , s pl i t ( y , N
/2 , 0) , u hat , ! u, N/2 , pe , pf ) , p W( 1 , s pl i t ( y ,
N/2 , 1) , u hat , 1 , N/2 , pe , pf ) ) ;
double sum = elnsum( f i r s t t e r m , second term ) ;
output = el nproduct ( . 5 , sum) ;
mxFree ( y) ;
}
} e l s e {
//output = . 5 (
// p W( ( i +1) /2 , s pl i t ( y , N/2 , 0) , xorr ( u hat , i 1)
, u, N/2 , pe , pf ) p W( ( i +1) /2 , s pl i t ( y , N/2 , 1) ,
evens ( u hat , i 1) , 0 , N/2 , pe , pf ) +
// p W( ( i +1) /2 , s pl i t ( y , N/2 , 0) , xorr ( u hat , i 1)
, ! u, N/2 , pe , pf ) p W( ( i +1) /2 , s pl i t ( y , N/2 , 1) ,
evens ( u hat , i 1) , 1 , N/2 , pe , pf ) ) ;
double f i r s t t e r m = el nproduct (p W( ( i +1) /2 , s pl i t ( y
, N/2 , 0) , xorr ( u hat , i 1) , u, N/2 , pe , pf ) , p W
( ( i +1) /2 , s pl i t ( y , N/2 , 1) , evens ( u hat , i 1) , 0 ,
N/2 , pe , pf ) ) ;
POLAR CODES OVER WIRELESS FADING CHANNELS 23
double second term = el nproduct (p W( ( i +1) /2 , s pl i t ( y
, N/2 , 0) , xorr ( u hat , i 1) , ! u, N/2 , pe , pf ) , p W
( ( i +1) /2 , s pl i t ( y , N/2 , 1) , evens ( u hat , i 1) , 1 ,
N/2 , pe , pf ) ) ;
double sum = elnsum( f i r s t t e r m , second term ) ;
output = el nproduct ( . 5 , sum) ;
mxFree ( y) ;
mxFree ( u hat ) ;
}
} e l s e {
i f ( i == 2) {
//output = . 5 ( p W( 1 , s pl i t ( y , N/2 , 0) , 0 , u u hat
[ 0 ] , N/2 , pe , pf ) p W( 1 , s pl i t ( y , N/2 , 1) , 0 , u,
N/2 , pe , pf ) ) ;
double f i r s t t e r m = el nproduct (p W( 1 , s pl i t ( y , N/2 ,
0) , 0 , u u hat [ 0 ] , N/2 , pe , pf ) , p W( 1 , s pl i t ( y ,
N/2 , 1) , 0 , u, N/2 , pe , pf ) ) ;
output = el nproduct ( . 5 , f i r s t t e r m ) ;
mxFree ( y) ;
mxFree ( u hat ) ;
} e l s e {
//output = . 5p W( i /2 , s pl i t ( y , N/2 , 0) , xorr ( u hat ,
i 2) , u u hat [ ( i 1) 1] , N/2 , pe , pf ) p W( i /2 ,
s pl i t ( y , N/2 , 1) , evens ( u hat , i 2) , u, N/2 , pe ,
pf ) ;
double f i r s t t e r m = el nproduct (p W( i /2 , s pl i t ( y , N
/2 , 0) , xorr ( u hat , i 2) , u u hat [ ( i 1) 1] , N/2 ,
pe , pf ) , p W( i /2 , s pl i t ( y , N/2 , 1) , evens ( u hat , i
2) , u, N/2 , pe , pf ) ) ;
output = el nproduct ( . 5 , f i r s t t e r m ) ;
mxFree ( y) ;
mxFree ( u hat ) ;
}
}
# i f de f MEMOIZE
map[ key ] = output ;
# endi f
ret urn output ;
}

Вам также может понравиться