Hello Dohyung,
It is my understanding that you are trying to implement a decoder for systematic (N, K) cyclic code using the provided code snippet. The code aims to correct errors in a received codeword by utilizing the generator polynomial "P" and the syndrome table "T".
To help you resolve the errors, it would be helpful if you can provide the specific error messages you are encountering. However, I have noticed some issues in the code you provided:
- Check Variable Names: In your code, you have used the variable name "ReceivedCodeword" in the "syndtable()" function, but it is not defined anywhere. Make sure you are using the correct variable names throughout your code.
- Calculation of Syndrome: Check the syndrome calculation. For an (N, K) cyclic code, the syndrome should be of length (N - K) and it would be the content in the syndrome register (LFSR). The LFSR content is unused in your code.
Additionally, I have attached below, a simplified approach for the detection of cyclic code by using the parity check matrix.
n = 7; % Codeword length
k = 4; % Message length
data = [1 0 1 1];
P = [1 1 0 1];
parmat = cyclgen(n,P);
T = syndtable(parmat);
encData = encode(data,n,k,'cyclic/binary',P);
disp(['Transmitted codeword: ', num2str(encData)]);
encData(3) = ~encData(3); % Error in 3rd bit
disp(['Received codeword: ', num2str(encData)]);
syndrome = mod(encData*parmat', 2);
disp(['Syndrome: ', num2str(syndrome)]);
errorPattern = T(bi2de(syndrome, 'left-msb') + 1, :);
disp(['Error pattern: ', num2str(errorPattern)]);
corData = mod(encData + errorPattern, 2);
disp(['Corrected codeword: ', num2str(corData)]);
Further, you can refer to the MathWorks documentation with example on "Encode and Decode Message with Cyclic Block Code" in the link:
Hope this helps you to get the decoding of cyclic codes with minimum effort