bblanchon / ArduinoStreamUtils

💪 Power-ups for Arduino streams
MIT License
257 stars 21 forks source link

Update HammingEncodingPolicy.hpp #18

Open supergohan opened 2 years ago

supergohan commented 2 years ago

The encoding table does not match the standard Hamming(7,4) codes ... it needs an explanation https://www.gaussianwaves.com/2008/05/hamming-codes-how-it-works/

bblanchon commented 2 years ago

Hi @supergohan,

Thank you very much for this contribution.

I don't recall how I choose the encoding table. I looked at the linked document, but I don't think it really helps.

Could you add a more explicit comment?

Best regards, Benoit

supergohan commented 2 years ago

Dear Benoit,

Thank you for contacting me. After spending more time looking at the Hamming (7,4) code, I have found the following two links [1] https://www.gaussianwaves.com/2008/05/hamming-codes-how-it-works/ [2] https://michaeldipperstein.github.io/hamming.html#download ; https://github.com/michaeldipperstein/hamming The last link [2] describes the theory that supports the encoding and decoding table in HammingEncodePolicy.hpp. I am not sure if you could extend the functionality so it could support encoding with Matrices (the code is in github). That will enhance the library as it opens the use of other Hamming codes . I got confused with the definition of the encoding matrix H as it was defined differently in [1] and [2]. However, the implementation is fine (I have attached a Matlab programme)

On another note, StreamUtils is really useful and I reckon adding the CRC functionality of https://github.com/RobTillaart/CRCwill be great for network communications.

Thank you again for your great work.

Best Wishes, Angel

El lun, 21 feb 2022 a las 8:16, Benoît Blanchon @.***>) escribió:

Hi @supergohan https://github.com/supergohan,

Thank you very much for this contribution.

I don't recall how I choose the encoding table. I tried to look at the linked document, but I don't think it really helps.

Could you add a more explicit comment?

Best regards, Benoit

— Reply to this email directly, view it on GitHub https://github.com/bblanchon/ArduinoStreamUtils/pull/18#issuecomment-1046585326, or unsubscribe https://github.com/notifications/unsubscribe-auth/AG65E5IOYOXEQPMB42L7PPTU4HYHJANCNFSM5OZRHPBA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

clear all; close all; clc;

%https://www.gaussianwaves.com/2008/05/hamming-codes-how-it-works/ %https://michaeldipperstein.github.io/hamming.html#download

%Hamming encoder (7,4) -- p1 p2 p3 d1 d2 d3 d4 % https://en.wikipedia.org/wiki/Hamming_code % p3 p2 p1 d1 d2 d3 d4 G=[0 1 1 1 0 0 0; 1 0 1 0 1 0 0; 1 1 0 0 0 1 0; 1 1 1 0 0 0 1];%generator matrix - (7,4) Hamming code %inputs with 4 bits dec=0:15; % convert the input to binary bin = dec2bin(dec,4); %it returns a string % the string has a binary number binn=double(bin)-double('0'); % convert the string into a number %find the Hamming code, with the code generator matrix RES=mod(binn*G,2) %The number is converter to a string result=num2str(RES) for i=1:16 requiredString(i,:) = regexprep(result(i,:), '\s+', '') %white spaces are removed end %This is the result dec2hex(bin2dec(requiredString))

%program to generate all possible codewords for (7,4) Hamming code m=de2bi(0:1:15,'left-msb');%list of all numbers from 0 to 2ˆk codebook=mod(m*G,2) %list of all possible codewords