Skip to content

Commit 57af767

Browse files
authored
Merge pull request #9 from erseghe/master
Add files via upload
2 parents b46c14f + 4d3761b commit 57af767

File tree

5 files changed

+145
-66
lines changed

5 files changed

+145
-66
lines changed

bi-awgn/converse_mc.m

Lines changed: 121 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323
% region where 'On2' is a reliable solution, namely the
2424
% region where 'On2' and 'On3' closely match.
2525
%
26-
% 'full' - (this option will be available soon) the full bound derived
27-
% numerically from [1].
26+
% 'full' - the full bound derived numerically as from [2].
27+
% Be aware this is very slow to compute! It is also
28+
% numerically less reliable where On2 and On3 closely agree.
2829
%
2930
% SNRdB = converse_mc(N, Pe, R, 'approx','error') for a codeword of length
3031
% N, and code rate R, the function returns the SNR (in dB) at which the
@@ -36,9 +37,14 @@
3637
% All bounds were derived from:
3738
% [1] T. Erseghe, "Coding in the Finite-Blocklength Regime: Bounds
3839
% based on Laplace Integrals and their Asymptotic Approximations",
40+
% IEEE Transactions on Information Theory, 62(12), pp 6854-6883, 2016
3941
% http://arxiv.org/abs/1511.04629
42+
% [2] T. Erseghe, N. Laurenti, M. Zecchin, "Coding Bounds in the
43+
% Finite-Block-Length Regime: an Application to Spread-Spectrum
44+
% Systems Design,"
45+
% 2019 AEIT International Annual Conference.
4046
%
41-
% Please give credits to [1] if you use this code for your research.
47+
% Please give credits to [1] & [2] if you use this code for your research.
4248
%
4349
% PS1: The function is implemented in MATLAB R2017a and extensively uses
4450
% the 'fmincon' solver. Different MATLAB versions may require some
@@ -48,7 +54,7 @@
4854
% the code fails on a particular choice of parameters, please drop an
4955
% email to [email protected] and I will try to fix the bug.
5056
%
51-
% (c) T. Erseghe 2016
57+
% (c) T. Erseghe 2020
5258
%
5359

5460
warning ('off','all');
@@ -82,12 +88,6 @@
8288
error(['Wrong input ',x4])
8389
end
8490

85-
% override 'full' option which is not available at the moment
86-
if strcmp(x3,'full')
87-
disp('Sorry, the "full" option is not available... switching to "On2" approximation')
88-
x3 = 'On2';
89-
end
90-
9191

