-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathunion_bound.m
61 lines (53 loc) · 1.44 KB
/
union_bound.m
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
% File: WeightDistribution.m
% Description: Compute the weight distrubution of a linear code given its
% generator matrix and the union bound on its performance
% with BPSK modulation over an AWGN channel.
% Copyright (c) 2006. Robert Morelos-Zaragoza. All rights reserved.
clear all
%n=10; % Code length
n=8; % Code length
k=4; % Code dimension
% Generator matrix, k=4, n=10
% G = [ 1 1 0 1 0 0 0 0 0 0
% 0 0 1 1 0 1 0 0 0 0
% 0 0 0 0 1 1 0 1 0 0
% 0 0 0 0 0 0 1 1 0 1 ];
% G = [ 1 1 0 1 0 0 0 0
% 0 0 1 1 0 1 0 0
% 0 0 0 0 1 1 0 1
% 0 0 0 0 0 0 1 1 ];
G = [ 1 1 0 1 0 0 0 0
0 0 1 1 0 1 0 0
0 0 0 0 1 1 0 1
0 1 0 0 0 0 1 1 ];
% Weight distribution W(C):
W = zeros(1,n+1);
W(1)=1;
% Generate all combinations of message vectors and their weigths
k2=2^k-1;
for i=1:k2
u = dec2bin(i,k);
v = mod(u*G,2);
W(sum(v)+1) = W(sum(v)+1)+1;
end
% Print the weight distribution
fprintf('W(C)={1');
for i=2:n+1
fprintf(',%d',W(i))
end
fprintf('}\n');
% Compute the union bound
EbNo = 0:0.5:9.5;
EbNoratio = 10.^(EbNo/10);
bound = 0;
for i=1:n
bound = bound + i*W(i+1)/n * qfunc(sqrt(2*i*(k/n)*EbNoratio));
end
% semilogy(EbNo,bound,'-o')
semilogy(EbNo,bound,'-s')
axis tight
grid on
xlabel('E_b/N_0 (dB)')
ylabel('P_b')
hold on
semilogy(EbNo, qfunc(sqrt(2*EbNoratio)))