I am wanting to simulate error bursts for my program but I am not sure how I would go about doing it.
Let's say I have a fixed bit-error-rate of 2/10 and varying error-burst-lengths from 4 to 12 bits and an infinite stream of bits, how can I make it so error-bursts occur at random intervals with varying lengths from 4 to 12 bits while still ensuring the average bit-error-rate converges toward 2/10?
Suppose you uniformly sample the set [4, 5, ..., 12] when it comes to choosing the length of an error bit burst. Then the expected length of an error burst is (4+5+...+12)/9 = 8.
Note: you can sample the error burst lengths however you want - all that we actually use below is the expectation of the error burst length.
If you want an overall bit error rate of 2/10, all you have to do is the following:
error_lengths = [4, 5, 6, 7, 8, 9, 10, 11, 12]
loop forever
if rand() < 1/33 // with probability 1/33
n = rand(error_lengths) // pick a random error length
emit n contiguous error bits
else
emit 1 good bit
The reason this works is that, on average, for every 33 iterations the if condition is true 1 time and false 32 times. Each true creates, on average, 8 error bits; each false creates 1 good bit.
Therefore the rate of error bits is (1*8)/(1*8 + 32*1) = 8/40 = 2/10.
If you want to guarantee that no two error sequences are ever adjacent, you can do this instead:
error_lengths = [4, 5, 6, 7, 8, 9, 10, 11, 12]
loop forever
if rand() < 1/32 // with probability 1/32
n = rand(error_lengths) // pick a random error length
emit n contiguous error bits
emit 1 good bit
Expected number of good bits per iteration = 1
Expected number of error bits per iteration = 8/32
Error rate = (8/32)/(1+8/32) = 8/40 = 2/10
You told us a range but haven't specified the distribution for the error-burst lengths, nor for the clean interval lengths. Are all values in the range equally likely, do 4's occur more frequently than 12's or vice-versa, or is, say, 6 the most common occurrence?
Let's assume you have distributions E for error-burst length and C for clean interval lengths, which have means M_e and M_c, respectively. Then what you need to do is derive/construct a parameterization the C distribution so that M_c = 4 M_e. To kick-start the process, choose an error-burst with probability 0.2 vs a clean interval with probability 0.8 for your first interval. Then alternate between error cycles and clean cycles using the E and C distributions to generate the durations.
For example, if both types of intervals follow uniform distributions, then the mean error burst length is 8 and you need clean intervals with a mean length of 32. You could achieve that with U(31,33), U(1,63), or U(10,54), for instance - all three have means of 32.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With