function result = calc_transfer_bound(EsNo)

%EsNo = 1; %Es/No
NSTATES = 64;
k=1;
dfree = 10;

%generate I,W,V matrices
gen_IWV;
%I = [0 0;1 1];
%W = [0 2;2 2];
%V = [1 1;1 1];

%store as [w,i]
IVal = 1;
WVal = exp(-EsNo);

dw = W(1,1); di = I(1,1);
cw = W(1,2:end); ci = I(1,2:end);
bw = W(2:end,1); bi = I(2:end,1);
Aw = W(2:end,2:end); Ai = I(2:end,2:end);


AVal = Aw;
bVal = bw;
cVal = cw;

dVal = (IVal^di)*(WVal^dw)*V(1,1);

for m = 1:NSTATES-1
	for n = 1:NSTATES-1
		AVal(m,n) = (IVal^Ai(m,n))*(WVal^Aw(m,n))*V(m+1,n+1);
	end
end

for m = 1:NSTATES-1
	bVal(m) = (IVal^bi(m))*(WVal^bw(m))*V(m+1,1);
	cVal(m) = (IVal^ci(m))*(WVal^cw(m))*V(1,m+1);
end

AprimeVal = Aw;
bprimeVal = bw;
cprimeVal = cw;

dprimeVal = di*(IVal^(di-1))*(WVal^dw)*V(1,1);

for m = 1:NSTATES-1
	for n = 1:NSTATES-1
		AprimeVal(m,n) = Ai(m,n)*(IVal^(Ai(m,n)-1))*(WVal^Aw(m,n))*V(m+1,n+1);
	end
end

for m = 1:NSTATES-1
	bprimeVal(m) = bi(m)*(IVal^(bi(m)-1))*(WVal^bw(m))*V(m+1,1);
	cprimeVal(m) = ci(m)*(IVal^(ci(m)-1))*(WVal^cw(m))*V(1,m+1);
end

result = 1/k*qfunc(sqrt(2*dfree*EsNo))*(dprimeVal + cVal*inv(eye(length(cVal))-AVal)*bprimeVal +...
	cprimeVal*inv(eye(length(cVal))-AVal)*bVal +...
	cVal*inv(eye(length(cVal))-AVal)*AprimeVal*inv(eye(length(cVal))-AVal)*bVal)*...
	exp(dfree*EsNo);

end
