Example #1
0
void test_is_correctible () {
  int row, col;

  assert (is_correctible(INPUT2, 4, &row, &col) != 0);
  assert (row == 2);
  assert (col == 3);
  
  assert (is_correctible(INPUT3, 4, &row, &col) == 0);
}
Example #2
0
int main () {
  int m[MAX][MAX];

  do {
    int n, i, j;
    scanf ("%d", &n);
    if (0 == n) 
      break;

    /* read the matrix */
    for (i = 0; i < n; i++) {
      for (j = 0; j < n; j++) {
        scanf ("%d ", &(m[i][j]));
      }
    }

    if (has_parity(m, n)) {
      printf ("OK\n");
    } else {
      int row, col;
      if (is_correctible(m, n, &row, &col)) {
        printf ("Change bit (%d,%d)\n", row, col);
      } else {
        printf ("Corrupt\n");
      }
    }
  } while (1);

  return 0;
}
Example #3
0
File: main.c Project: mjftw/CubeSat
//uses is_correctible instead of the actual reed_solomon codec to make it faster
float message_pass_rate_sim(int num_errors_min, int tries_max, float BER, int t)
{
  int successes = 0;
  int errors = 0;
  int tries = 0;

  while(errors < num_errors_min)
  {

    raw_data rd;
    rd.length = 128 + 2*t;
    rd.data = (uint8_t*)alloc_named(rd.length, "message_pass_rate_sim rd");
    unsigned int i;
    for(i = 0; i < rd.length; i++)
      rd.data[i] = rand();

    raw_data ep = convolute(rd);

    //interleaving not needed as errror insertion is AWGN- faster to not do it
    //interleave(ep);  //interleaves data in place

    insert_errors2(ep.data, ep.length, BER);

    //deinterleave(ep);

    raw_data deconvoluted = deconvolute(ep, NULL);

    if(is_correctible(rd, deconvoluted, t, 0))
    {
      successes++;
    }
    else
    {
      errors++;
    }

    dealloc(ep.data);
    dealloc(deconvoluted.data);
    dealloc(rd.data);
    if(tries >= tries_max)
      break;

    tries++;
  }
  return (float)successes / ((float)successes + (float)errors);
}
Example #4
0
File: main.c Project: mjftw/CubeSat
//tests the methods used encoding and decoding, uses insert_errors2 to accomodate any bit rate
float message_pass_rate(int num_tests, float BER)
{
  int successes = 0;
  int errors = 0;
  int tries = 0;
  int wrong1 = 0, wrong2 = 0;
  //for(unsigned int i = 0; i < num_tests; i++)
  while(errors < 100)
  {

    raw_data rd;
    rd.length = 64;
    rd.data = (uint8_t*)alloc_named(rd.length, "message_pass_rate rd");
    unsigned int i;
    for(i = 0; i < 64; i++)
      rd.data[i] = rand();

    int t = 2;  //PYTHON//

    //p = make_packet(rd);
    //encoded_packet ep = encode(&p);  //currently convolutional- subject to change

    raw_data rs_encoded = rs_encode(rd, t);
    raw_data ep = convolute(rs_encoded);

    interleave(ep);  //interleaves data in place

    insert_errors2(ep.data, ep.length, BER);

    deinterleave(ep);

    raw_data deconvoluted = deconvolute(ep, NULL);

    int isc = is_correctible(rs_encoded, deconvoluted, t, 0);

    raw_data decoded;
    rs_decode(deconvoluted, &decoded, t, NULL);

    //q = decode(ep, NULL);
    if(rd.length != decoded.length)
    {
      printf("lengths are not the same!\n");
      printf("rd.length = %i, decoded.length = %i\n", rd.length, decoded.length);
    }
    if(!memcmp(decoded.data, rd.data, rd.length))
    {
      if(!isc)
        wrong1++;
      //if(!isc)
      //  is_correctible(rs_encoded, deconvoluted, t, 1);
      //assert(isc);
      successes++;
    }
    else
    {
      if(isc)
        wrong2++;
      //assert(!isc);
      errors++;
    }

    dealloc(ep.data);
    dealloc(rs_encoded.data);
    dealloc(deconvoluted.data);
    dealloc(decoded.data);
    dealloc(rd.data);
    if(tries >= num_tests)
    {
      printf("tries = %i, errors = %i\n", tries, errors);
      break;
    }
    tries++;
  }
  //return (float)successes / (float)num_tests;
  printf("wrong1 = %i\n", wrong1);
  printf("wrong2 = %i\n", wrong2);
  printf("tests = %i\n", successes + errors);
  return (float)successes / ((float)successes + (float)errors);
}