-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_1bit_error.m
32 lines (28 loc) · 1.65 KB
/
add_1bit_error.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
% function to add 1 bit error for given input code padded with zeros
function [error_detected, error_corrected, total_cnt] = add_1bit_error(in_code, conv_code, g1, g2, threshold, m)
len = length(conv_code);
total_cnt = 0;
error_detected = 0;
error_corrected = 0;
for i = 1:len
error1bit_conv_code = conv_code;
%{
if(error1bit_conv_code(i) == 1) % if bit is 1
error1bit_conv_code(i) = 0; % change bit from 1 to 0
else
error1bit_conv_code(i) = 1; % else, change bit from 0 to 1
end
%}
error1bit_conv_code(i) = ~error1bit_conv_code(i);%Introduce error in the bit
decoded = decode(error1bit_conv_code, g1, g2, zeros(1, m-1), 0, threshold, m); % decode the 1 bit error convolutional code
total_cnt = total_cnt + 1; % increment count of total combination
if(length(decoded) < length(in_code)) % if decoded code's length is less than input code's length
error_detected = error_detected + 1; % increment number of detected error
elseif(decoded == in_code) % else if decoded code is equal to input code
error_corrected = error_corrected + 1; % increment number of detected error
error_detected = error_detected + 1; % and, increment number of corrected error
end
end
%per_detected = error_detected/total_cnt * 100; % percentage of detected errors
%per_corrected = error_corrected/total_cnt * 100; % percentage of corrected errors
end