A code for the detection and correction of errors was implemented using the Hamming method, this code was made in c ++. Make the code in Matlab, in such a way that the c ++ code is a base, to be able to develop the algorithm or the error detection and correction program using the Hamming method. The algorithm made in c ++ is shown below so that you can develop it in matlab.   #include #include   int main() {         int a[20], b[20], c[20], d[20], i, k, m, f, n, j, r, p, x, y, z, ch,             key, q, v, sum = 0;         system("clear");         printf("\n Ingresa la longitud de la palabra de datos :");         scanf("%d", &k);         printf("\n Ingresa la palabra de datos: \n");         for (i = 1; i <= k; i++) {                  scanf("%d", &a[i]);         }         m = 1;         while ((k + m + 1) >= pow(2, m)) {                  m++;         }         printf("\n El valor de  m es : %d", m);         n = k + m;         j = 1;         r = 0;         for (i = 1; i <= n; i++) {                  p = pow(2, r);                  if (i == p) {                          b[i] = 0;                          r++;                  } else {                          b[i] = a[j];                          j++;                  }         }         printf("\n Palabra código intermedia es: \n");         for (i = 1; i <= n; i++)                  printf("%d", b[i]);         p = 0;         for (i = 1; i <= m; i++) {                  x = pow(2, p);                  r = 1;                  for (j = x; j <= n; j = j + (x * 2)) {                          for (y = j; y < (j + x); y++) {                                   c[r] = b[y];                                   r++;                          }                  }                  z = 0;                  for (y = 1; y <= (r - 1); y++) {                          if (c[y] == 1)                                   z++;                  }                  if (z % 2 == 0)                          b[x] = 0;                  else                          b[x] = 1;                  for (y = 1; y <= 20; y++)                          c[y] = 0;                  p++;         }         printf("\n\n El código hamming es: \n");         for (i = 1; i <= n; i++)                  printf("%d", b[i]);         while (1) {                  printf                      ("\n\n Presiona 1 para cambiar un bit o 0 para salir \n\n");                  scanf("%d", &ch);                  if (ch == 1) {                          printf("\n Ingresa el bit que quieras cambiar: \n");                          scanf("%d", &key);                          for (i = 1; i <= n; i++) {                                   if (i == key) {                                           if (b[key] == 1)                                                    b[key] = 0;                                           else                                                    b[key] = 1;                                           break;                                   }                          }                          printf("\n El nuevo código es: \n\n");                          for (i = 1; i <= n; i++)                                   printf("%d", b[i]);                  } else                          break;         }         p = 0;         q = 0;         for (i = 1; i <= m; i++) {                  x = pow(2, p);                  r = 1;                  for (j = x; j <= n; j = j + (x * 2)) {                          for (y = j; y < (j + x); y++) {                                   c[r] = b[y];                                   r++;                          }                  }                  z = 0;                  for (y = 1; y <= (r - 1); y++) {                          if (c[y] == 1)                                   z++;                  }                  v = z % 2;                  d[q] = v;                  sum = sum + (v * pow(2, q));                  q++;                  for (y = 1; y <= 20; y++)                          c[y] = 0;                  p++;         }         if (sum == 0)                  printf("\n\n Ningún error encontrado....... \n\n");         else                  printf("\n\n Error en la posición %d", sum);         printf("\n");         return 0;

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

A code for the detection and correction of errors was implemented using the Hamming method, this code was made in c ++. Make the code in Matlab, in such a way that the c ++ code is a base, to be able to develop the algorithm or the error detection and correction program using the Hamming method.

The algorithm made in c ++ is shown below so that you can develop it in matlab.

 

#include <stdio.h>

#include <math.h>

 

int main()

{

        int a[20], b[20], c[20], d[20], i, k, m, f, n, j, r, p, x, y, z, ch,

            key, q, v, sum = 0;

        system("clear");

        printf("\n Ingresa la longitud de la palabra de datos :");

        scanf("%d", &k);

        printf("\n Ingresa la palabra de datos: \n");

        for (i = 1; i <= k; i++) {

                 scanf("%d", &a[i]);

        }

        m = 1;

        while ((k + m + 1) >= pow(2, m)) {

                 m++;

        }

        printf("\n El valor de  m es : %d", m);

        n = k + m;

        j = 1;

        r = 0;

        for (i = 1; i <= n; i++) {

                 p = pow(2, r);

                 if (i == p) {

                         b[i] = 0;

                         r++;

                 } else {

                         b[i] = a[j];

                         j++;

                 }

        }

        printf("\n Palabra código intermedia es: \n");

        for (i = 1; i <= n; i++)

                 printf("%d", b[i]);

        p = 0;

        for (i = 1; i <= m; i++) {

                 x = pow(2, p);

                 r = 1;

                 for (j = x; j <= n; j = j + (x * 2)) {

                         for (y = j; y < (j + x); y++) {

                                  c[r] = b[y];

                                  r++;

                         }

                 }

                 z = 0;

                 for (y = 1; y <= (r - 1); y++) {

                         if (c[y] == 1)

                                  z++;

                 }

                 if (z % 2 == 0)

                         b[x] = 0;

                 else

                         b[x] = 1;

                 for (y = 1; y <= 20; y++)

                         c[y] = 0;

                 p++;

        }

        printf("\n\n El código hamming es: \n");

        for (i = 1; i <= n; i++)

                 printf("%d", b[i]);

        while (1) {

                 printf

                     ("\n\n Presiona 1 para cambiar un bit o 0 para salir \n\n");

                 scanf("%d", &ch);

                 if (ch == 1) {

                         printf("\n Ingresa el bit que quieras cambiar: \n");

                         scanf("%d", &key);

                         for (i = 1; i <= n; i++) {

                                  if (i == key) {

                                          if (b[key] == 1)

                                                   b[key] = 0;

                                          else

                                                   b[key] = 1;

                                          break;

                                  }

                         }

                         printf("\n El nuevo código es: \n\n");

                         for (i = 1; i <= n; i++)

                                  printf("%d", b[i]);

                 } else

                         break;

        }

        p = 0;

        q = 0;

        for (i = 1; i <= m; i++) {

                 x = pow(2, p);

                 r = 1;

                 for (j = x; j <= n; j = j + (x * 2)) {

                         for (y = j; y < (j + x); y++) {

                                  c[r] = b[y];

                                  r++;

                         }

                 }

                 z = 0;

                 for (y = 1; y <= (r - 1); y++) {

                         if (c[y] == 1)

                                  z++;

                 }

                 v = z % 2;

                 d[q] = v;

                 sum = sum + (v * pow(2, q));

                 q++;

                 for (y = 1; y <= 20; y++)

                         c[y] = 0;

                 p++;

        }

        if (sum == 0)

                 printf("\n\n Ningún error encontrado....... \n\n");

        else

                 printf("\n\n Error en la posición %d", sum);

        printf("\n");

        return 0;

}

Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY