コード例 #1
0
ファイル: matrix.c プロジェクト: RaVhen/Hamming-project
Matrix encode(Matrix mat){
  Matrix hamming = CreateNewMatrix(4,7);
  init_Hamming(hamming);
  Matrix result = times_Matrix(mat, hamming);
  free_matrix(hamming);
  return (result);
}
コード例 #2
0
ファイル: main.c プロジェクト: quangthanh010290/Linux
int main(int argc, char** argv) {
    Matrix_t m = CreateNewMatrix(10,10);

    //CreateNewMatrix(10,20,&m);
   
    DeleteMatrix(&m);
    return (EXIT_SUCCESS);
}
コード例 #3
0
ファイル: matrix.c プロジェクト: RaVhen/Hamming-project
Matrix decode(Matrix mat){
  Matrix result = CreateNewMatrix(mat.row, mat.col - 3);
  int i,j;
  for(i = 0; i < result.row; i++){
    for(j = 0; j < result.col; j++){
      result.matrix[i][j] = mat.matrix[i][j];
    }
  }
  return result;
}
コード例 #4
0
ファイル: matrix.c プロジェクト: RaVhen/Hamming-project
Matrix convert(int r, int c, int mat[r][c]){
  Matrix result = CreateNewMatrix(r,c);
  int i,j;
  for(i = 0; i < r; i++){
    for(j = 0; j < c; j++){
      result.matrix[i][j] = mat[i][j];
    }
  }
  return result;
}
コード例 #5
0
ファイル: matrix.c プロジェクト: RaVhen/Hamming-project
Matrix random_Matrix(int r, int c){
  Matrix result = CreateNewMatrix(r,c);
  int i,j;
  for(i = 0; i < r; i++){
    for(j = 0; j < c; j++){
      result.matrix[i][j] = rand() % 2;
    }
  }
  return result;
}
コード例 #6
0
ファイル: matrix.c プロジェクト: RaVhen/Hamming-project
Matrix transpose(Matrix mat){
  Matrix result = CreateNewMatrix(mat.col, mat.row);
  int i,j;
  for(i = 0; i < mat.row; i++){
    for(j = 0; j < mat.col; j++){
      result.matrix[j][i] = mat.matrix[i][j];
    }
  }
  return result;
}
コード例 #7
0
ファイル: matrix.c プロジェクト: RaVhen/Hamming-project
Matrix times_Matrix(Matrix mat1, Matrix mat2){
  Matrix result = CreateNewMatrix(mat1.row, mat2.col);
  int i,j;
  int n,k,sum;
  for(i = 0; i < result.row; i++){
    for(j = 0; j < result.col; j++){
      sum = 0;
      for(n = 0; n < mat1.col; n++){
	sum += mat1.matrix[i][n] * mat2.matrix[n][j];
      }
      result.matrix[i][j] = sum % 2;
    }
  }
  
  return result;
}
コード例 #8
0
ファイル: matrix.c プロジェクト: RaVhen/Hamming-project
Matrix noise(Matrix mat, double d){
  Matrix result = CreateNewMatrix(mat.row, mat.col);
  copy_Matrix(mat, result);
  int i,j,count;
  count = 0;
  for(i = 0; i < result.row; i++){
    for(j = 0; j < result.col; j++){
      double r = (double)rand() / (double)RAND_MAX;
      if(r < d){
	result.matrix[i][j] = (result.matrix[i][j] + 1) % 2;
	count++;
      }
    }
  }
  /*printf("Alterate %d bits in message\n", count);*/
  return result;
}
コード例 #9
0
ファイル: matrix.c プロジェクト: RaVhen/Hamming-project
Matrix correct(Matrix mat, Matrix hmat){
  Matrix error = times_Matrix(hmat, transpose(mat));
  Matrix result = CreateNewMatrix(mat.row, mat.col);
  copy_Matrix(mat, result);
  if(error.matrix[0][0] == 0
     && error.matrix[1][0] == 0
     && error.matrix[2][0] == 0){
    /*printf("No error(s) found in the message\n");*/
  }
  else{
    /*printf("Error(s) found in message, correcting ...\n");*/
    int pos = (error.matrix[0][0] * 4) +
      (error.matrix[1][0] * 2) +
      (error.matrix[2][0] * 1) - 1;
    result.matrix[0][pos] = (result.matrix[0][pos] + 1) % 2;  
  }
  free_matrix(error);
  return result;
}