Document 5773951

advertisement
Turbo Codes
Colin O’Flynn
Dalhousie University
http://www.newae.com/tiki-index.php?page=Turbo
coflynn@dal.ca
Last Update of This Presentation: Thursday Jan 26 / 2012
Handy References @Dal
Trellis and turbo coding
Schlegel, Christian B.; Pérez, Lance C.
http://www.knovel.com/web/portal/basic_search/display?_EXT_KNOVEL_DISPLAY_bookid=1988
http://www.amazon.ca/Trellis-Turbo-Coding-Christian-Schlegel/dp/0471227552/
Codes and turbo codes
Claude Berrou
http://www.springerlink.com/content/w56240
http://www.amazon.ca/Codes-turbo-codes-Claude-Berrou/dp/2817800389
Turbo code applications : a journey from a paper to realization
Keattisak Sripimanwat
http://www.springerlink.com/content/l32688/
http://www.amazon.ca/Turbo-Code-Applications-Journey-realization/dp/1402036868
Note: You need to be on Dalhousie Network or using EZProxy to access these
2
resources online.
Handy References @Dal
The design and application of RZ turbo codes
Xin Liao
http://proquest.umi.com/pqdlink?Ver=1&Exp=11-01-2016&FMT=7&DID=766741131&RQT=309
Turbo coding, turbo equalisation, and space-time coding : exit-chart
aided near-capacity designs for wireless channels
L. Hanzo et. al.
http://www.dal.worldcat.org/title/turbo-coding-turbo-equalisation-and-space-time-coding-exit-chartaided-near-capacity-designs-for-wireless-channels/oclc/666867885&referer=brief_results
3
Note: You need to be on Dalhousie Network or using EZProxy to access these resources online.
Handy References
A Turbo Code Tutorial
William E. Ryan
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.37.4605
Liang Li’s Nine Month Report & MATLAB Code
Liang Li, Rob Maunder
http://users.ecs.soton.ac.uk/rm/wp-content/liang_li_nine_month_report.pdf
http://users.ecs.soton.ac.uk/rm/resources/matlabturbo/
Chapers 4,9,15 of Turbo coding, turbo equalisation, and space-time
coding : exit-chart aided near-capacity designs for wireless channels
http://eprints.ecs.soton.ac.uk/8252/2/Turbo_Chaps_4,9,15.pdf
4
Notes If You Are Viewing Online
Be sure to enable presentation notes, as there is some additional information there:
I’m using the following acronyms to reference where you can find additional information:
CATC: Codes and Turbo Coding, 1st Edition, Berrou
TATC: Trellis and Turbo Coding, 1st Edition, Schlegel
TCT: Turbo Code Tutorial, Ryan
TCTEASTC: Turbo Coding, Turbo Equalization, and Space-Time Coding
5
Which Reference to Use?
Trellis and Turbo Coding – Very in-depth guide to Turbo Codes, including mathematical
derivation. Covers sufficient background to make book stand-alone reference. Covers topics I
didn’t find in other books such as derivation of free-distance for turbo codes.
Codes and Turbo Coding – Less mathematical derivation by comparison, but contains some
examples which are easier to follow. Author was also on team that invented Turbo Codes.
Turbo Code Applications – Covers how codes are used in real systems, and also history of
discovery in more depth than other books.
Turbo coding, turbo equalisation, and space-time coding : exit-chart aided near-capacity
designs for wireless channels - I found had easiest to understand description of how Turbo
Decoding works. Includes a complete example of the decoding process, with intermediate
values and internal operation of soft-output decoders. Also includes substantial number of
charts showing difference in performance for changing Turbo parameters, which is fairly
interesting. You can get a few chapters of this book online (see previous slides for link).
6
BACKGROUND, HAND-WAVING,
AND ALL THAT STUFF
7
The Beginning
10100
01100
<
101000101011
011001011011
8
“With 52 FPGAs for the processors, 52 FPGAs for the switches, seven
FPGAs for the memory controllers and one FPGA to control the whole
system, a total of 112 FPGAs are required. In total, the cost of the
RACER II is approximately $200,000, which is 10 times cheaper than
the BVD at the same decoding rate and without the need for custom
ASICs”
9
The Beginning
Large MHD Code
Small MHD Code
What we can have
What we want
“It's not the quantity that
counts — it's the quality”
WRONG
10
The Beginning
Small MHD Code
Large MHD Code
Small MHD Code
Small MHD Code
Maybe we can get the large MHD by using
several of the small ones…
11
Concatenated Codes: Serial
Permutation
Outer Encoder
Inner Encoder
Permutation
Inner Decoder
Outer Decoder
12
Concatenated Codes: Parallel
Systematic Part of Codeword
Encoder 1
Redundant Part of
Codeword from Enc 1
Encoder 2
Redundant Part of
Codeword from Enc 2
Permutation
13
Concatenated Codes: Comparison Shopping
Parallel
R1 R2
Rp 
1  (1  R1 )(1  R2 )
Serial
Rs  R1R2
MHD Normally better compared
to parallel
Systematic ONLY, at least one should
be recursive, need to be careful with
code choice
Systematic or Non-Systematic, pretty
indifferent to code choice
14
Example: Parallel
Using Hamming (7,4) as base:
Data
d
d

d

d
d
d
d
d
d
d
d
d
d
d 
d

d
p
p

 p
p
p
p
p
p
p
p
p 
p 
p
p

p

p
p
p
p
p
p
p 
p

p
Parity from Code 1
Parity from Code 2
15
Example: Parallel
Using Hamming (7,4) as base:
Data
1
0

0

0
0
0
0
0
0
0
0
0
0
0 
0

0
1 0 0 0 
1 0 0 0 


 0 0 0 0 
1
0

0

0
1
0
0
0
0
0 
0

0
Parity
Math from
StuffCode 1
Rate = 16/40 =4/10
For input of weight 1, output = 5
Asymptotic Gain = 10log(R*d)
= 10log(4 * 5 / 10) =3.01 dB
Compare with input code:
=10log(4 * 3 / 7) = 2.34 dB
Parity from Code 2
16
Example: Serial
Using Hamming (7,4) as base:
Data
0
0 
0

0
1 0 0 0 1 1 0 
1 0 0 0 1 1 0 


0 0 0 0 0 0 0 
1
0

0

0
0
0
0
0
0
0
0
0
0  1
0   0
0 0

