Hello,
I want to use Hamming Code to correct any BER's that I have streaming from a text file.
The contents of my text file are as follows:
0 0 1 0 1 1 0 0 0 1 0 1 1 1 1 1 1 0 0 0 0 1 1 0 0 1 1 0 0 1 1 1 1 0 0 0 0 1 0 1 1 0 .
I want to split them up into 6 different 7x1 vectors so that each element in my vector (e.g. c2i1[7][1]) contains the corresponding element from the text file.
Ultimately, the 7x1 vector will be multiplied by 3x7 Hamming parity matrix (e.g. G[3][7]) and use the mod-2 (%2) to find where the error is, if there is any. After the BER's are corrected I want to translate it into ASCII and display the word.
This is what I have so far:
#include <stdio.h>
#include "conio.h"
#include <string.h>
#include <math.h>
int main()
{
FILE *pFile;
int c2i1[7][1], c2i2[7][1], c2i3[7][1], c2i4[100][1], c2i5[100][1], c2i6[100][1]; //char to int arrays
int c, i=0, j=7, k=14, l=21, m=28, n=35; //counters
int p1[3][1], p2[3][1], p3[3][1], p4[3][1], p5[3][1], p6[3][1]; //Parity check Matrix
/*Hamming Generator Matrix*/
int G[3][7] = {{1,0,1,0,1,0,1}, {0,1,1,0,0,1,1}, {0,0,0,1,1,1,}};
/*Opens file*/
pFile = fopen("data_streamF.txt", "r");
/*Prints stream on screen*/
/*printf("This is the incoming stream:\n");
c = fgetc(pFile);
while (c != EOF)
{
printf("%c", c);
c = fgetc(pFile);
}
printf("\n");
/*Prints the first 7 bits*/
printf("These are the first 7 bits:\n");
while ( !feof (pFile) && i<7 )
{
fscanf(pFile, "%d", &c2i1[i][0]);
printf("%d ", c2i1[i][0]);
i++;
}
printf("\n");
printf("These are the second 7 bits:\n");
/*Prints the second 7 bits*/
while (!feof (pFile) && j<14)
{
fscanf(pFile, "%d", &c2i2[j-7][0]);
printf("%d ", c2i2[j-7][0]);
j++;
}
printf("\n");
/*Prints the third 7 bits*/
printf("These are the third 7 bits:\n");
while (!feof (pFile) && k<21)
{
fscanf(pFile, "%d", &c2i3[k-14][0]);
printf("%d ", c2i3[k-14][0]);
k++;
}
printf("\n");
/*Prints the fourth 7 bits*/
printf("These are the fourth 7 bits:\n");
while (!feof (pFile) && l<28)
{
fscanf(pFile, "%d", &c2i4[l-21][0]);
printf("%d ", c2i4[l-21][0]);
l++;
}
printf("\n");
/*Prints the fifth 7 bits*/
printf("These are the fifth 7 bits:\n");
while (!feof (pFile) && m<35)
{
fscanf(pFile, "%d", &c2i5[m-28][0]);
printf("%d ", c2i5[m-28][0]);
m++;
}
printf("\n");
/*Prints the fifth 7 bits*/
printf("These are the sixth 7 bits:\n");
while (!feof (pFile) && n<42)
{
fscanf(pFile, "%d", &c2i6[n][0]);
printf("%d ", c2i6[n][0]);
n++;
}
printf("\n\n");
/*for(i=0; i<7; i++)
{
for (j=0; j<2 ; j++)
{
p1[j][0] = (c2i1[i][0]*G[0][i]);
if (p1[j][0 ]%2 == 0)
printf("No bit error");
}
}
*/
fclose(pFile);
_getch();
return 0;
}