Скачиваний:
5
Добавлен:
17.06.2023
Размер:
2.11 Кб
Скачать


pkg load communications
function outArr=gec(dataArr,pBG,pGB,pG,pB,initState)
State = initState;
[Height,Width]=size(dataArr);
outArr=zeros(Height,Width);
for Cnt1=1:1:Height
for Cnt2=1:1:Width
if State == 0
outArr(Cnt1,Cnt2) = xor(dataArr(Cnt1,Cnt2),rand(1)<=pG);
State = rand(1)<=pGB;
elseif State == 1
outArr(Cnt1,Cnt2) = xor(dataArr(Cnt1,Cnt2),rand(1)<=pB);
State = rand(1)>pBG;
else
printf('Error: Incorrect state\n');
endif
end
end
endfunction

---------------------------------------------------------------------------------

function Mean = MonteCarlo(dataArr,Height,Width,n)
Sum=0;
for count=1:1:n
row=floor((Height-1).*rand(1))+1;
column=floor((Width-1).*rand(1))+1;
Sum=Sum+dataArr(row,column);
end
Mean=Sum./n;
endfunction

----------------------------------------------------------------------------------------------------------
function averageOverAll = dsk(dataArr, p, Height, Width, n, pBG, pGB, pG, pB, initState, Model)
for i=1:1:5
Arr(1:Height,1:Width)=0;
if (Model==1)
Arr=gec(dataArr,pBG,pGB,pG,pB,initState);
elseif (Model==0)
Arr=bsc(dataArr,p);
endif
ArrOfMean(1,i)=MonteCarlo(Arr,Height,Width,n);
end
averageOverAll=sum(ArrOfMean(:))./5;
x=[1 2 3 4 5];
y=[ArrOfMean(1,1) ArrOfMean(1,2) ArrOfMean(1,3) ArrOfMean(1,4) ArrOfMean(1,5)];
plot(x,averageOverAll,'o-r',x,y);
title('mean');
endfunction
----------------------------------------------------------------------------------------------------------

Height=100;
Width=1000;
dataArr(1:Height,1:Width)=0;
pG=1;
pB=0;
pGB=0.4;
pBG=0.6;
n=0.2*(Height*Width);


dsk(dataArr, 0.0001, Height, Width, n, pBG, pGB, pG, pB, 0, 0);
dsk(dataArr, 0.0005, Height, Width, n, pBG, pGB, pG, pB, 0, 0);
dsk(dataArr, 0.001, Height, Width, n, pBG, pGB, pG, pB, 0, 0);
dsk(dataArr, 0.005, Height, Width, n, pBG, pGB, pG, pB, 0, 0);
dsk(dataArr, 0.01, Height, Width, n, pBG, pGB, pG, pB, 0, 0);
dsk(dataArr, 0.05, Height, Width, n, pBG, pGB, pG, pB, 0, 0);
dsk(dataArr, 0.1, Height, Width, n, pBG, pGB, pG, pB, 0, 0);
dsk(dataArr, 0, Height, Width, n, pBG, pGB, pG, pB, 0, 1);


Соседние файлы в предмете Основы теории передачи данных