- 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.
cyclic code encoder/decoder problem
63 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I keep getting errors when running, but I don't know where the problem is.
% Decoder for Systematic (N,K) Cyclic Codes
function M = CyclicDecoder(R, P, T)
% Define N, K, DegPoly
K = length(R); % K is the length of Received Code
N = length(P); % N is length of Polynomial
DegPoly = N - 1;
LFSR = zeros(1, N - K);
for i = 1:K
feedback = R(i); % compute feedback
disp(['Input message: ', num2str(R(i)), ', Current LFSR: ', num2str(LFSR), ', feedback: ', num2str(feedback)]);
for j = DegPoly:-1:2
if (P(j) == 1)
LFSR(j) = rem((LFSR(j - 1) + feedback), 2);
else
LFSR(j) = LFSR(j - 1);
end
end
LFSR(1) = feedback;
disp(['Next LFSR: ', num2str(LFSR)]);
end
SYN = mod(conv(R, P), 2); % compute syndrome using convolution
index = bi2de(SYN, 'left-msb'); % get index value from binary syndrome
ErrorPattern = T(index + 1, :);
Uhat = mod(R + ErrorPattern, 2); % Correct R using ErrorPattern
M = Uhat(1:K); % Extract the message part from corrected Codeword
end
M = [1 0 1 1];
P = [1 1 0 1];
C = [1 0 0 1 0 1 0];
T = syndtable(cyclgen(length(ReceivedCodeword), P, 'system'));
0 commentaires
Réponses (1)
Sudarsanan A K
le 18 Oct 2023
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:
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
0 commentaires
Voir également
Catégories
En savoir plus sur Error Detection and Correction dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!