82 lines
1.8 KiB
Plaintext
82 lines
1.8 KiB
Plaintext
% generating error patterns using gilbert-elliot model
|
|
|
|
p_gg = 0.99;
|
|
p_bb = 0.1;
|
|
p_bg = 1 - p_bb;
|
|
|
|
pi_0 = p_bb / (2 - (p_gg + p_bb));
|
|
|
|
% freely chosen bit error probability
|
|
e_g = 10^-4;
|
|
e_b = 10^-1;
|
|
|
|
% generate random bitstream
|
|
bits_array_len = 10^6;
|
|
bits = randi([0, 1], 1, bits_array_len);
|
|
|
|
% choose beginning channel state, biased to false,
|
|
% assume pipe dirty at start of stream
|
|
if rand() < pi_0
|
|
channel_state = true;
|
|
else
|
|
channel_state = false;
|
|
end
|
|
|
|
% preallocated array/vector for the resulting bits
|
|
result_stream = zeros(1, bits_array_len);
|
|
|
|
bit_error_rate_counter = 0;
|
|
gap_size_tracker = [];
|
|
current_gap_size = 0;
|
|
|
|
for it = 1 : bits_array_len
|
|
current_bit = bits(it);
|
|
|
|
r = rand();
|
|
|
|
% error and channel
|
|
if channel_state == true
|
|
% channel selection from good state with probability p_gg
|
|
if r < p_gg
|
|
channel_state = 1;
|
|
else
|
|
channel_state = 0;
|
|
end
|
|
|
|
if r < e_g
|
|
received_bit = 1 - current_bit;
|
|
else
|
|
received_bit = current_bit;
|
|
end
|
|
else
|
|
% change channel to good with probability
|
|
if r < p_bg
|
|
channel_state = 1;
|
|
else
|
|
channel_state = 0;
|
|
end
|
|
|
|
if r < e_b
|
|
received_bit = 1 - current_bit;
|
|
else
|
|
received_bit = current_bit;
|
|
end
|
|
end
|
|
|
|
result_stream(it) = received_bit;
|
|
|
|
% BER and Gap
|
|
if current_bit ~= received_bit
|
|
bit_error_rate_counter = bit_error_rate_counter + 1;
|
|
gap_size_tracker(end + 1) = current_gap_size;
|
|
current_gap_size = 0;
|
|
end
|
|
|
|
current_gap_size = current_gap_size + 1;
|
|
end
|
|
|
|
bit_error_rate = bit_error_rate_counter / bits_array_len
|
|
|
|
% limit gap size to 500 in histogram
|
|
% for pdf, 1 - 2 sites, describe what i did and what the results were and
|
|
% are |