Initial push

This commit is contained in:
ti_mo
2026-04-23 21:34:07 +02:00
commit 7c91ba9129
3 changed files with 184 additions and 0 deletions
+78
View File
@@ -0,0 +1,78 @@
% generating error patterns using gilbert-elliot model
p_gg = 0.99;
p_bb = 0.1;
p_bg = 1 - 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);
% start with a clean error free pipe
channel_state = true;
% 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);
% two different rands for channel and bit logic
% to prevent unwanted coupling of these two mechanics
channel_change_probability = rand();
bit_error_probability = rand();
% error and channel
if channel_state == true
% channel selection from good state with probability p_gg
if channel_change_probability < p_gg
channel_state = 1;
else
channel_state = 0;
end
if bit_error_probability < e_g
received_bit = 1 - current_bit;
else
received_bit = current_bit;
end
else
% change channel to good with probability of p_bg
if channel_change_probability < p_bg
channel_state = 1;
else
channel_state = 0;
end
if bit_error_probability < 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