Я пытаюсь получить код VHDL, соответствующий моему моделированию в MATLAB с помощью приложения кодировщика HDL, но я получаю первую ошибку в строке 25, когда я создаю код MATLAB в приложении кодировщика HDL:
Выражение индекса выходит за пределы. Попытка доступа к элементу 15. Допустимый диапазон: 1-1.
Я не понимаю, потому что моделирование в MATLAB работает, и я не получаю эту ошибку.
function U_p = HDL_decoder_function(r)
H1 = [ 1 0 0 0 1 0 1 1 0 0 0 0 0 0 0 ];
H = 0;
S_in_rows = 0;
Sm = 0;
S = 0;
f_in_column = 0;
f = 0;
f_largest = 0;
f_nth_largest = 0;
% Declaration of the parity-check matrix
% Fill the first row to prepare the shift in the H matrix
for i = 1 : 15
H( 1, i ) = H1(i);
end
% Fill all the other rows with the shift
for j = 2 : 15
for i = 1 : 15
if( i == 1 )
H( j, i) = H( j-1, 15); % first error
else
H( j, i) = H( j-1, i-1);
end
end
end
H;
% Start of the bit-flipping algorithm
for k = 1 : 20 % Authorize 20 executions maximum of the statements of the algorithm
% Calculate the syndrome S = r^T * H
for j = 1 : 15
for i = 1 : 15
S_in_rows(i) = and( r(i), H( j, i) );
end
for i = 1 : 15
Sm = sum(S_in_rows);
end
if rem(Sm, 2) == 1
S(j) = 1;
else
S(j) = 0;
end
end
S;
% Go out from the loop when syndrome S = 0
if S == 0
U_p = r;
break
end
if k == 20
disp('Decoding fail')
U_p = [ 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ];
end
% Find the number f of failed syndrome bits for every received bits r
for i = 1 : 15
f(i) = 0; % Declaration
end
for i = 1 : 15
for j = 1 : 15
f_in_column = and( S(j), H( j, i) );
if f_in_column == 1
f(i) = f(i)+1;
end
end
end
f;
% Flip the the rth bit corresponding to the first largest number of error in f
f_largest = 0;
for i = 1 : 15
if f(i) > f_largest
f_largest = f(i); % Save the number of error
f_nth_largest = i; % Save the position of f_largest
end
end
f_largest;
f_nth_largest;
r(f_nth_largest) = not(r(f_nth_largest));
r;
U_p = r;
end