commit 7c91ba91299ea31c18a1f314ffeb10ff8dd2121a Author: ti_mo Date: Thu Apr 23 21:34:07 2026 +0200 Initial push diff --git a/Tutorial/tutorial1.m b/Tutorial/tutorial1.m new file mode 100644 index 0000000..50a114c --- /dev/null +++ b/Tutorial/tutorial1.m @@ -0,0 +1,24 @@ +A = [1 2 3 4; + 4 3 2 1; + 3 1 4 2; + 2 3 4 1]; + +x = A.*A; + +normalize(A); + +normalize(inv(A)); +norm(A); +norm(inv(A)); + +B = {1 2 4}; +C = {4 3 5}; + +y = -1:0.2:1; + +z = 1:1:3; + +M = repmat(z, [5 1]) +M = reshape(M, [size(M) 1]) + + diff --git a/lab_1/lab_1.asv b/lab_1/lab_1.asv new file mode 100644 index 0000000..33fbd0c --- /dev/null +++ b/lab_1/lab_1.asv @@ -0,0 +1,82 @@ +% 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 \ No newline at end of file diff --git a/lab_1/lab_1.m b/lab_1/lab_1.m new file mode 100644 index 0000000..ecfbedb --- /dev/null +++ b/lab_1/lab_1.m @@ -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 \ No newline at end of file