9292
% optimization settings
9393
options1 = optimoptions('fmincon',...
@@ -124,6 +124,16 @@
124124
pe = Pe(k); % packet error probability
125125
qe = Qe(k); % Q^(-1)(pe)
126126
om = 10^(x2(k)/10); % snr value
127+
128+
% define the saddle point starting point
129+
if ~((n==inf)||strcmp(x3,'normal'))
130+
if (k>2)&&(~isnan(y(k-2)))&&(~isnan(sb))
131+
sb0 = sb;
132+
else
133+
[~, ~, V] = fun_HP(om,0);
134+
sb0 = -qe/sqrt(V*n);
135+
end
136+
end
127137

128138
try
129139
if (n==inf)||strcmp(x3,'normal')
@@ -132,9 +142,6 @@
132142

133143
elseif strcmp(x3,'On2')
134144
% case 2: O(n^-2) approximation
135-
% define the saddle point starting point
136-
[~, ~, V] = fun_HP(om,0);
137-
sb0 = -qe/sqrt(V*n);
138145
% find saddle point
139146
sb = fmincon(@(x)zero_obj(x),sb0,[],[],[],[],[],[],...
140147
@(x)constr_om_on2_rate(x,om,pe,n),options2);
@@ -143,17 +150,19 @@
143150

144151
elseif strcmp(x3,'On3')
145152
% case 3: O(n^-2) approximation
146-
% define the saddle point starting point
147-
[~, ~, V] = fun_HP(om,0);
148-
sb0 = -qe/sqrt(V*n);
149153
% find saddle point
150154
sb = fmincon(@(x)zero_obj(x),sb0,[],[],[],[],[],[],...
151155
@(x)constr_om_on3_rate(x,om,pe,n),options2);
152156
% calculate rate value
153157
y(k) = -logFA_on3(sb,om,n)/log(2);
154158

155159
elseif strcmp(x3,'full')
156-
% case 4: full bound (numerical)
160+
% case 4: full bound (numerical)
161+
% find saddle point
162+
sb = fmincon(@(x)zero_obj(x),sb0,[],[],[],[],[],[],...
163+
@(x)constr_om_full_rate(x,om,pe,n),options2);
164+
% calculate rate value
165+
y(k) = -logFA_full(sb,om,n)/log(2)/n;
157166

158167
end
159168

@@ -192,10 +201,20 @@
192201
% define the SNR starting point
193202
if k==1
194203
om0 = 1;
204+
[~, ~, V] = fun_HP(om0,0);
205+
sb0 = -qe/sqrt(V*n);
195206
elseif ~isnan(y(k-1)) % use previous value
196207
om0 = y(k-1);
197208
end
198-
209+
if ~((n==inf)||strcmp(x3,'normal'))
210+
if (k>2)&&(~isnan(y(k-2)))&&(~isnan(x(1)))
211+
sb0 = x(1);
212+
else
213+
[~, ~, V] = fun_HP(om0,0);
214+
sb0 = -qe/sqrt(V*n);
215+
end
216+
end
217+
199218
try
200219
if (n==inf)||strcmp(x3,'normal')
201220
% case 1: normal approximation
@@ -205,9 +224,6 @@
205224

206225
elseif strcmp(x3,'On2')
207226
% case 2: O(n^-2) approximation
208-
% define the saddle point starting point
209-
[~, ~, V] = fun_HP(om0,0);
210-
sb0 = -qe/sqrt(V*n);
211227
% check that if starting point is feasible
212228
[~, con] = constr_om_on2_error([sb0; om0],R,pe,n);
213229
% find SNR/saddle point
@@ -217,9 +233,6 @@
217233

218234
elseif strcmp(x3,'On3')
219235
% case 3: O(n^-3) approximation
220-
% define the saddle point starting point
221-
[~, ~, V] = fun_HP(om0,0);
222-
sb0 = -qe/sqrt(V*n);
223236
% check if the starting point is feasible
224237
[~, con] = constr_om_on3_error([sb0; om0],R,pe,n);
225238
% find SNR/saddle point
@@ -229,7 +242,13 @@
229242

230243
elseif strcmp(x3,'full')
231244
% case 4: full bound (numerical)
232-
245+
% check if the starting point is feasible
246+
[~, con] = constr_om_full_error([sb0; om0],R,pe,n);
247+
% find SNR/saddle point
248+
x = fmincon(@(x)zero_obj(x),[sb0; om0],[],[],[],[],[],[],...
249+
@(x)constr_om_full_error(x,R,pe,n),options2);
250+
y(k) = x(2);
251+
233252
end
234253

235254
% something did not work !
@@ -306,14 +325,6 @@
306325
R = C - qe*log2(exp(1))*sqrt(V/n) + log2(n)/2/n; % rate
307326
end
308327

309-
% constraints for calculating the error rate bound under the normal
310-
% approximation
311-
function [c ceq gradc gradceq] = constr_om_normal(x,R,qe,n)
312-
c = [];
313-
gradc = [];
314-
ceq = [rate_normal(n,x,qe)-R];
315-
gradceq = []; % too long to derive !!!
316-
317328
% log(FA) function under the O(n^-2) approximation
318329
function y = logFA_on2(sb,om,n)
319330
sa = sb+1;
@@ -325,6 +336,66 @@
325336
[Hp, la, a2] = fun_HP(om,sb);
326337
y = la.*sb + log(Hp) -log(2*pi*n*sb.^2.*a2)/2/n;
327338

339+
% log(FA) function under the O(n^-3) approximation
340+
function y = logFA_on3(sb,om,n)
341+
sa = sb+1;
342+
[Hp, la, a2, a3, a4] = fun_HP(om,sb);
343+
y = la*sa + log(Hp/2)-log(2*pi*n*sa^2*a2)/2/n;
344+
g = (12*a2.*a4-15*a3.^2)./a2.^3/8 - 3*a3./(2*sa.*a2.^2)-1./(a2.*sa.^2);
345+
y = y + log(1+g/n)/n;
346+
347+
% log(MD) function under the O(n^-3) approximation
348+
function y = logMD_on3(sb,om,n)
349+
[Hp, la, a2, a3, a4] = fun_HP(om,sb);
350+
y = la.*sb + log(Hp) -log(2*pi*n*sb.^2.*a2)/2/n;
351+
g = (12*a2.*a4-15*a3.^2)./a2.^3/8 - 3*a3./(2*sb.*a2.^2)-1./(a2.*sb.^2);
352+
y = y + log(1+g/n)/n;
353+
354+
% log(FA) function under the full approximation
355+
function y = logFA_full(sb,om,n)
356+
[~, la, a2, a3] = fun_HP(om,sb);
357+
% integration path
358+
t0 = 1; % this is set heuristically
359+
pb = @(t) sb + 1i*t/sqrt(a2) + a3*((t<=t0).*t.^2+(t>t0)*t0^2)/(2*a2^2);
360+
pb1 = @(t) 1i/sqrt(a2) + a3*(t<=t0).*t/(a2^2);
361+
% integrals
362+
h = @(x) log(1+exp(-2*x));
363+
I1 = 40;
364+
H = @(s) (1/sqrt(2*pi*om))*quadl(@(x)exp((-1/(2*om))*(x-om).^2-s*h(x)),-I1,I1);
365+
Beta = @(s) 2*(la*s+log(H(s)));
366+
Alpha = @(s) Beta(s-1)-2*log(2)+2*la;
367+
I = 40; % this is set heuristically
368+
tol = 1e-12; % tolerance for integrations
369+
y = integral(@(u)imag(exp(Alpha(pb(u)+1)*n/2).*pb1(u)./(1+pb(u)))/pi,0,I,'AbsTol',tol,'ArrayValued',true);
370+
y = y + 1.0*(sb<-1.0) + 0.5*(sb==-1.0);
371+
y = log(y);
372+
373+
% log(MD) function under the full approximation
374+
function y = logMD_full(sb,om,n)
375+
[~, la, a2, a3] = fun_HP(om,sb);
376+
% integration path
377+
t0 = 1; % this is set heuristically
378+
pb = @(t) sb + 1i*t/sqrt(a2) + a3*((t<=t0).*t.^2+(t>t0)*t0^2)/(2*a2^2);
379+
pb1 = @(t) 1i/sqrt(a2) + a3*(t<=t0).*t/(a2^2);
380+
% integrals
381+
h = @(x) log(1+exp(-2*x));
382+
I1 = 40;
383+
H = @(s) (1/sqrt(2*pi*om))*quadl(@(x)exp((-1/(2*om))*(x-om).^2-s*h(x)),-I1,I1);
384+
Beta = @(s) 2*(la*s+log(H(s)));
385+
I = 40; % this is set heuristically
386+
tol = 1e-12; % tolerance for integrations
387+
y = integral(@(u)imag(exp(Beta(pb(u))*n/2).*pb1(u)./(-pb(u)))/pi,0,I,'AbsTol',tol,'ArrayValued',true);
388+
y = y + 1.0*(sb>0.0) + 0.5*(sb==0.0);
389+
y = log(y);
390+
391+
% constraints for calculating the error rate bound under the normal
392+
% approximation
393+
function [c ceq gradc gradceq] = constr_om_normal(x,R,qe,n)
394+
c = [];
395+
gradc = [];
396+
ceq = [rate_normal(n,x,qe)-R];
397+
gradceq = []; % too long to derive !!!
398+
328399
% constraints for calculating the code rate bound under the O(n^-2)
329400
% approximation
330401
function [c ceq gradc gradceq] = constr_om_on2_rate(sb,om,Pe,n)
@@ -342,21 +413,6 @@
342413
logFA_on2(x(1),x(2),n)+R*log(2)];
343414
gradceq = []; % too long to derive !!!
344415

