“…index = find(i == rs.alphaPower(1:n)); invertx(1+i) = rs.alphaPower(n+2-index); end invertxLT = @(x) invertx(1+uint16(x)); %% Chien search and Forney algorithm forneyCells2t = gfMul(uint16(1), alphaPowerLT(0), rs); errorValues = uint16(zeros(1, n)); %% Chien search cells preparation forneyCells(1:t) = gfMul(omega(1:t), alphaPowerLT(0), rs); chienCellsEven(1:floor(t/2+1)) = gfMul(lambda(t+3-2*(1:floor(t/2)+1)), alphaPowerLT(0), rs); chienCellsOdd(1:ceil(t/2)) = gfMul(lambda(t+2-2*(1:ceil(t/2))), alphaPowerLT(0), rs); alphaForney = alphaPowerLT(t-(1:t)); alphaChienEven = alphaPowerLT(t+2-2*(1:(floor(t/2)+1))); alphaChienOdd = alphaPowerLT(t+1-2*(1:ceil(t/2))); roots = 0; for i = 1:n lambdaEven = uint16(0); lambdaOdd = uint16(0); omegaVal = uint16(0); chienCellsEven = gfMul(chienCellsEven, alphaChienEven, rs); chienCellsOdd = gfMul(chienCellsOdd, alphaChienOdd, rs); forneyCells2t = gfMul(alphaPowerLT(2*t), forneyCells2t, rs); forneyCells = gfMul(forneyCells, alphaForney, rs); for j=1:floor(t/2)+1 lambdaEven = bitxor(lambdaEven, chienCellsEven(j)); end for j=1:ceil(t/2) lambdaOdd = bitxor(lambdaOdd, chienCellsOdd(j)); end lambdaFull = bitxor(lambdaEven, lambdaOdd); for j=1:t omegaVal = bitxor(omegaVal, forneyCells(j)); end omegaVal2t = gfMul(omegaVal, forneyCells2t, rs); %% Find root of error locator polynomial if (lambdaFull == 0) && (lambdaOdd~=0) % Calculate error value errorValues(i) = gfMul(omegaVal2t, invertxLT(lambdaOdd), rs); roots = roots + 1; else errorValues(i) = uint16(0); end end cf.errorValues = errorValues; cf.roots = roots; end Decoding function implementation The complete RS code decoder using implemented Syndrome calculation, RiBM algorithm, Chien search and Forney algorithm: function decoder = rsDecoder(receivedCode, rsStructure) receivedCode = uint16(receivedCode); n = rs.n; t = rs.t; %% Syndrome Calculation syndr = syndrome(receivedCode, rs); %% RiBM algorithm ribm = RiBM(syndr, rs); %% Chien search and Forney Algorithm chienForney = ChienForney(ribm, rs); %% Error Correction corrected = receivedCode(1:(n-2*t)); if ribm.lambdaDegree == chienForney.roots % Correct symbols corrected = bitxor(receivedCode, chienForney.errorValues); end decoder.received = receivedCode; decoder.syndrome = syndr; decoder.RiBM = ribm; decoder.chienForney = chienForney; decoder.corrected = corrected; decoder.msg = decoder.corrected(1:(n-2*t)); end Evaluation with examplesRS(7,3)A RS code of 𝑚 = 3 bits symbol size, 𝑘 = 3 symbols message size, codeword size of 𝑛 = 7 symbols and capable of correcting 𝑡 = (𝑛 − 𝑘)/2 = 2 symbol errors. The encoder takes 𝑚 bits to form a symbol, and 𝑘 symbols to form a message.…”