0 0
1
0
0
0
Parity
Math from
StuffCode 1
Rate = 16/49
For input of weight 1, output = 9
Asymptotic Gain = 10log(R*d)
= 10log(16 * 9 / 49) =4.68 dB
Compare with input code:
=10log(4 * 3 / 7) = 2.34 dB
Parity from Code 2
17
Concatenated Codes: Conclusions
As promised, serial codes had better MHD but
worse Rate. Parallel codes can work well but
should use Recursive Systematic
Convolutional (RSC) codes – notice poor
performance with hamming code here.
18
Tag Team (Iterative) Decoding
Eat this
Error-Man!
19
Iterative Example
1
2
3
4
5
i
V S D A L
ii
T H E T A
iii
L A N E S
iv
A P O N G
v
P
I N T O
i.
ii.
iii.
iv.
v.
animate
Greek
Sticks
Conflicts
slow
1.
2.
3.
4.
5.
oral
representation
projection
force
rope
This example from: Codes and Turbo Codes by Claude Berrou
20
Iterative Example - Across
1
2
3
4
5
i
V S D A L
ii
T H E T A
iii
C A N E S
iv
A P O N G
v
P
I N T O
i.
ii.
iii.
iv.
v.
animate
Greek
Sticks
Conflicts
slow
1.
2.
3.
4.
5.
oral
representation
projection
force
rope
This example from: Codes and Turbo Codes by Claude Berrou
21
Iterative Example - Down
1
2
3
4
5
i
V S T A L
ii
T H E G A
iii
C A N E S
iv
A P O N S
v
P E N T O
i.
ii.
iii.
iv.
v.
animate
Greek
Sticks
Conflicts
slow
1.
2.
3.
4.
5.
oral
representation
projection
force
rope
This example from: Codes and Turbo Codes by Claude Berrou
22
Iterative Example - Across
1
2
3
4
5
i
V I
ii
T H E G A
iii
C A N E S
T A L
iv
A G O N S
v
L E N T O
i.
ii.
iii.
iv.
v.
animate
Greek
Sticks
Conflicts
slow
1.
2.
3.
4.
5.
oral
representation
projection
force
rope
Agons = fight/struggle in Latin
Lento = slow in Spanish
This example from: Codes and Turbo Codes by Claude Berrou
23
Iterative Example - Down
1
2
3
4
5
i
V I
ii
O M E G A
iii
C A N E S
T A L
iv
A G O N S
v
L E N T O
i.
ii.
iii.
iv.
v.
animate
Greek
Sticks
Conflicts
slow
1.
2.
3.
4.
5.
oral
representation
projection
force
rope
Tenon = A projecting piece of wood made for insertion
into a mortise in another piece
This example from: Codes and Turbo Codes by Claude Berrou
24
Iterative Example - Across
1
2
3
4
5
i
V I
ii
O M E G A
iii
C A N E S
T A L
iv
A G O N S
v
L E N T O
i.
ii.
iii.
iv.
v.
animate
Greek
Sticks
Conflicts
slow
1.
2.
3.
4.
5.
oral
representation
projection
force
rope
This example from: Codes and Turbo Codes by Claude Berrou
25
Turbo Encoder – General Format
Systematic Part of Codeword
Encoder 1
Redundant Part of
Codeword from Enc 1
Permutation
Puncturing (Optional)
Encoder 2
Redundant Part of
Codeword from Enc 2
26
Turbo Encoder - Permutation
101001010101010101010101011010101011100010101110101
WIRELES
S
CHANNEL
101001010010101010101101011010101011100010101110101
27
Turbo Encoder - Permutation
101001010101010101010101011010101011100010101110101
101001010101010101010101011010101011100010101110101
WIRELES
S
CHANNEL
101001010010101010101101011010101011100010101110101
101001010101010101010101011010101011100010101110101
28
Turbo Encoder - Permutation
Assumption: Nature Hates Us
(In all fairness, we started it.)
29
Turbo Encoder - Permutation
101001010101010101010101011010101011100010101110101
101001010101010101010101011010101011100010101110101
WIRELES
S
CHANNEL
101001010101010101010101011010101011100010101110101
101001010010101010101101011010101011100010101110101
30
Turbo Encoder - Termination
1. Do Nothing
•
•
Decreases Asymptotic Gain
Will give proof later about why this is bad – hold on
31
Turbo Encoder - Termination
2. Terminate the Trellis of One or Both, outside
of permutation
Systematic Part of Codeword
Message
Encoder 1
Redundant Part of
Codeword from Enc 1
Permutation
Puncturing (Optional)
Encoder 2
Redundant Part of
Codeword from Enc 2
32
Unterminated Loss
N=1024, only
1st encoder
terminated
N=1024, both
encoders
terminated
From “Illuminating the Structure of Code and Decoder of Parallel Concatenated Recursive
33
Systematic (Turbo) Codes”, by Patrick Robertson
Turbo Encoder - Termination
3. Use Interleaver to Terminate Trellis based on
input sequence to first
34
Turbo Encoder - Termination
4. Circular Encoding (“Tail Biting”)
See page 138 of TATC or page 194 of CATC.
35
A LITTLE MORE RIGOR
36
Why is RSC So Good?
Convolution Code (Not Systematic, Not Recursive):
G  [ g1 (D) g2 (D)]  [1  D3  D4 1  D  D3  D4 ]
Note: Input of weight 1 results in finite-weight output
37
TACT pp291, TTC pp1
Why is RSC So Good?
Recursive Systematic Convolution Code:
 g 2 ( D)   1  D  D 3  D 4 
G  1
  1

3
4
1 D  D 
 g1 ( D)  
Note: Input of weight 1 results in infinite-weight output
38
Example with Non-Recursive
Systematic Part of Codeword
Encoder 1
Redundant Part of
Codeword from Enc 1
Permutation
Non-recursive encoders
Encoder 2
Redundant Part of
Codeword from Enc 2
39
Example with RSC
Systematic Part of Codeword
Encoder 1
Redundant Part of
Codeword from Enc 1
Permutation
RSC
Encoder 2
Redundant Part of
Codeword from Enc 2
40
Permutation - Linear
0
0

0

0
0

0
0 0 0 0 0
1 0 0 1 0 
0 0 0 0 0

0 0 0 0 0
1 0 0 1 0

0 0 0 0 0
Encoder 1
dFree
Permutation
Encoder 2
dFree
41
TACT pp296-7
Permutation - Random
0
0

0

0
0

0
0 0 0 0 0
1 0 0 1 0 
0 0 0 0 0

0 0 0 0 0
1 0 0 1 0

0 0 0 0 0
Encoder 1
dFree
Permutation
1
0

0

0
0

0
0 1 0 0 0
0 1 0 0 0 
0 0 0 0 0

0 0 0 0 0
0 0 0 0 0

1 0 0 0 0
Encoder 2
dFree
42
Why Terminate Encoder 1?
000…001
43
ANALYZING PERFORMANCE
44
What does Turbo Code BER Look
Like?
Turbo Cliff
45
46
Bit Error Rate Bound of FiniteLength Convolution Code
wi 
2 REb
Pber   Q  d i
N0
i 1 N

2N



wi  Hamming weight of information sequence input i
N  Size of block
k
R = Code rate ( )
n
di  Hamming weight of codeword i
Eb
 SNR
N0
47
TACT 10.3 / 10.4 : pp290-7
Distance Spectrum Representation of
Bound
Pber 


d  d free
N d wd 
2 REb
Q  d
N
N0




N d  Number of information sequences causing codeword weight d
wd  Mean hamming weight of all information sequences counted in N d
N  Size of block
k
R = Code rate ( )
n
Eb
 SNR
N0
48
TACT 10.3 / 10.4 : pp290-7
Free Distance of Turbo Code
N free wfree 
2 REb
Pber 
Q  d free
N
N0




N free  Number of information sequences causing minimum codeword weight d free
wfree  Mean hamming weight of all information sequences counted in N free
N  Size of interleaver
k
R = Code rate ( )
n
d free  Minimum distance d free
Eb
 SNR