345-
% log(FA) function under the O(n^-3) approximation
346-
function y = logFA_on3(sb,om,n)
347-
sa = sb+1;
348-
[Hp, la, a2, a3, a4] = fun_HP(om,sb);
349-
y = la*sa + log(Hp/2)-log(2*pi*n*sa^2*a2)/2/n;
350-
g = (12*a2.*a4-15*a3.^2)./a2.^3/8 - 3*a3./(2*sa.*a2.^2)-1./(a2.*sa.^2);
351-
y = y + log(1+g/n)/n;
352-
353-
% log(MD) function under the O(n^-3) approximation
354-
function y = logMD_on3(sb,om,n)
355-
[Hp, la, a2, a3, a4] = fun_HP(om,sb);
356-
y = la.*sb + log(Hp) -log(2*pi*n*sb.^2.*a2)/2/n;
357-
g = (12*a2.*a4-15*a3.^2)./a2.^3/8 - 3*a3./(2*sb.*a2.^2)-1./(a2.*sb.^2);
358-
y = y + log(1+g/n)/n;
359-
360416
% constraints for calculating the code rate bound under the O(n^-3)
361417
% approximation
362418
function [c ceq gradc gradceq] = constr_om_on3_rate(sb,om,Pe,n)
@@ -373,3 +429,20 @@
373429
ceq = [logMD_on3(x(1),x(2),n)-log(Pe)/n; ...
374430
logFA_on3(x(1),x(2),n)+R*log(2)];
375431
gradceq = []; % too long to derive !!!
432+
433+
% constraints for calculating the code rate bound under the full
434+
% approximation
435+
function [c ceq gradc gradceq] = constr_om_full_rate(sb,om,Pe,n)
436+
c = [];
437+
gradc = [];
438+
ceq = [logMD_full(sb,om,n)-log(Pe)];
439+
gradceq = []; % too long to derive !!!
440+
441+
% constraints for calculating the error rate bound under the full
442+
% approximation
443+
function [c ceq gradc gradceq] = constr_om_full_error(x,R,Pe,n)
444+
c = [];
445+
gradc = [];
446+
ceq = [logMD_full(x(1),x(2),n)-log(Pe); ...
447+
logFA_full(x(1),x(2),n)+n*R*log(2)];
448+
gradceq = []; % too long to derive !!!

