save
This commit is contained in:
Vendored
BIN
Binary file not shown.
+29
-22
@@ -4,8 +4,6 @@ p_gg = 0.99;
|
|||||||
p_bb = 0.1;
|
p_bb = 0.1;
|
||||||
p_bg = 1 - p_bb;
|
p_bg = 1 - p_bb;
|
||||||
|
|
||||||
pi_0 = p_bb / (2 - (p_gg + p_bb));
|
|
||||||
|
|
||||||
% freely chosen bit error probability
|
% freely chosen bit error probability
|
||||||
e_g = 10^-4;
|
e_g = 10^-4;
|
||||||
e_b = 10^-1;
|
e_b = 10^-1;
|
||||||
@@ -14,49 +12,51 @@ e_b = 10^-1;
|
|||||||
bits_array_len = 10^6;
|
bits_array_len = 10^6;
|
||||||
bits = randi([0, 1], 1, bits_array_len);
|
bits = randi([0, 1], 1, bits_array_len);
|
||||||
|
|
||||||
% choose beginning channel state, biased to false,
|
% start with a clean error free pipe
|
||||||
% assume pipe dirty at start of stream
|
|
||||||
if rand() < pi_0
|
|
||||||
channel_state = true;
|
channel_state = true;
|
||||||
else
|
|
||||||
channel_state = false;
|
|
||||||
end
|
|
||||||
|
|
||||||
% preallocated array/vector for the resulting bits
|
% preallocated array/vector for the resulting bits
|
||||||
result_stream = zeros(1, bits_array_len);
|
result_stream = zeros(1, bits_array_len);
|
||||||
|
|
||||||
bit_error_rate_counter = 0;
|
bit_error_rate_counter = 0;
|
||||||
gap_size_tracker = [];
|
gap_begin = 1; % stores the last dirty bit idx, meaning the begin of a new gap
|
||||||
current_gap_size = 0;
|
gap_tracker = []; % holds a 3xn matrix of begin and end gap values and the gap size between them
|
||||||
|
|
||||||
|
state_sequence = []; % collector array for the visited states
|
||||||
|
|
||||||
for it = 1 : bits_array_len
|
for it = 1 : bits_array_len
|
||||||
current_bit = bits(it);
|
current_bit = bits(it);
|
||||||
|
|
||||||
r = rand();
|
% 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
|
% error and channel
|
||||||
if channel_state == true
|
if channel_state == true
|
||||||
|
state_sequence(end + 1) = 'Good';
|
||||||
% channel selection from good state with probability p_gg
|
% channel selection from good state with probability p_gg
|
||||||
if r < p_gg
|
if channel_change_probability < p_gg
|
||||||
channel_state = 1;
|
channel_state = 1;
|
||||||
else
|
else
|
||||||
channel_state = 0;
|
channel_state = 0;
|
||||||
end
|
end
|
||||||
|
|
||||||
if r < e_g
|
% flip the bit with probability e_g
|
||||||
|
if bit_error_probability < e_g
|
||||||
received_bit = 1 - current_bit;
|
received_bit = 1 - current_bit;
|
||||||
else
|
else
|
||||||
received_bit = current_bit;
|
received_bit = current_bit;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
% change channel to good with probability
|
% change channel to good with probability of p_bg
|
||||||
if r < p_bg
|
if channel_change_probability < p_bg
|
||||||
channel_state = 1;
|
channel_state = 1;
|
||||||
else
|
else
|
||||||
channel_state = 0;
|
channel_state = 0;
|
||||||
end
|
end
|
||||||
|
|
||||||
if r < e_b
|
if bit_error_probability < e_b
|
||||||
received_bit = 1 - current_bit;
|
received_bit = 1 - current_bit;
|
||||||
else
|
else
|
||||||
received_bit = current_bit;
|
received_bit = current_bit;
|
||||||
@@ -68,15 +68,22 @@ for it = 1 : bits_array_len
|
|||||||
% BER and Gap
|
% BER and Gap
|
||||||
if current_bit ~= received_bit
|
if current_bit ~= received_bit
|
||||||
bit_error_rate_counter = bit_error_rate_counter + 1;
|
bit_error_rate_counter = bit_error_rate_counter + 1;
|
||||||
gap_size_tracker(end + 1) = current_gap_size;
|
|
||||||
current_gap_size = 0;
|
gap_tracker(:, end + 1) = [gap_begin; it; it - gap_begin - 1];
|
||||||
end
|
gap_begin = it;
|
||||||
|
end
|
||||||
current_gap_size = current_gap_size + 1;
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
gap_tracker(:, 1) = []; % trim first gap, this is a fault entry by design
|
||||||
bit_error_rate = bit_error_rate_counter / bits_array_len
|
bit_error_rate = bit_error_rate_counter / bits_array_len
|
||||||
|
|
||||||
% limit gap size to 500 in histogram
|
gap_sizes = gap_tracker(3, :);
|
||||||
|
gap_sizes = gap_sizes(gap_sizes <= 500); % limit gap size to 500 for histogram
|
||||||
|
|
||||||
|
histogram(gap_sizes, 'BinEdges', -0.5:1:500.5);
|
||||||
|
xlabel('Gap size')
|
||||||
|
ylabel('Frequency')
|
||||||
|
title('Histogram of gap sizes between consecutive errors')
|
||||||
|
|
||||||
% for pdf, 1 - 2 sites, describe what i did and what the results were and
|
% for pdf, 1 - 2 sites, describe what i did and what the results were and
|
||||||
% are
|
% are
|
||||||
+28
-8
@@ -19,8 +19,11 @@ channel_state = true;
|
|||||||
result_stream = zeros(1, bits_array_len);
|
result_stream = zeros(1, bits_array_len);
|
||||||
|
|
||||||
bit_error_rate_counter = 0;
|
bit_error_rate_counter = 0;
|
||||||
gap_size_tracker = [];
|
gap_begin = 1; % stores the last dirty bit idx, meaning the begin of a new gap
|
||||||
current_gap_size = 0;
|
gap_tracker = []; % holds a 3xn matrix of begin and end gap values and the gap size between them
|
||||||
|
|
||||||
|
state_sequence = []; % stores the state timeline
|
||||||
|
state_visit_counter = 0;
|
||||||
|
|
||||||
for it = 1 : bits_array_len
|
for it = 1 : bits_array_len
|
||||||
current_bit = bits(it);
|
current_bit = bits(it);
|
||||||
@@ -32,22 +35,29 @@ for it = 1 : bits_array_len
|
|||||||
|
|
||||||
% error and channel
|
% error and channel
|
||||||
if channel_state == true
|
if channel_state == true
|
||||||
|
state_visit_counter = state_visit_counter + 1;
|
||||||
% channel selection from good state with probability p_gg
|
% channel selection from good state with probability p_gg
|
||||||
if channel_change_probability < p_gg
|
if channel_change_probability < p_gg
|
||||||
channel_state = 1;
|
channel_state = 1;
|
||||||
else
|
else
|
||||||
channel_state = 0;
|
channel_state = 0;
|
||||||
|
state_sequence(end + 1) = state_visit_counter + 'x Good';
|
||||||
|
state_visit_counter = 0;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
% flip the bit with probability e_g
|
||||||
if bit_error_probability < e_g
|
if bit_error_probability < e_g
|
||||||
received_bit = 1 - current_bit;
|
received_bit = 1 - current_bit;
|
||||||
else
|
else
|
||||||
received_bit = current_bit;
|
received_bit = current_bit;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
state_sequence(it) = 'Bad';
|
||||||
% change channel to good with probability of p_bg
|
% change channel to good with probability of p_bg
|
||||||
if channel_change_probability < p_bg
|
if channel_change_probability < p_bg
|
||||||
channel_state = 1;
|
channel_state = 1;
|
||||||
|
state_sequence(end + 1) = state_visit_counter + 'x Bad';
|
||||||
|
state_visit_counter = 0;
|
||||||
else
|
else
|
||||||
channel_state = 0;
|
channel_state = 0;
|
||||||
end
|
end
|
||||||
@@ -64,15 +74,25 @@ for it = 1 : bits_array_len
|
|||||||
% BER and Gap
|
% BER and Gap
|
||||||
if current_bit ~= received_bit
|
if current_bit ~= received_bit
|
||||||
bit_error_rate_counter = bit_error_rate_counter + 1;
|
bit_error_rate_counter = bit_error_rate_counter + 1;
|
||||||
gap_size_tracker(end + 1) = current_gap_size;
|
|
||||||
current_gap_size = 0;
|
gap_tracker(:, end + 1) = [gap_begin; it; it - gap_begin - 1];
|
||||||
|
gap_begin = it;
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
current_gap_size = current_gap_size + 1;
|
gap_tracker(:, 1) = []; % trim first gap, this is a fault entry by design
|
||||||
end
|
bit_error_rate = bit_error_rate_counter / bits_array_len;
|
||||||
|
|
||||||
bit_error_rate = bit_error_rate_counter / bits_array_len
|
gap_sizes = gap_tracker(3, :);
|
||||||
|
gap_sizes = gap_sizes(gap_sizes <= 500); % limit gap size to 500 for histogram
|
||||||
|
|
||||||
|
histogram(gap_sizes, 'BinEdges', -0.5:1:500.5);
|
||||||
|
xlabel('Gap size')
|
||||||
|
ylabel('Frequency')
|
||||||
|
title('Histogram of gap sizes between consecutive errors')
|
||||||
|
|
||||||
|
disp(state_sequence)
|
||||||
|
disp(bit_error_rate)
|
||||||
|
|
||||||
% limit gap size to 500 in histogram
|
|
||||||
% for pdf, 1 - 2 sites, describe what i did and what the results were and
|
% for pdf, 1 - 2 sites, describe what i did and what the results were and
|
||||||
% are
|
% are
|
||||||
Reference in New Issue
Block a user