N0
49
TACT 10.3 / 10.4 : pp290-7
Plotting Distance Spectrum
function printBERContribution( d, Nd, wd, N, R )
%PRINTBERCONTRIBUTION Print contribution from distance spectrum components.
% d, Nd, wd are arrays of numbers, each index corresponding to one spectral
% component. N is interleaver size. R is rate.
close all;
%SNR Range in dB
SNR_range = [0:0.01:2];
ebno = 10 .^ (SNR_range ./ 10);
ber=zeros(length(d), length(ebno));
linetypes = {'b', 'r--', 'b--', 'r:', 'b:', 'r-.', 'b-.'};
leg = cell(1,length(d));
for i=1:length(d)
ber(i+1,:) = ber(i,:) + ((Nd(i) * wd(i)) / N) * qfunc (sqrt(d(i) * 2 * R * ebno));
semilogy(SNR_range, ber(i+1,:), linetypes{i});
hold on
leg{i} = sprintf('d = %d', d(i));
end
legend(leg);
50
Distance Spectrum Examples
The following plotted with Roger Garello’s algorithm & software. Based on
‘example 2’ available from:
http://www.tlc.polito.it/garello/turbodistance/turbodistance.html
Full tutorial for plotting given in Part 2.
Specifications:
-No Puncturing (e.g.: rate = 1/3)
-Block length = 1000
51
Distance Spectrum (examples)
Linear Interleaver N=1000
d
Nd
Wd
11
1
1
21
1
2
24
1
1
>> inter = CreateLinearInterleaver(1000,25,40); >> plot(0:999, inter, ‘.’)
>> writePerm(inter);
turbo.exe
52
Distance Spectrum Contribution
>>
>>
>>
>>
d=[11 21 24];
Nd=[1 1 1];
wd=[1 2 1];
printBERContribution(d, Nd, wd, 1000, 1/3);
53
Distance Spectrum (examples)
Linear Interleaver N=1000
d
Nd
Wd
11
1
1
14
1
2
15
1
1
18
1
3
>> inter = CreateLinearInterleaver(1000,100,10); >> plot(0:999, inter, ‘.’)
>> writePerm(inter);
turbo.exe
54
Distance Spectrum (examples)
Random Interleaver N=1000
d
Nd
Wd
14
2
4
16
1
1
18
3
6
19
2
4
>> inter = CreateRandomInterleaver(1000);
>> writePerm(inter);
turbo.exe
>> plot(0:999, inter, ‘.’)
55
Distance Spectrum (examples)
Another Random Interleaver N=1000
d
Nd
Wd
14
1
2
15
1
1
18
5
10
19
1
3
>> inter = randperm(1000) – 1;
>> writePerm(inter)
turbo.exe
>> plot(0:999, inter, ‘.’)
56
Distance Spectrum Contribution
>>
>>
>>
>>
d=[20 22 25 26];
Nd=[1 5 1 8];
wd = [1 10 3 16];
printBERContribution(d, Nd, wd, 1000, 1/3);
57
Distance Spectrum (examples)
S Random Interleaver N=1000, S=9
d
Nd
Wd
18
4
8
21
1
3
22
4
8
24
1
2
>> inter = CreateSRandomInterleaver(1000, 9);
>> writePerm(inter)
turbo.exe
>> plot(0:999, inter, ‘.’)
58
Distance Spectrum Contribution
>>
>>
>>
>>
d=[18 21 22 24];
Nd = [4 1 4 1];
wd = [8 3 8 2];
printBERContribution(d, Nd, wd, 1000, 1/3);
59
Distance Spectrum (examples)
S Random Interleaver N=1000, S=16
d
Nd
Wd
20
1
1
22
5
10
25
1
3
26
8
16
>> inter = CreateSRandomInterleaver(1000, 16);
>> writePerm(inter)
turbo.exe
>> plot(0:999, inter, ‘.’)
60
Free Distance Asymptote vs. BER
>> startup
>> CmlSimulate(‘TurboTests’, [8])
(wait a while, can end early with
Ctrl-C if you don’t need higher
SNRs)
>> CmlPlot(‘TurboTests’, [8])
>> close([2 3 4])
>> figure(1)
>> hold on
>> printBERContribution([18],
[4], [8], 1000, 1/3)
Using S-Random interleaver, S=9, same parameters as in previous slides.
61
Sidenote: Simulation Time
SNR Value (dB)
Delta Sim Time
(hour:min:sec)
Actual Sim Time
(hour:min:sec)
0.00
00:00:02
00:00:02
0.25
00:00:02
00:00:04
0.50
00:00:03
00:00:07
0.75
00:00:07
00:00:14
1.00
00:00:32
00:00:46
1.25
00:03:55
00:04:41
1.50
00:12:05
00:16:46
1.75
00:16:18
00:33:04
2.00
00:26:45
00:59:49
2.25
00:51:03
01:50:52
2.50
01:28:47
03:19:39
2.75
02:22:46
05:42:25
3.00
04:13:04
09:55:29
3.25
08:19:09
18:14:38
3.50
16:54:45
35:08:33
Using cml running on dual 3.5
GHz Intel i7 990 on 64-bit Linux.
No shortage of processing power!
62
Free Distance Asymptote vs. BER
>> startup
>> CmlSimulate(‘TurboTests’, [9])
(wait a while, can end early with
Ctrl-C if you don’t need higher
SNRs)
>> CmlPlot(‘TurboTests’, [9])
>> close([2 3 4])
>> figure(1)
>> hold on
>> printBERContribution([11],
[1], [1], 1000, 1/3)
Using Linear interleaver, same parameters as in previous slides.
63
TURBO DECODING
64
Soft Input Soft Output (SISO)
0
1
0
1
1
0
1
1
1
0
Things we
Both
Know
Decoder 1
Things
Only I
Know
Decoder 2
Things
only I
Know
65
A Posteriori Probability (APP)
State 00
State 01
State 10
State 11
Log-likelihood Ratio
 P(uk  1) 
L(uk )  ln 

 P(uk  0) 
