# Demo entry 6657468

Matlab Code

Submitted by anonymous on Nov 03, 2017 at 12:42
Language: Matlab. Code size: 1.0 kB.

```clc
clear all
close all
% Setup code parameters
n = 12;
N = 2^n; % length of codeword
e = 0.5; % erasure probability

for j=1:20
% Find best frozen bits and compute rate
d=j/100;% target block error rate d
f = polar_design_bec(n,e,d); %f=0.5 means good bits
k = sum(f==1/2);
rate(j) = k/N; %coding efficiency rate
% Run a few sims to compare with union bound
M = 100;
biterr = zeros(1,M);
for i=1:M
% Set frozen bits, add random data, and encode
u = f;
u(f==1/2) = rand(1,k)<0.5;
x = polar_transform(u);
% Transmit
y = x;
y(rand(1,N)<e)=1/2;
% Decode
[uhat,xhat] = polar_decode(y,f);
biterr(i) = mean(uhat~=u);
end
% Display average bit and block error rate
a(j)=mean(biterr);
b(j)=mean(biterr>0);
end

plot(linspace(0.01,0.2,20),a,'r','LineWidth',2)
hold on
plot(linspace(0.01,0.2,20),b,'y','LineWidth',2)
hold on
plot(linspace(0.01,0.2,20),rate,'b','LineWidth',2)
xlabel('Target block error rate')
legend('bit error rate', 'block error rate','coding efficiency rate');
```

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.