Skip to content

ethanpo2/hamming-code

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Description of Program

Creates a HammingVector (Hamming Code) with a user-defined number of data bits. After creation, prints the randomized data and the calculated message. Then an errored version of the message is "sent" to a new HammingVector. Finally, the program prints the errored message, the parity vector of the error message, the corrected message, and the derived data.

Description of algorithms and libraries used

Algorithms used:

  • matrixCrossVector function uses a bog standard matrix multiplication algorithm and as such is O(n^2).
  • buildG function builds the G matrix based on whether or not the current row is a power of 2; it is O(n^2).
  • buildH and buildR functions are used to decode a message in different ways. Both should be O(n^2).

Libraries used:

Description of functions and program structure

int main()
controls all the I/O and creates the HammingVectors
calls:
 HammingVector(int)
 vector HammingVector.getData()
 vector HammingVector.getMessage()
 vector HammingVector.getEMessage()
 void printVector(vector)
 HammingVector(vector)
 HammingVector.getParity()

HammingVector(int)
Returns a new instance of HammingVector. First, checks to make sure the number of data bits is large enough. Then, it calculates the number appropriate number of parity bits. Next, it randomly generates the data vector and builds the G, H, and R matrices. Finally, it uses matrix multiplication to calculate the message and parity of the HammingVector.
calls:
 void HammingVector.buildG()
 void HammingVector.buildH()
 void HammingVector.buildR()
 vector HammingVector::matrixCrossVector(vector<vector>, vector)

vector HammingVector.getData()
Returns the instance's data vector

vector HammingVector.getMessage()
Returns the instance's message vector

vector HammingVector.getEMessage()
First, creates a copy of the instance's message. If the instance's parity vector is a zero vector, then a random bit in the copy is flipped and the copy is returned. Else, a bit in the copy is flipped based on the instance's parity vector and the copy is returned.

void printVector(vector)
Prints the given vector to the screen

HammingVector(vector)
Returns a new instance of HammingVector. First, this function checks that the input vector is long enough. Then, given that the vector is indeed long enough, the number of data and parity bits is calculated based on the size of the vector. Then the G, H, and R, matrices are calculated. Then the parity vector is calculated and the message is corrected based on the parity vector. Finally, the data is derived from the corrected message.
calls:
 void HammingVector.buildG()
 void HammingVector.buildH()
 void HammingVector.buildR()
 vector HammingVector::matrixCrossVector(vector<vector>, vector)

vector HammingVector.getParity()
Returns the instance's parity vector

void HammingVector.buildG()
Builds the instance's G matrix (encoding matrix) with a size of totalBits x dataBits.
calls:
 bool HammingVector::isPowerOfTwo(int)

void HammingVector.buildH()
Builds the instance's H matrix (check matrix) with a size of parityBits x totalBits.

void HammingVector.buildR()
Builds the instance's R matrix (decoding matrix) with a size of dataBits x totalBits.
calls:
 bool HammingVector::isPowerOfTwo(int)

vector HammingVector::matrixCrossVector(vector<vector>, vector)
Takes in a matrix of size m x n and vector of size n x 1. Returns a vector of size m x 1. Used to calculate the data, message, and parity vectors.

bool HammingVector::isPowerOfTwo(int)
Returns a boolean indicating whether or not the input is a power of two

Description of testing and verification process

The only part of the program susceptible to error is user input. The expected behavior on invalid input is to print the thrown exception then reprint the input prompt. These input scenarios were tested:

  • input <1 resulted in expected behavior
  • input as NAN resulted in expected behavior
  • input as float resulted in the float getting rounded down and automatically cast to an integer and the program ran without exception

How run it

There are two ways to run this program. Both assume that you have extracted the zip file into an empty folder and are currently in said folder.

  1. Go to .\x64\Debug
  2. Run .\Hamming.exe
  3. Use the program as described in the project description

If unable to to do that for any reason, you may try the following instead.

  1. Open the Visual Studio solution in Visual Studio 2019 (other versions might work, but I make no guarantees)
  2. In Visual Studio, click on Debug > Start Without Debugging
  3. Use the program as described in the project description

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages