Gilbert-Elliot模型生成丢包模式的MATLAB代码

仅作为学习Gilbert-Elliot模型的参考,直接上代码:

%If p is the probability of transferring from Good State to the bad state
%and if r is the probability of transferring from the bad state to the Good
%state, given the p and r values, this code will generate a packet loss
%pattern (with burst losses) and save it to a file named “Loss_Pattern.txt”

clc

p = 0.02777;       % probability of transferring from Good State to the bad 
r = 0.25;          % probability of transferring from bad state to the Good
total_packs = 10000;     %包大小

check = 100;

while check >= 10           %当理论与实际的误差 >= 10% 时,再次执行

good = 1;                   %good = 1表示good state;  good = 0表示bad state
packets = [];

size = 1;

while size <= total_packs
if good == 1
    packets = [packets good];      %元素为1表示准确接收到了包,为0则表示丢包
    good = rand(1) > p;
elseif good == 0
    packets = [packets good];
    good = rand(1) > (1-r);
else
    fprintf('error\n');
    break;
end
size = size + 1;
end

fid = fopen('Loss_Pattern.txt','w');
fprintf(fid, '%d ', packets);
fclose(fid);
received_packs = nnz(packets);                           %准确接收到的包
%假定好状态时不发生丢包;bad状态时必发生丢包
theo_pack_loss_rate = 1 - r / (p+r);                     %理论丢包率
act_pack_loss_rate = 1 - received_packs/total_packs;     %实际丢包率

check = abs(theo_pack_loss_rate - act_pack_loss_rate) / theo_pack_loss_rate * 100;

end


save('packets','packets');     %保存为mat文件
theo_pack_loss_rate = p / (p+r)
act_pack_loss_rate = 1 - received_packs/total_packs

注:参考
https://www.mathworks.com/matlabcentral/fileexchange/38554-generate-packet-loss-patters-using-gilbert-elliot-model
https://blog.csdn.net/u010643777/article/details/89194456
http://www.ohohlfeld.com/paper/hasslinger_hohlfeld-mmb_2008.pdf

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值