WARNING: Some papers define this other way around, so if using code or equations
which rely on LLR, always look back to see which way the code/equation previously
defined it.
“Trellis and Turbo Coding” for example defines it as ln(p0/p1).
67
Log-likelihood Ratio
>>
>>
>>
>>
>>
>>
p1=[0:0.01:1]
p0=1-p1;
llr = log(p1./p0);
plot([0:0.01:1], llr);
xlabel('P(u = 1)');
ylabel('LLR(u)');
68
Maximum A Posteriori Estimation: A
Dumb Approach
Step 1: Generate EVERY possible
Codeword every possible codeword
%Generate
for i=1:2^nbits
codeword = rsc_encode([feedback; feedforward], allValidInputs(i,:), 1);
all_codewords(i,:) = reshape(codeword, 1, len);
end
Step 2: Calculate probability that transmitter sent some codeword
%For every possible codeword & ours: find out Pcodeword
for i=1:2^nbits
bitsInDiff = sum(abs(input - all_codewords(i,:)));
bitsOK = len - bitsInDiff;
%Find APP Pr{X | Y}
% X = Codeword that was transmitted
% Y = Codeword that was receieved
pcodeword(i) = pberr^bitsInDiff * (1-pberr)^bitsOK;
end
%Limited valid Tx codewords, so normalize probability to add up to 1.0
pcodeword = pcodeword ./ (sum(pcodeword));
69
MAP: A Dumb Approach
Step 3: Calculate probability for each bit in systematic input part
%Calculate individual probability of error
pSystematic = zeros(1, nbits);
for bitindex=1:nbits
psum = 0;
for i=1:2^nbits
codewords_reshaped = reshape(all_codewords(i,:), 2, len/2);
%Find probability any given bit is ZERO
if codewords_reshaped(1, bitindex) == 0
psum = psum + pcodeword(i);
end
p0Systematic(bitindex) = psum;
end
end
%Find probability any given bit is ONE
p1Systematic = 1.0 - p0Systematic;
%From P1 & P0 calculate LLR
llrs = log(p1Systematic ./ p0Systematic);
Note: this is not full code, see resources/brute_force_map.m for full listing
70
MAP: A Dumb Approach, Example
Information Bits:
1 1 1 1 1
Codeword after RSC:
1 1 1 1 1
1 0 1 1 1
0
1
1
0
0
1
1
1
1
0
0
1
0
1
1
0
1
0
*** SEND OVER CHANNEL ***
Location of errors after demodulating:
0 0 0 0 0 1 0 1 0
Result of decoding:
llrs: 4.4882 3.8149 3.5202 3.0160 1.8966
Codeword:
1 1 1
1 0 1
1
1
1
1
0
1
1
1
1
0
0
1
0
1
1
0
0.2422
0.5871 -0.2635 -2.1073
1
0
Result of Actual LOG-MAP Algorithm SISO Decoder with HARD inputs:
4.5758 3.8945 3.5978 3.0795 1.9285 0.2353 0.5767 -0.2573 -2.1352
Run example yourself: doc\resources\brute_force_test.m
71
MAP: A Smart Approach: BCJR
Citations in IEEE Xplore for BCJR Paper
250
200
Axis Title
150
100
50
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
0
Optimal Decoding of Linear Codes for minimizing symbol error rate
Bahl, L.; Cocke, J.; Jelinek, F.; Raviv, J.;
72
Soft Input Soft Output (SISO)
Normal input to decoder
from demodulator (hardinput)
73
Soft Input Soft Output (SISO)
Here is my best guess about the data
a priori probability information
SISO
Here is my best guess about the data
a posteriori probability information
74
MAP: HISO vs SISO
Information to Send
1
1
1
1
1
0
Demodulated Signal (input to SISO):
0.0498 3.1128 2.3742 3.5604 3.3145
Hard Limited Signal (input to HISO):
+1
+1
+1
+1
+1
1
1.9150
+1
1
0
2.5781 -0.3870 -1.1380
+1
-1
-1
Result of LOG-MAP Algorithm Decoder with HARD inputs:
4.5758 3.8945 3.5978 3.0795 1.9285 0.2353 0.5767 -0.2573 -2.1352
Result of LOG-MAP Algorithm Decoder with SOFT inputs:
3.7027 3.7415 5.7940 5.8576 2.0905 -1.3506 2.6070 1.1498 -4.7725
75
EXIT Chart
Extrinsic Information Transfer (EXIT)
Output Information
I E  T ( I A , Eb / N0 )
Input Information
CATC 7.6.3 pp 259-266 & http://www.inue.uni-stuttgart.de/publications/pub_2001/tenBrink_IEEE-Trans_10-01_Convergence.pdf
TCTEASTC 16.3 pp497-500
76
Turbo Decoder Setup
Depuncturing / Reshaping
Upper
Encoder
Parity Bits
SISO
Extrinsic Information
SISO
Systematic Part
Lower Encoder Parity Bits
77
Turbo Decoder Iterations
Iteration 4
Iteration 3
Iteration 2
Iteration 1
78
EXIT Chart Notes
79
EXIT Chart Notes
80
EXIT Chart Notes
81
EXIT Chart – BER of Previous
82
EXAMPLE
83
Turbo Example
% SNR in dB to run channel at, play around
% with this to get a good number
% which uses a few turbo iterations. On my
% system this causes the code to do
% 3 iterations to correct all the errors
SNR = -7.3;
%Length of data in bits
frame_length = 9;
% The generator polynomials we are using
feedback_polynomial = [1 0 1 1]
feedforward_polynomial = [1 1 0 0]
84
Turbo Example - Polynomial
feedback_polynomial = [1 0 1 1]
feedforward_polynomial = [1 1 0 0]
1 D  D
2
3
1 D
85
Turbo Example
%Keep all tail bits
tail_pattern = [1 1 1 %Encoder
1 1 1 %Encoder
1 1 1 %Encoder
1 1 1];%Encoder
1
1
2
2
Systematic Part
Parity Part
Systemtic Part
Parity Part
%Puncture systematic part from encoder 2
pun_pattern = [ 1 1 %Encoder 1 Systematic Part
1 1 %Encoder 1 Parity Part
0 0 %Encoder 2 Systemtic Part
1 1];%Encoder 2 Parity Part
86
Turbo Example - Puncturing
87
Turbo Example
%Max number of iterations to
display
turbo_iterations = 5;
%Automatically stop when no more
errors
autostop = 1;
88
Turbo Example – Data
%% Data Generation
%Seed the random number generator so we always
%get the same random data
rand('state', 0);
randn('state', 0);
%Generate some random data
data = round( rand( 1, frame_length ) );
fprintf('Information Data = ');
fprintf('%d ', data);
fprintf('\n');
Information Data = 1 0 1 0 1 1 0 0 1
89
Turbo Example - Encoding
%% Encoding
%Make polynomial
genPoly = [feedback_polynomial; feedforward_polynomial];
%How many rows in polynomial?
[N, K] = size(genPoly);
upper_data = data;
upper_output = ConvEncode( upper_data, genPoly, 0);
%lower input data is interleaved version of upper
lower_data = interleave(data, 1);
lower_output = ConvEncode( lower_data, genPoly, 0);
% convert to matrices (each row is from one row of the
generator)
upper_reshaped = [ reshape( upper_output, N,
length(upper_output)/N ) ];
lower_reshaped = [ reshape( lower_output, N,
length(lower_output)/N ) ];
90
Turbo Example - Encoding
Upper Code Input
= 1 0 1 0 1 1 0 0 1
Upper Code Systematic = 1 0 1 0 1 1 0 0 1 1 0 1
Upper Code Parity
= 1 1 0 1 0 1 0 1 0 1 0 0
91
Turbo Example - Encoding
101011001
1
0
1
0
1
1
0
0
1
1
0
0
0
1
0
1
1
1
100010111
function [interleaved] = interleave(input, print)
input_data = reshape(input, a, a);
output_data = input_data';
interleaved = reshape(output_data, 1, length(input));
92
Turbo Example - Encoding
Lower Code Input
= 1 0 0 0 1 0 1 1 1
Lower Code Systematic = 1 0 0 0 1 0 1 1 1 1 0 1
Lower Code Parity
= 1 1 1 0 1 0 0 1 0 1 0 0
93
Turbo Example - Puncturing
% parallel concatenate
unpunctured_word = [upper_reshaped
lower_reshaped];
fprintf('\n\nUnpunctured = ');
fprintf('%d ', unpunctured_word);
fprintf('\n');
%Puncture Codeword
codeword = Puncture( unpunctured_word,
pun_pattern, tail_pattern );
fprintf('Punctured
= ');
fprintf('%d ', codeword);
fprintf('\n');
Unpunctured = 1 1 1 1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 1 1 1 1 0 0 0 0 1 0 0 1 1 1 1 0 1 0 1 1 1 1 0 0 0 0 1 0 1 0
Punctured
= 1 1 1 0 1 1 1 0 1 0 1 0 1 0 1 1 1 0 0 0 0 0 1 1 1 0 0 1 1 0 0 1 0 1 1 0 0 1 0
94
Turbo Example - Puncturing
Upper
Upper
Lower
Lower
Code
Code
Code
Code
Systematic
Parity
Systematic
Parity
=
=
=
=
1
1
1
1
0
1
0
1
1
0
0
1
0
1
0
0
1
0
1
1
1
1
0
0
0
0
1
0
0
1
1
1
1
0
1
0
1
1
1
1
0
0
0
0
1
0
1
0
Upper
Upper
Lower
Lower
Code
Code
Code
Code
Puncturing
Puncturing
Puncturing
Puncturing
=
=
=
=
1
1
0
1
1
1
0
1
1
1
0
1
1
1
0
1
1
1
0
1
1
1
0
1
1
1
0
1
1
1
0
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
Upper
Upper
Lower
Lower
Code
Code
Code
Code
Systematic
Parity
Systematic
Parity
= 1 0 1 0 1 1 0 0 1
= 1 1 0 1 0 1 0 1 0
=
= 1 1 1 0 1 0 0 1 0
1
1
1
1
0
0
0
0
1
0
1
0
Punctured = 1 1 1 0 1 1 1 0 1 0 1 0 1 0 1 1 1 0 0 0 0 0 1 1 1 0 0 1 1 0 0 1 0 1 1 0 0 1 0
95
Turbo Example - Channel
%% Modulate, Channel, and Demodulate
%Turn into +/- 1 for BPSK modulation example
tx = -2*(codeword-0.5);
%Generate AWGN of correct length
EsNo = 10^(SNR/10.0);
variance = 1/(2*EsNo);
noise = sqrt(variance)*randn(1, length(tx) );
%Add AWGN
rx = tx + noise;
%Demodulate
symbol_likelihood = -2*rx./variance;
%Stats
plot(symbol_likelihood, zeros(1, length(symbol_likelihood)),
'.')
fprintf('Received log-liklihood ratio (LLR): mean(abs(LLR)) =
%f\n', mean(abs(symbol_likelihood)));
96
Turbo Example - Channel
Sending data over AWGN channel, SNR=-7.300000
Received log-liklihood ratio (LLR): mean(abs(LLR)) =
1.229565
97
Turbo Example - Depuncturing
%% Decoding
% intialize error counter
errors = zeros( turbo_iterations, 1 );
% depuncture and split into format used in each decoder
depunctured_output = Depuncture(symbol_likelihood,
pun_pattern, tail_pattern );
input_upper_c = reshape( depunctured_output(1:N,:), 1,
N*length(depunctured_output) );
input_lower_c = reshape( depunctured_output(N+1:N+N,:), 1,
N*length(depunctured_output) );
LLR After Channel
= 1.3 2.8 0.6 -1.1 2.1 -0.7 -0.7 -0.7 0.3 -1.0 ...
LLR After Depuncturing = 1.3 2.8 0.0 0.6 -1.1 2.1 0.0 -0.7 -0.7 -0.7 ...
Upper Input = 1.3 2.8 -1.1 2.1 -0.7 -0.7 -1.0 1.0 1.5 -3.4 0.6 -0.6 ...
Lower Input = 0.0 0.6 0.0 -0.7 0.0 0.3 0.0 -1.6 0.0 0.9 0.0 -0.8 ...
98
Turbo Example – Decode Setup
% No estimate of original data
input_upper_u = zeros( 1, frame_length );
saved_outLLR =
saved_outExt =
saved_interLLR
saved_interExt
[];
[];
= [];
= [];
totalIts = 0;
traj = zeros(1,2);
figure;
axis square;
title('Turbo Decoder Trajectory');
ylabel('I_E');
xlabel('I_A');
xlim([0,1]);
ylim([0,1]);
hold on;
IA = 0;
IE = 0;
99
Turbo Example - Decoding
% Iterate over a number of times
for turbo_iter=1:turbo_iterations
fprintf( '\n*** Turbo iteration = %d\n', turbo_iter );
% Pass through upper decoder
[output_upper_u output_upper_c] = SisoDecode( input_upper_u,
input_upper_c, genPoly, 0, 0 );
% Extract Extrinsic information
ext = output_upper_u - input_upper_u;
% Interleave this information, which organizes it
% in the same manner which the lower decoder sees bits
input_lower_u = interleave(ext, 0);
100
Turbo Example - Decoding
% Pass through lower decoder
[output_lower_u output_lower_c] = SisoDecode( input_lower_u, input_lower_c,
genPoly, 0, 0 );
% Interleave and extract Extrinsic information
input_upper_u = interleave( output_lower_u - input_lower_u, 0 );
% Hard decision based on LLR: if < 0 bit is 0, if > 0 bit is 1
detected_data = (sign(interleaved_output_lower_u) + 1) / 2;
% Find errors – NOT part of turbo algorithm, since normally you don’t have
% actual data. But we do so take advantage of that to detect when to stop
error_positions = xor( detected_data, data);
if (sum(error_positions)==0) && (autostop)
break;
else
errors(turbo_iter) = temp_errors + errors(turbo_iter);
end
end
101
Turbo Example - Outputs
*** Turbo iteration = 1
Error Vector = 0 0 1 0 0 0 0 1 0
Errors = 2, mean(abs(output LLR)) = 1.796717
*** Turbo iteration = 2
Error Vector = 0 0 0 0 0 0 0 1 0
Errors = 1, mean(abs(output LLR)) = 1.810404
*** Turbo iteration = 3
Error Vector = 0 0 0 0 0 0 0 0 0
Errors = 0, mean(abs(output LLR)) = 1.879098
102
input_upper_u
Turbo Decoder - LLRs
Error Vectors for
Each Iteration
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
0
0
0
0
103
output_upper_u - input_upper_u
Turbo Decoder - Extrinsic
Error Vectors for
Each Iteration
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
0
0
0
0
104
output_upper_u - input_upper_u
Turbo Decoder - Extrinsic
Error Vectors for
Each Iteration
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
0
0
0
0
105
Turbo Example - Decoding
detected_data = reshape( detected_data', 1, frame_length);
1 0 1 0 1 1 0 0 1
106
Turbo Example - Decoding
% Combine output_c and puncture
% convert to matrices (each row is from one row of the
generator)
upper_reshaped = [ reshape( output_upper_c, N,
length(output_upper_c)/N ) ];
lower_reshaped = [ reshape( output_lower_c, N,
length(output_lower_c)/N ) ];
% parallel concatenate
unpunctured_word = [upper_reshaped
lower_reshaped];
Upper Code Output
= 1 1 0 1 1 0 0 1 1 0 1 1 0 0 0 1 1 0 1 1 0 0 1 0
Upper Code Output Systematic = 1 0 1 0 1 1 0 0 1 1 0 1
Upper Code Output Parity
= 1 1 0 1 0 1 0 1 0 1 0 0
Lower Code Output
= 1 1 0 1 0 1 0 0 1 1 0 0 1 0 1 0 1 0 0 1 0 0 1 0
Lower Code Output Systematic = 1 0 0 0 1 0 1 1 1 0 0 1
Lower Code Output Parity
= 1 1 1 0 1 0 0 0 0 1 0 0
107
Part 2 – Computer
simulations
108
Coded Modulation Library
Iterative Solutions has created an Open Source (LGPL) project to simulate
Turbo Codes.
• Key functions written in C & work on Linux, Windows, MAC from
MATLAB
• Speeds up simulation drastically compared to MATLAB-only solution
• NOTE: Comes with Documentation in documentation/CMLOverview.pdf,
see that file for more help, as I won’t repeat information in that file
http://www.iterativesolutions.com/Matlab.htm
http://code.google.com/p/iscml/
109
Downloading CML
I’ve extended CML to add:
• Bunch of examples
• Tutorial file (shows decoding step-by-step)
• Some simple additional interleavers
• Functions to find dFree and plot asymptote
• EXIT Chart Plotting & Trajectories (wouldn’t trust it
100%)
• Option to plot only specified iteration without
changing files (useful for comparisons)
110
Download CML
My version + this presentation stored in SVN on
http://www.assembla.com/code/turbocml/subversion/nodes
Or download a .zip from
http://www.newae.com/tiki-index.php?page=Turbo
111
Installing CML
1. Unzip file somewhere
2. On Windows – you are done. On other systems: Startup
MATLAB, go to cml\mex\source and run ‘make’
3. Optional for dFree calculation:
Download turbo.exe from
http://www.tlc.polito.it/garello/turbodistance/turbodistance.html , direct
link: http://www.tlc.polito.it/garello/turbodistance/turbo.exe
112
Running CML
1. cd to directory you unzipped file in
2. run command ‘startup’
>> cd E:\Documents\academic\classes\ilo2\turbocml\trunk
>> startup
>>
113
RUNNING BER SIMULATIONS
114
Running Simulations
• Simulations run with ‘CmlSimulate’ command.
Parameters for simulations stored in scenario
files
• Scenario files stored in ‘cml/localscenarios’
and ‘cml/scenarios’.
• Simulation results saved in ‘cml/output’
– You can interrupt simulation and continue it later
without loosing all the data
115
Running Simulations
>> CmlSimulate('TurboTests', [1 2 3])
Use file TurboTests.m
Run scenarios 1, 2, and 3
116
Running Simulations
>> CmlSimulate('TurboTests', [3 6])
Initializing case (3): UMTS-TC, BPSK, Rayleigh, 530 bits, max-log-MAP
Initializing case (6): UMTS-TC, BPSK, Rayleigh, 5114 bits, max-log-MAP
Record 1
UMTS-TC, BPSK, Rayleigh, 530 bits, max-log-MAP
Eb/No in dB = 1.400000 dB
Clock 13:32:26
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.
Eb/No in dB = 1.600000 dB
Clock 13:32:27
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx??? Operation terminated by user during ==> TurboDecode at 99
Hit Ctrl-C To Abort
117
Running Simulations
>> CmlSimulate('TurboTests', [3 6])
Initializing case (3): UMTS-TC, BPSK, Rayleigh, 530 bits, max-log-MAP
Initializing case (6): UMTS-TC, BPSK, Rayleigh, 5114 bits, max-log-MAP
Record 1
UMTS-TC, BPSK, Rayleigh, 530 bits, max-log-MAP
Eb/No in dB = 1.400000 dB
Clock 13:32:31
Continue Simulation – Note 1.4 dB
point already simulated and saved
Eb/No in dB = 1.600000 dB
Clock 13:32:31
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.
Eb/No in dB = 1.800000 dB
Clock 13:32:32
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxx.
Eb/No in dB = 2.000000 dB
Clock 13:32:34
xxxxxxxxxxxxx.xxxxxxxxxxxxx.xxxxxxxxxxxxxx.Simulation Complete
Clock 13:32:38
118
Running Simulations
>> CmlSimulate('TurboTests', [11])
Initializing case (11):
TC, BPSK, AWGN, 65536 bits, max-log-MAP
Record 1
TC, BPSK, AWGN, 65536 bits, max-log-MAP
‘x’ printed for
errors in frames
Eb/No in dB = 0.000000 dB
Clock 10: 3:11
xxxxxxxx.xxxxxxxx.xxxxxxxx.xxxxxxxx.xxxxxxxx.xxxxxxxx.xxxxxxxx.xxxxxxxx.xxxxxxxx.xxxxxxxx.xxxxxxxx.xxxxxxxx.xxxx.
Eb/No in dB = 0.250000 dB
Clock 10: 5: 7
xxxxxxxx.xxxxxxxx.xxxxxxxx.xxxxxxxx.xxxxxxxx.xxxxxxxx.xxxxxxxx.xxxxxxxx.xxxxxxxx.xxxxxxxx.xxxxxxxx.xxxxxxxx.xxxx.
Eb/No in dB = 0.500000 dB
Clock 10: 7: 3
.x.x.x..x..xx..x...xxx..x.x..x.xx..x.x.xx.x.xx..x.....x...x.x.xx.x.xx.xx..x..xx....x..xxx..x....x.x.x...x.....xxx.x.....x...x.x.x.x.x.......x...x.....x.x.x...xx....x.x.x.....xx.x.x..............x..x.x.x.x..x..x....x....x..
xx....x.....x..xx.x.xx.x...x.x.....x.....x..xx.x.x..x..x...x...x.
Eb/No in dB = 0.750000 dB
Clock 10:28:17
...................................................................................................................................................................................................x...............................................................x....................
..................................................................................................x...............................................................................................................................................................x..x.................
..........................................................................................................................................................................................................................................................................................
..........................................................................................................................................................................................................................................................................................
..........................................................................................................................................................................................................................................................................................
..........................................................................................................................................................................................................................................................................................
........................................................................................x....................................................x........x................................................................................................................................
......................................................................................................................................................................................x..................................................................................................
..........................................................................................................................................................................................................................................................................................
..........................................................................................................................................................................................................................................................................................
...........................................................................................................................................................................................x.............................................................................x............x
...................................................................................................................x.....................................................................................................................................x....
As you go over turbo cliff, simulation times become massive… note
0.25 dB change in SNR (this sim step isn’t done yet either)
119
Plotting Simulations
Use ‘CmlPlot’ command in same way as Simulate. You can copy
saved .mat files from another source to the proper place in
Output if you don’t do the simulations yourself. e.g.:
On command line, copy proper .mat file from server running simulation:
$ cd cml/output/TurboCodes
$ scp mwrf@c107bfs:/home/mwrf/colin/turbocml/trunk/cml/output/TurboCodes/tc65536awgn1_huge.mat .
Back in MATLAB, Plot results, we can see how Simulation is doing and decide if we
have enough data
>> CmlPlot('TurboTests', [11])
Initializing case (11):
TC, BPSK, AWGN, 65536 bits, max-log-MAP
ans =
B: []
… BUNCH MORE STUFF …
120
Plotting Simulations
Scenario File decides what type of simulation,
and thus what type of plot:
‘coded’ means Bit Error
Rate (BER) and Frame
Error Rate (FER). Only
sim type I’m using.
121
Resulting Plots
Figure 1: BER vs
Eb/No
Figure 3: FER vs
Eb/No
Figure 2: BER vs
Es/No
Figure 4: FER vs
Es/No
EbNo = EsNo./sim_param(i).rate; for this example rate= 0.2493
122
Comparing Turbo Iterations
record = 8;
sim_param(record).comment = 'TC, BPSK, AWGN, 1000 bits, max-log-MAP';
sim_param(record).SNR = 0:0.25:3.5;
sim_param(record).framesize = 1000;
sim_param(record).channel = 'awgn';
sim_param(record).decoder_type = 1;
sim_param(record).max_iterations = 16;
sim_param(record).plot_iterations = [1 5 10 16];
Plot BER for iterations 1, 5, 10, 16
123
Comparing Turbo Iterations
>> CmlPlot('TurboTests', [8], 'iter', [1 2 3])
Initializing case (8): TC, BPSK, AWGN, 1000 bits, max-log-MAP
Override scenario file, plot
iterations 1,2, and 3. Final
iteration always plotted (in
this example = 16)
124
Comparing Plots
>> CmlPlot('TurboTests', [8 11], 'iter', [16])
Use ‘iter’ override to only plot
final iteration, cleans up plot
125
Comparing Plots
• Specify ‘linetype’ in Scenario file to make
plots different
record = 8;
...
sim_param(record).linetype = 'g-';
...
record = 11;
...
sim_param(record).linetype = ‘b-';
...
126
Defining your Own Simulation: 1
• Copy/Paste block of code, increment ‘record’
number, adjust parameters. e.g.:
record = 8;
sim_param(record).comment = 'TC, BPSK,
bits, max-log-MAP';
sim_param(record).SNR = 0:0.25:3.5;
sim_param(record).framesize = 1000;
sim_param(record).channel = 'awgn';
sim_param(record).decoder_type = 1;
sim_param(record).max_iterations = 16;
sim_param(record).plot_iterations = [1
sim_param(record).linetype = 'g-';
sim_param(record).sim_type = 'coded';
sim_param(record).code_configuration =
sim_param(record).SNR_type = 'Eb/No in
sim_param(record).modulation = 'BPSK';
Continued on Next Page
AWGN, 1000
You need to change this
You should change this
Change as needed
5 10 16];
You should change this
1;
dB';
127
Defining your Own Simulation: 2
sim_param(record).mod_order = 2;
sim_param(record).bicm = 1;
sim_param(record).demod_type = 0;
sim_param(record).legend = sim_param(record).comment;
sim_param(record).code_interleaver = ...
strcat( 'CreateSRandomInterleaver(',
int2str(sim_param(record).framesize ), ', 9)' );
Interleaver is specified as
a function which gets
called, so you need to
create a string with all
the parameters that will
be required. Examples:
S-Random, S=9
strcat( 'CreateSRandomInterleaver(', int2str(sim_param(record).framesize ), ', 9)' )
S-Random, S=16
strcat( 'CreateSRandomInterleaver(', int2str(sim_param(record).framesize ), ', 16)' )
Random
strcat( 'CreateRandomInterleaver(', int2str(sim_param(record).framesize ), ‘)' )
Linear (note this has fixed parameters, need to change them if frame-size changes)
'CreateLinearInterleaver(1000, 25, 40)'
UMTS
strcat( 'CreateUmtsInterleaver(', int2str(sim_param(record).framesize ), ')' );
Continued on Next Page
128
Defining your Own Simulation: 3
% Feedback = [1011]
% Feedforward = [1111]
sim_param(record).g1 = [1 0 1 1
1 1 1 1];
sim_param(record).g2 = sim_param(record).g1;
sim_param(record).nsc_flag1 = 0;
sim_param(record).nsc_flag2 = 0;
%No puncturing
sim_param(record).pun_pattern1 = [1 1
1 1];
sim_param(record).pun_pattern2= [0 0
1 1 ];
sim_param(record).tail_pattern1 = [1 1 1
1 1 1];
sim_param(record).tail_pattern2 = ...
sim_param(record).tail_pattern1;
Continued on Next Page
Polynomial order for
RSC:
[ Feedback
Feedforward]]
Puncturing pattern
specified in:
[ Systematic Part
Codeword Part]
Pattern needs to be long
enough to show pattern,
see examples next page
129
Defining your Own Simulation: 4
%No puncturing
sim_param(record).pun_pattern1 = [1 1
1 1];
sim_param(record).pun_pattern2= [0 0
1 1 ];
sim_param(record).tail_pattern1 = [1 1 1
1 1 1];
sim_param(record).tail_pattern2 = ...
sim_param(record).tail_pattern1;
%Rate = 1/2 Puncturing
sim_param(record).pun_pattern1 = [1 1
0 1];
sim_param(record).pun_pattern2= [0 0
1 0 ];
sim_param(record).tail_pattern1 = [1 1 1
1 1 1];
sim_param(record).tail_pattern2 = ...
sim_param(record).tail_pattern1;
Continued on Next Page
130
Defining your Own Simulation: 5
THIS IS CRITICAL: Must have unique filename for each record,
or records will share data. Here it autogenerates filename based on
some parameters, but if you are lazy add a strcat() of int2str(record)
to ensure filename for each record # is unique, which I have done
here. Save this file to save your simulation results.
sim_param(record).filename = strcat( data_directory, ...
strcat(int2str(record), 'umts', ...
int2str(sim_param(record).framesize ), ...
sim_param(record).channel, ...
int2str( sim_param(record).decoder_type ), '.mat') );
sim_param(record).reset = 0;
sim_param(record).max_trials = 1e9*ones(...
size(sim_param(record).SNR) );
sim_param(record).minBER = 1e-8;
sim_param(record).max_frame_errors = 100* ... ones( 1,
length(sim_param(record).SNR) );
sim_param(record).save_rate = ...
ceil(511400/sim_param(record).framesize);
Continued on Next Page
Set to ‘1’ to force
simulation to run
again, and not used
previously saved
results
See
CMLOverview.pdf
slide 17
131
Defining your Own Simulation: 6
Number of trajectories to
plot on EXIT chart, set to
‘0’ for none
sim_param(record).exit_trajectories = 5;
sim_param(record).exit_nframes = 100;
sim_param(record).exit_iterations = 20;
sim_param(record).exit_snr = -4:2:0;
SNR in dB to plot EXIT
charts over. Creates one
chart for each point, so
don’t make too many! This
example plots three: -4 dB,
-2 dB, and 0 dB.
Number of frames for each
Ia point. If you have short
frames set this higher
(>1000), if you have very
long frames can set this
much shorter.
Number of iterations to plot
trajectory over
132
Changing Simulation Parameters
• Some simulation parameters you
can change without needing to
reset simulation:
SNR
filename
comment
legend
linetype
plot_iterations
save_rate
reset
max_trials
minBER
minFER
max_frame_errors
compiled_mode
input_filename
trial_size
scenarios
exit_trajectories
exit_iterations
exit_snr
exit_nframes
NB: Reset = Throw away all previously simulated results. When changing above
parameters previously simulated results can be integrated into new simulated
data
133
Changing Simulation Parameters
• The rest you need to reset simulation by setting
‘reset=1’ in the record , otherwise you get a
mismatch since some data was simulated with
potentially different data (be sure to set reset
back to 0 once done)
e.g.:
CML is not impressed.
>> CmlPlot('TurboTests', [9])
Initializing case (9): TC, BPSK, AWGN, 1000 bits, max-log-MAP
Warning: field pun_pattern2 does not match stored value, using stored value
>> CmlSimulate('TurboTests', [9])
Initializing case (9): TC, BPSK, AWGN, 1000 bits, max-log-MAP
Warning: field pun_pattern2 does not match stored value, using stored value
134
EXIT CHARTS
135
EXIT Chart Plotting
Actual Trajectories
Theoretical
>> CmlPlotExit('TurboTests', [11])
NOTE: This function doesn’t save any state, so save your figures if
they took a while to calculate!
136
EXIT Chart Plotting
I’m not too confident on EXIT chart accuracy. TurboTests scenario
number 13 should match figure 10.13 of TATC, but it doesn’t.
137
FREE DISTANCE
138
Free Distance Calculation
• Free distance calculation done by Roberto Garello’s
program/algorithm from
http://www.tlc.polito.it/garello/turbodistance/turbodistance.html
• You must be in freeDistance directory
• Simply call a single scenario you’d like analyzed like:
>> cd turboUtils\freeDistance
>>[dfree, Nfree, wfree] = CmlFindDfree('UmtsScenarios', [1])
Initializing case (1): UMTS-TC, BPSK, AWGN, 40 bits, max-log-MAP
Calling Garellos turbo program, this step could take a while
dfree =
12
Nfree =
2
wfree =
8
139
Free Distance Spectrum
• You do this manually by looking at output file
out.txt in directory
• Function printBERContribution can be used to
plot free distance asymptote (see earlier
examples)
140
Fin
Did you find this helpful? Find errors? Please let me know at coflynn@dal.ca or
visit www.newae.com for more.
141
Review Questions
142
Q1: Plotting
• Run a simulation with a R=1/2 Turbo Code,
SRandom Interleaver with S=9, Interleaver
length=512
• Plot iterations 1-10 over SNR of 0-3dB.
• Also plot the improvement in SNR for each
iteration for a BER of ~10E-5 (if possible)
 g 2 ( D)   1  D  D 3  D 4 
G  1
  1

3
4
g
(
D
)
1

D

D


1
 
143
Q1: Plotting
Hint #1: Polynomials are:
feedback = [1 0 0 1 1]
feedforward = [1 1 0 1 1]
Hint #2: R=1/2 implies we are puncturing half the parity
bits. See slide in this presentation entitled “Defining
Your Own Simulation: 4”.
Hint #3: There is no function for plotting the SNR
improvement, you’ll need to read off graph (consider
using MATLAB data-point picker here).
144
Q2: SISO Decoding
• The brute force MAP example used hard inputs. Can you
extend that to work on soft-input decoding?
– Hint #1: The code already outputs the true soft-input LOG-MAP
algorithm, which should match your results
– Hint #2: Doing so will require calculating probability of bit in
error (pberr) for each input bit. Remember for hard-input we
are only told if result of demodulating was >0 or <0, which we
use with Q function to give probability bit with original value +/1 was thrown over zero. For soft-input we are given actual result
of demodulation, so instead need to find probability bit was
thrown from +/- 1 to that value instead of zero.
– Hint #3: The easiest way to do the above will be to consider the
output of the demodulator as LLRs. You can find a formula in the
references to convert from LLR to Pb(0) and Pb(1).
145
Q3: Free Distance
• I have an idea for an interleaver which maps
like this for a 1000-bit input:
0
1
2
3
4
..
..
24
25
26
27
28
29
..
..
49
50
51
52
40 Rows
74
75
25 Columns
146
Q3: Continued
That is, the interleaver vector would look like:
[0 25 1 50 26 2 75 51 … 999]
147
Q3: Continued
1. Plot the free distance asymptote for a rate 1/3
code compared to normal linear & S-Random
interleavers. You can use TurboTests.m
scenario 9 as a starting point (and the
comparison).
2. Also plot the visualization of the interleaver
to understand the performance
148
ANSWERS TO QUESTIONS
(CHEATER)
149
Question Answer Scenario
NB: I highly suggest trying to answer them on
your own first! But the scenario file, which
parts of are copied here, is in
localscenarios/TurboReviewAnswers.m .
150
Question 1: Setup
% Question 1
% Run a simulation with a R=1/2 Turbo Code, SRandom Interleaver with S=9, Interleaver
length=512
% Plot iterations 1-10 over SNR of 0-3dB.
% Also plot the improvement in SNR for each iteration for a BER of ~10E-5.
record = 1;
sim_param(record).comment = 'Review Question 1';
sim_param(record).SNR = 0:.2:3;
sim_param(record).framesize = 512;
sim_param(record).channel = 'AWGN';
sim_param(record).decoder_type = 1;
sim_param(record).max_iterations = 10;
sim_param(record).plot_iterations = [1:sim_param(record).max_iterations];
sim_param(record).linetype = 'r-';
sim_param(record).sim_type = 'coded';
sim_param(record).code_configuration = 1;
sim_param(record).SNR_type = 'Eb/No in dB';
sim_param(record).modulation = 'BPSK';
sim_param(record).mod_order = 2;
sim_param(record).bicm = 1;
sim_param(record).demod_type = 0;
sim_param(record).legend = sim_param(record).comment;
sim_param(record).code_interleaver = ...
strcat( 'CreateSRandomInterleaver(', int2str(sim_param(record).framesize ), ', 9)'151
);
Question 1: Setup Continued
%From question slide:
% d1(D)=1+D^2+D^3 <= Feedback = [1011]
% d2(D)=1+D+D^3+D^4 <= Feedforward = [1111]
sim_param(record).g1 = [1 0 1 1
1 1 1 1];
sim_param(record).g2 = sim_param(record).g1;
sim_param(record).nsc_flag1 = 0;
sim_param(record).nsc_flag2 = 0;
sim_param(record).pun_pattern1 = [1 1
0 1];
sim_param(record).pun_pattern2= [0 0
1 0 ];
sim_param(record).tail_pattern1 = [1 1 1
1 1 1];
sim_param(record).tail_pattern2 = sim_param(record).tail_pattern1;
sim_param(record).filename = strcat( data_directory, ...
strcat( 'q1', int2str(sim_param(record).framesize ), sim_param(record).channel,
int2str( sim_param(record).decoder_type ), '.mat') );
sim_param(record).reset = 0;
sim_param(record).max_trials = 1e9*ones(size(sim_param(record).SNR) );
sim_param(record).minBER = 1e-6;
sim_param(record).max_frame_errors = 200*ones( 1, length(sim_param(record).SNR) );
sim_param(record).save_rate = ceil(511400/sim_param(record).framesize);
152
Question 1: Running Commands
>> CmlSimulate('TurboReviewAnswers', [1])
Initializing case (1): Review Question 1
Record 1
Review Question 1
…..
>> CmlPlot('TurboReviewAnswers', [1])
153
Question 1: BER Results
154
Question 2: SISO Decoder
NB: Files located in
doc/resources/question_answers/q2_softbrute
1. Output of demodulator is used as input LLR
2. Convert LLR to probability of error for each
bit
3. Use that probability in calculation of
probability of word in error
4. Rest of file is same as in the hard input
155
Code Clips
%Demodulate
rx_demodulated = -2*rx./variance;
%Chop into binary
received = (sign(rx_demodulated) + 1)/2;
%% Do MAP Algorithm
fprintf('Result of decoding:\n');
[llrs, resultingCodeword] = brute_force_map_soft(feedback,
feedforward, received, rx_demodulated, nbits)
156
Code Clips
%Convert input LLR into pberr, this equation is:
%D = exp(-LLR/2) / (1+exp(-LLR);
%P1 = D * exp(LLR/2)
%P0 = D * exp(-LLR/2)
%Error will be minimum of those two
pberr = zeros(1,nbits);
for i=1:length(llr_input)
D = exp(-llr_input(i)/2) / (1+exp(-llr_input(i)));
pberr(i) = min([D*exp(llr_input(i)/2) D*exp(llr_input(i)/2) ]);
end
157
%For every possible codeword & ours: find out Pcodeword
for i=1:2^nbits
%Generates an error vector indicating which bits are different
%between received codeword & codeword we are testing against
bitsInDiff = abs(input - all_codewords(i,:));
%Generates a vector with only the probabilities of bits in error
pbErrVect = bitsInDiff .* pberr;
%Get non-zero elements, multiple together, this works on previous
%operation which got only probabilities of bits we care about
pbCodeError = prod(pbErrVect(find(pbErrVect)));
%Do same
%though
bitsSame
pbOkVect
pbCodeOk
steps as above, I haven't duplicate the documentation
= 1-bitsInDiff;
= bitsSame .* (1-pberr);
= prod(pbOkVect(find(pbOkVect)));
%Find APP Pr{X
% X = Codeword
% Y = Codeword
pcodeword(i) =
| Y}
that was transmitted
that was receieved
pbCodeError * pbCodeOk;
end
158
Q3: Fancy (or not?) Interleaver
function [output] = q3_interleaver(rows, cols)
linput = rows*cols;
input = [0:linput-1];
output = zeros(1,length(input));
input = reshape(input, cols, rows)';
j = 1;
for startingrow=1:rows;
%Start at left point in each row...
col = 1;
row = startingrow;
while row > 0 && col <= cols
output(j) = input(row,col);
col = col+1;
row = row-1;
j = 1+j;
end
end
for startingcol=2:cols;
%Do bottom row all way along
col = startingcol;
row = rows;
while row > 0 && col <= cols
output(j) = input(row,col);
col = col+1;
row = row-1;
j = 1+j;
end
end
159
Q3: Fancy (or not?) Interleaver
record = 2;
% Copy everything from our reference
sim_param(record) = sim_param(9);
sim_param(record).code_interleaver = ...
strcat( 'q3_interleaver(25, 40)' );
Assuming record 9 is setup using Linear, and 10 is using SRandom, and you are in
directory with q3_interleaver.m:
>> [df1, nf1, wf1] = CmlFinddFree('TurboReviewAnswers ', [2])
>> [df2, nf2, wf2] = CmlFinddFree('TurboReviewAnswers', [9])
>> [df3, nf3, wf3] = CmlFinddFree('TurboReviewAnswers', [10])
>> printBERContribution( df1, nf1, wf1, 1000, 1/3 )
>> hold on
>> printBERContribution( df2, nf2, wf2, 1000, 1/3 )
>> printBERContribution( df3, nf3, wf3, 1000, 1/3 )
160
Q3 Results: Not Very Good
161
Q3 Results: Not Very Good
162
Download