4 семестр ИКТ 6 вариант / ЛР3 СПВТ
.docxЛабораторная работа №3
Задание 1
N=6
Ndigits = 5000;
Py1x2 = 0.06;
Py2x1 = 0.06;
j = 0;
for p = 0:0.1:1
j = j + 1;
res = 0;
res = bsc_new(Ndigits, p, Py1x2, Py2x1, 0);
ProbPy1(j) = res(1);
ProbPy2(j) = res(2);
ProbSum(j) = res(1) + res(2);
ProbError(j) = res(3);
Axis(j) = p;
end
plot(Axis,ProbError, '-ro', Axis, ProbPy1, '-bx', Axis, ProbPy2, '-ms', Axis, ProbSum, '-g+');
xlabel('Probability Px1');
legend('Pe', 'Py1', 'Py2','Py1+Py2');
function [res] = bsc_new(Ndigits, Px1, Py1x2, Py2x1, option)
y1 = 0;
y2 = 0;
CountError = 0;
for i = 1:Ndigits
TransBit = BinarySource(Px1);
RecBit = Channel(TransBit, Py2x1, Py1x2);
if (RecBit == 0)
y1 = y1 + 1;
else
y2 = y2 + 1;
end
if ( RecBit ~= TransBit)
CountError = CountError + 1;
end
end
if (option == 1)
disp('----------------------------');
disp('Simultion Results');
disp('----------------------------');
disp('Probability Py1');
disp(y1/Ndigits);
disp('Probability Py2');
disp(y2/Ndigits);
disp('Py1 + Py2');
disp(y1/Ndigits + y2/Ndigits);
disp('Probability of an error in a binary digit');
disp(CountError/Ndigits);
disp('----------------------------');
Px2 = 1 - Px1;
Py2x2 = 1 - Py1x2;
Py1x1 = 1- Py2x1;
disp('Theoretical Results');
disp('----------------------------');
disp('Expected Py1 = ');
Py1 = Py1x1*Px1 + Py1x2*Px2;
disp(Py1);
disp('Expected Py2 = ');
Py2 = Py2x1*Px1 + Py2x2*Px2;
disp(Py2);
disp('Expected Pe = ');
Pe =Py1x2*Px2 + Py2x1*Px1;
disp(Pe);
disp('----------------------------');
end
res(1) = y1/Ndigits;
res(2) = y2/Ndigits;
res(3) = res(1)+res(2);
res(4) = CountError/Ndigits;
disp(res)
Задание 2
for alpha = 0.1:0.1:0.5
j = j + 1;
PeSim3(j) = DCS(100, 0.5, alpha, 3);
PeSim6(j) = DCS(100, 0.05, alpha, 6);
Theory3(j) = PeTheory(3, alpha);
Theory6(j) = PeTheory2(6, alpha);
Axis(j) = alpha;
end
function pe = PeTheory2(n, alpha)
sum = 0;
for i = (n/2) + 1 : 1 : n
tmp1 = factorial(n);
tmp2 = factorial(n-i);
tmp3 = factorial(i);
tmp4 = alpha^i;
tmp5 = (1-alpha)^(n-i);
sum = sum + (tmp1/(tmp2*tmp3))*tmp4*tmp5;
end
pe = sum;