www.pudn.com > Polar_code.zip > W.m, change:2013-06-21,size:1235b

```
function Val = W(input_y,input_u,condition_u,p,Channel)
% input_y = [1 0 0 0 0 0 0 1];
% input_u = [1 0 0 0];

k = length(input_u)+1; %length(input_u)+length(condition_u)
N = length(input_y);
u_2i = [0; 1];
Temp = 0;
M = N/2;
% p = 0.5; % channel probability

if N == 2
if k == 1
for i = 1:2
Temp = Temp + 0.5*prob(input_y(1),mod(u_2i(i)+condition_u,2),p,Channel)*prob(input_y(2),u_2i(i),p,Channel);
end
elseif k == 2
Temp = 0.5*prob(input_y(1),mod(input_u+condition_u,2),p,Channel)*prob(input_y(2),condition_u,p,Channel);
end
else
MOD = mod(k,2);
if k == 1 || k==2
u_L =[];
u_R = [];
else
u_L = mod(input_u(1:2:k-2+MOD)+input_u(2:2:k-2+MOD),2);
u_R = input_u(2:2:k-2+MOD);
end

if MOD ==1
for i = 1:2
L = W(input_y(1:M),u_L,mod(condition_u+u_2i(i),2),p,Channel);
R = W(input_y(M+1:N),u_R,u_2i(i),p,Channel);
Temp = Temp + 0.5*L*R;
end
else
L = W(input_y(1:M),u_L,mod(condition_u+input_u(k-1),2),p,Channel);
R = W(input_y(M+1:N),u_R,condition_u,p,Channel);
Temp = 0.5*L*R;
end
end

Val = Temp;

```