How do I use multiple variables in a for loop, that rely on each other?
5 views (last 30 days)
Show older comments
I am trying to create a Meggitt Decoder. The part I need help with is at the end when I need to calculate the syndrome. Parts of the syndrome relys on each other and I do not know how to make it work.
clear variables; clc;
n = 7;
k = 4;
fprintf ('Hamming code (%u, %u)\n\n', n, k);
Message = [1 0 1 1];
fprintf ('Message Polynomial = ')
gfpretty(Message)
Generator = [1 1 0 1];
fprintf ('Generator Polynomial = ')
gfpretty(Generator)
% Creating the Codeword
Codeword = encode(Message,n,k);
fprintf ('Codeword = ');
gfpretty(Codeword)
% Finding the Syndrome
value = 0:(n-1);
Error = zeros(size(value));
sn = 0;
for l = value
sn = 2;
Error(sn) = 1;
end
fprintf('Error = ')
gfpretty(Error)
[Quotient,Remainder] = gfdeconv(Error,Generator);
fprintf ('Syndrome = ')
gfpretty(Remainder)
% Meggitt Decoder
Recieved = bitxor(Codeword,Error);
fprintf('Recieved Codeword = ')
gfpretty(Recieved)
%Part I need help working
S2 = zeros(size(0:n-1));
S1 = zeros(size(0:n-1));
S0 = zeros(size(0:n-1));
for i = 0:n-1
count = i + 1;
Buffer = Recieved(count);
S2 = S1(count);
S1 = bitxor(S0(count),S2(count));
S0 = bitxor(S2(count),Buffer);
end
2 Comments
Rishik Ramena
on 18 Mar 2021
Can you provide more details regarding the variables you need help regarding?
Jan
on 18 Mar 2021
"I do not know how to make it work" - this sound like something is not working as you expect it. Then mention, what it is. The readers cannot guess this detail.
Answers (1)
Jan
on 18 Mar 2021
This looks strange:
S2 = zeros(size(0:n-1));
It is working, but you do know the size of a 0:n-1 vector already, don't you?
S2 = zeros(1, n);
In the folloing loop you overwrite the values of S0, S1, and S2 by a scalar in each iteration. I guess, you want something else, but withouit meaningful and exhaustive comments I'm do not know the purpose of the code.
Why do you run a loop from 0 to n-1 if you access i+1 only? It is simpler to run the loop from 1 to n:
for i = 1:n
Buffer = Recieved(i);
% Then what do you want to happen here?
end
0 Comments
See Also
Categories
Find more on Error Detection and Correction in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!