为什么随机损失符号不能很好地工作 [英] Why Random loss symbol does not work well

查看:120
本文介绍了为什么随机损失符号不能很好地工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试从给定的比特流中随机丢失。假设我有点流

  10 01 10 11 00 
  int * bitloss(int * orbit,int size_orbit,float loss_percent)
{
srand(time(NULL));
int * out_bitstream =(int *)malloc(sizeof(int)* size_orbit);
double randval;
for(int i = 0; i< size_orbit,i ++)
{
randval =(double)rand()/(double)RAND_MAX;
if(randval< loss_percent)
out_bitstream [i] =-1;
else out_bitstream [i] = orbit [i];

}
return out_bitstream;
}

如果随机数小于,则此代码会将原始位的值更改为-1 loss_percent。我称-1位为损失位。因此,给定loss_percent等于20%。这意味着我将从10个原始位中丢失2个数据包。但是当我这样做时。我表明,有些时候我会丢失0位,有些时候会丢失4位,有些时候会丢失2位。不稳定。如何编辑我的代码以稳定损失。例如,我想亏损20%。因此-1位的数量为2。非常感谢

解决方案

假设每个位的概率为 p 丢失,并且该位丢失是独立的(例如,在某些衰落的信道中,位丢失更可能发生在突发中,情况可能并非如此), N 位遵循二项式分布



因此,对于10位和20%的丢失率,您将获得以下分布:



类似地,对于1000位和相同的20%丢失率,您将获得以下分布:



请注意,随着位数的增加,二项式分布趋于高斯分布,其平均 Np 和v ariance Np(1-p)
具体来说,对于 N = 1000 p = 0.2 覆盖二项式的高斯分布的情况分布给出:



如您所见,这是一个很好的近似值。


I try to make random loss from a given bit stream. Assume that I have a bit stream as

10 01 10 11 00

Now I will create a code to implement random loss. The function with two inputs are original bit stream and percent loss. Output function is output bit stream

int* bitloss(int* orbit,int size_orbit,float loss_percent)
{
srand(time(NULL));
int* out_bitstream=(int*)malloc(sizeof(int)*size_orbit);
double randval ;
for(int i=0;i<size_orbit,i++)
{
    randval = (double)rand()/(double)RAND_MAX;
    if(randval<loss_percent) 
         out_bitstream[i]=-1;
     else out_bitstream[i]=orbit[i];

}
return out_bitstream;
}

This code will change value of original bit to -1 if the random belows than loss_percent.I call -1 bit is loss bit. So given loss_percent equals 20%. That mean I will loss 2 packets from 10 original bits. But when I do it. I show that some time I loss 0 bit, some time 4 bit, and sometime 2 bit. It is not stable. How to edit my code to stable loss. For example, I want to loss 20%. So the number of -1 bits are 2. Thank you so much

解决方案

Assuming each bit has a probability p of being lost, and that bit loss are independent (this may not be the case in for example some fading channels where bit loss are more likely to occur in bursts), the number of bit lost in N bits follows a binomial distribution.

Thus, for 10 bits and a loss rate of 20%, you would get the following distribution:

Similarly, for 1000 bits and the same loss rate of 20%, you would get the following distribution:

Note that as the total number of bits gets larger, the binomial distribution approaches a Gaussian distribution with average Np and variance Np(1-p) . Specifically, for the case of N=1000 and p=0.2 overlapping the Gaussian distribution over the binomial distribution gives:

As you can see it is a pretty good approximation.

这篇关于为什么随机损失符号不能很好地工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