Sign in

username or email:

password:



Not a member?
Forgot your password?

Search code



Search tips


See Also

Embedded SystemsFPGA

DSP Code Sharing > Hamming Weight and Hamming Distance

Hamming Weight and Hamming Distance

Language: Scilab

Processor: Not Relevant

Submitted by Senthilkumar R on Mar 24 2011

Licensed under a Creative Commons Attribution 3.0 Unported License

Hamming Weight and Hamming Distance


 

Hamming Weight and Hamming Distance H(7,4).Code Word Length = 7, Message Word length = 4, Parity bits =3

 
// Hamming Weight and Hamming Distance
//H(7,4)
//Code Word Length = 7, Message Word length = 4, Parity bits =3
close;
clc;
//Getting Code Words
code1 = input('Enter the first code word');
code2 =  input('Enter the second code word');
Hamming_Distance = 0;
for i = 1:length(code1)
  Hamming_Distance =Hamming_Distance+xor(code1(i),code2(i));
end
disp(Hamming_Distance,'Hamming Distance')
//Result
//Enter the first code word [0,1,1,1,0,0,1]
//Enter the second code word[1,1,0,0,1,0,1]
//Hamming Distance       4.  
 
Rate this code snippet:
0
Rating: 0 | Votes: 0
 
   
 
posted by Senthilkumar R



Comments


 

ottokar wrote:

2/20/2012
 
This one seems to work also:
a = [0,1,1,1,0,0,1]
b = [1,1,0,0,1,0,1]
hammingDist = sum(a <> b)

Add a Comment
You need to login before you can post a comment (best way to prevent spam). ( Not a member? )