bi-awgn/example_per.m

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
% PACKET ERROR RATE BOUNDS - LOWER BOUNDS ON ERROR RATE
22

3-
if(1) % set to (1) if you wish to run the converse_mc function
3+
if(0) % set to (1) if you wish to run the converse_mc function
44

55
n = 1e3;
66
R = 1/2;
77
Pev = 10.^([-0.5:-0.25:-1.75,-2:-0.5:-7]);
88
uno = ones(size(Pev));
99

10-
% normal approximation - expected execution time 4 sec
10+
% expected execution times evaluated on a MacBook Pro
11+
% normal approximation - expected execution time 2 sec
1112
tic; SNRdBNA = converse_mc(n*uno,Pev,R*uno,'normal','error'); toc
12-
% O(n^-2) approximation - expected execution time 40 sec
13-
tic; SNRdBPPV = converse_mc(n*uno,Pev,R*uno,'On2','error'); toc
14-
% O(n^-3) approximation - expected execution time 80 sec
15-
tic; SNRdBPPVb = converse_mc(n*uno,Pev,R*uno,'On3','error'); toc
13+
% O(n^-2) approximation - expected execution time 20 sec
14+
tic; SNRdBPPV2 = converse_mc(n*uno,Pev,R*uno,'On2','error'); toc
15+
% O(n^-3) approximation - expected execution time 50 sec
16+
tic; SNRdBPPV3 = converse_mc(n*uno,Pev,R*uno,'On3','error'); toc
17+
% full approximation - expected execution time 40 min
18+
tic; SNRdBPPV = converse_mc(n*uno,Pev,R*uno,'full','error'); toc
1619

