|
23 | 23 | % region where 'On2' is a reliable solution, namely the
|
24 | 24 | % region where 'On2' and 'On3' closely match.
|
25 | 25 | %
|
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. |
28 | 29 | %
|
29 | 30 | % SNRdB = converse_mc(N, Pe, R, 'approx','error') for a codeword of length
|
30 | 31 | % N, and code rate R, the function returns the SNR (in dB) at which the
|
|
36 | 37 | % All bounds were derived from:
|
37 | 38 | % [1] T. Erseghe, "Coding in the Finite-Blocklength Regime: Bounds
|
38 | 39 | % based on Laplace Integrals and their Asymptotic Approximations",
|
| 40 | +% IEEE Transactions on Information Theory, 62(12), pp 6854-6883, 2016 |
39 | 41 | % 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. |
40 | 46 | %
|
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. |
42 | 48 | %
|
43 | 49 | % PS1: The function is implemented in MATLAB R2017a and extensively uses
|
44 | 50 | % the 'fmincon' solver. Different MATLAB versions may require some
|
|
48 | 54 | % the code fails on a particular choice of parameters, please drop an
|
49 | 55 | % email to [email protected] and I will try to fix the bug.
|
50 | 56 | %
|
51 |
| -% (c) T. Erseghe 2016 |
| 57 | +% (c) T. Erseghe 2020 |
52 | 58 | %
|
53 | 59 |
|
54 | 60 | warning ('off','all');
|
|
82 | 88 | error(['Wrong input ',x4])
|
83 | 89 | end
|
84 | 90 |
|
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 |
| - |
91 | 91 |
|
92 | 92 | % optimization settings
|
93 | 93 | options1 = optimoptions('fmincon',...
|
|
124 | 124 | pe = Pe(k); % packet error probability
|
125 | 125 | qe = Qe(k); % Q^(-1)(pe)
|
126 | 126 | 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 |
127 | 137 |
|
128 | 138 | try
|
129 | 139 | if (n==inf)||strcmp(x3,'normal')
|
|
132 | 142 |
|
133 | 143 | elseif strcmp(x3,'On2')
|
134 | 144 | % 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); |
138 | 145 | % find saddle point
|
139 | 146 | sb = fmincon(@(x)zero_obj(x),sb0,[],[],[],[],[],[],...
|
140 | 147 | @(x)constr_om_on2_rate(x,om,pe,n),options2);
|
|
143 | 150 |
|
144 | 151 | elseif strcmp(x3,'On3')
|
145 | 152 | % 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); |
149 | 153 | % find saddle point
|
150 | 154 | sb = fmincon(@(x)zero_obj(x),sb0,[],[],[],[],[],[],...
|
151 | 155 | @(x)constr_om_on3_rate(x,om,pe,n),options2);
|
152 | 156 | % calculate rate value
|
153 | 157 | y(k) = -logFA_on3(sb,om,n)/log(2);
|
154 | 158 |
|
155 | 159 | 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; |
157 | 166 |
|
158 | 167 | end
|
159 | 168 |
|
|
192 | 201 | % define the SNR starting point
|
193 | 202 | if k==1
|
194 | 203 | om0 = 1;
|
| 204 | + [~, ~, V] = fun_HP(om0,0); |
| 205 | + sb0 = -qe/sqrt(V*n); |
195 | 206 | elseif ~isnan(y(k-1)) % use previous value
|
196 | 207 | om0 = y(k-1);
|
197 | 208 | 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 | + |
199 | 218 | try
|
200 | 219 | if (n==inf)||strcmp(x3,'normal')
|
201 | 220 | % case 1: normal approximation
|
|
205 | 224 |
|
206 | 225 | elseif strcmp(x3,'On2')
|
207 | 226 | % 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); |
211 | 227 | % check that if starting point is feasible
|
212 | 228 | [~, con] = constr_om_on2_error([sb0; om0],R,pe,n);
|
213 | 229 | % find SNR/saddle point
|
|
217 | 233 |
|
218 | 234 | elseif strcmp(x3,'On3')
|
219 | 235 | % 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); |
223 | 236 | % check if the starting point is feasible
|
224 | 237 | [~, con] = constr_om_on3_error([sb0; om0],R,pe,n);
|
225 | 238 | % find SNR/saddle point
|
|
229 | 242 |
|
230 | 243 | elseif strcmp(x3,'full')
|
231 | 244 | % 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 | + |
233 | 252 | end
|
234 | 253 |
|
235 | 254 | % something did not work !
|
|
306 | 325 | R = C - qe*log2(exp(1))*sqrt(V/n) + log2(n)/2/n; % rate
|
307 | 326 | end
|
308 | 327 |
|
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 |
| - |
317 | 328 | % log(FA) function under the O(n^-2) approximation
|
318 | 329 | function y = logFA_on2(sb,om,n)
|
319 | 330 | sa = sb+1;
|
|
325 | 336 | [Hp, la, a2] = fun_HP(om,sb);
|
326 | 337 | y = la.*sb + log(Hp) -log(2*pi*n*sb.^2.*a2)/2/n;
|
327 | 338 |
|
| 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 | + |
328 | 399 | % constraints for calculating the code rate bound under the O(n^-2)
|
329 | 400 | % approximation
|
330 | 401 | function [c ceq gradc gradceq] = constr_om_on2_rate(sb,om,Pe,n)
|
|
342 | 413 | logFA_on2(x(1),x(2),n)+R*log(2)];
|
343 | 414 | gradceq = []; % too long to derive !!!
|
344 | 415 |
|
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 |
| - |
360 | 416 | % constraints for calculating the code rate bound under the O(n^-3)
|
361 | 417 | % approximation
|
362 | 418 | function [c ceq gradc gradceq] = constr_om_on3_rate(sb,om,Pe,n)
|
|
373 | 429 | ceq = [logMD_on3(x(1),x(2),n)-log(Pe)/n; ...
|
374 | 430 | logFA_on3(x(1),x(2),n)+R*log(2)];
|
375 | 431 | 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 !!! |
0 commit comments