1720
% save('example_per.mat')
1821
else
@@ -23,11 +26,11 @@
2326
close all
2427
figure(1)
2528
set(0,'defaulttextinterpreter','latex')
26-
semilogy(SNRdBPPV,Pev,'-',SNRdBPPVb,Pev,'--',SNRdBNA,Pev,'-.')
29+
semilogy(SNRdBPPV3,Pev,'-.',SNRdBPPV,Pev,'-',SNRdBPPV2,Pev,'--',SNRdBNA,Pev,'-.x')
2730
xlabel('SNR $E_b/N_0$')
28-
ylabel('error probability $P_e$')
31+
ylabel('packet error probability $P_e$')
2932
title(['n = ' num2str(n) ', R = ', num2str(R)])
3033
legend({},'interpreter','latex')
31-
legend('$O(n^{-2}\,)$ approx $\quad$','$O(n^{-3}\,)$ approx',...
34+
legend('$O(n^{-3}\,)$ approx','full approx','$O(n^{-2}\,)$ approx $\quad$',...
3235
'normal approx','Location','Best')
3336
grid

bi-awgn/example_per.mat

623 KB
Binary file not shown.

bi-awgn/example_speff.m

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
% SPECTRAL EFFICIENCY CURVES - UPPER BOUNDS ON RATE
22

3-
if(1) % set to (1) if you wish to run the converse_mc function
3+
if(0) % set to (1) if you wish to run the converse_mc function
44

55
n = 1e3;
66
Pe = 1e-5;
7-
SNRdB = -15:10;
7+
SNRdB = -15:7;
88
uno = ones(size(SNRdB));tic
99

1010
% normal approximation - expected execution time 0.5 sec
1111
tic; rhoNA = 2*converse_mc(n*uno,Pe*uno,SNRdB,'normal'); % spectral efficiency
1212
EbN0NA = SNRdB-10*log10(rhoNA); toc
13-
% O(n^-2) approximation - expected execution time 20 sec
14-
tic; rhoPPV = 2*converse_mc(n*uno,Pe*uno,SNRdB,'On2'); % spectral efficiency
13+
% O(n^-2) approximation - expected execution time 10 sec
14+
tic; rhoPPV2 = 2*converse_mc(n*uno,Pe*uno,SNRdB,'On2'); % spectral efficiency
15+
EbN0PPV2 = SNRdB-10*log10(rhoPPV2); toc
16+
% O(n^-3) approximation - expected execution time 20 sec
17+
tic; rhoPPV3 = 2*converse_mc(n*uno,Pe*uno,SNRdB,'On3'); % spectral efficiency
18+
EbN0PPV3 = SNRdB-10*log10(rhoPPV3); toc
19+
% full approximation - expected execution time 10 min
20+
tic; rhoPPV = 2*converse_mc(n*uno,Pe*uno,SNRdB,'full'); % spectral efficiency
1521
EbN0PPV = SNRdB-10*log10(rhoPPV); toc
16-
% O(n^-3) approximation - expected execution time 40 sec
17-
tic; rhoPPVb = 2*converse_mc(n*uno,Pe*uno,SNRdB,'On3'); % spectral efficiency
18-
EbN0PPVb = SNRdB-10*log10(rhoPPVb); toc
1922

2023
% save('example_speff.mat')
2124
else
@@ -26,11 +29,11 @@
2629
close all
2730
figure(1)
2831
set(0,'defaulttextinterpreter','latex')
29-
semilogy(EbN0PPV,rhoPPV,'-',EbN0PPVb,rhoPPVb,'--',EbN0NA,rhoNA,'-.')
32+
semilogy(EbN0PPV3,rhoPPV3,'--', EbN0PPV,rhoPPV,'-',EbN0PPV2,rhoPPV2,'--',EbN0NA,rhoNA,'-.x')
3033
xlabel('SNR $E_b/N_0$')
3134
ylabel('spectral efficiency $\rho$ [bit/s/Hz]')
3235
title(['n = ' num2str(n) ', Pe = ', num2str(Pe)])
3336
legend({},'interpreter','latex')
34-
legend('$O(n^{-2}\,)$ approx $\quad$','$O(n^{-3}\,)$ approx',...
37+
legend('$O(n^{-3}\,)$ approx $\quad$','full approx','$O(n^{-2}\,)$ approx',...
3538
'normal approx','Location','Best')
3639
grid

bi-awgn/example_speff.mat

626 KB
Binary file not shown.

0 commit comments

Comments
 (0)