The purpose of this assignment is to simulate the transmissi

The purpose of this assignment is to simulate the transmission and reception of a text message (ie., character string) over a noisy communications channel. Suppose we wish to transmit the string \"Hello.\" We can translate this string into a bit stream as shown below: String: He l I o. 10 (note: the last character 10 is the null terminator character) ASCII: 72 101 108 108 111 46 0 Binary: 01001000 01 100 101 01 101 100 0110 1100 01101111 00101110 00000000 Notice how this string can be expressed as 8 x 56 bits. Suppose we transmit each of these bits as voltages on an electrical signal (for simplicity, +1.0 V for binary 1 and 0.0 V for binary 0) We can simulate noise by encoding these bits in a double array of length 56 and then adding noise samples to the 1.0 and 0.0 values that will initially be loaded into the array. With a small amount of noise (low SNR), the values in this array for the first character \"H\" may be: 0.0143, 0.9985, -0.00124, 0.1076, 1.00325, 0.00173, 0.0563, 0.00474 With low noise, it is clear that the voltages \"near\" 0 represent binary 0 and the voltages \"near\" 1 represent binary 1. As a general rule, a receiver will take any voltages less than 0.5 and treat them as binary 0 and any voltages greater than or equal to 0.5 and treat them as binary 1 Problem 1: Write a function double message to signal (char message) that accepts a message as a string (appropriately terminated) and returns a dynamically allocated double array that contains the bit stream for this messages (as the values 1.0 for binary 1 and 0.0 for binary 0)

Solution

Answer to Problem 1:

double* message_to_signal (char* message)
{
   int i, j;
   double temp = 0.0;
   char buff[9];
   static double output[800] = {0.0};
   for(i = 0; message[i] != \'\\0\'; i++)
   {
       int value = 0;
       snprintf (buff, sizeof(buff), \"%d\", message[i]);
       for (j=0; buff[j] != \'\\0\'; j++)
       {
           value = value * 10 + (buff[j] - \'0\');  
       }
      
       for (j = 7; j >= 0; --j)
       {
           if((value%2) == 0)
           {
               temp = 0.0;
               value = value/2;
           }
           else
           {
               temp = 1.0;
               value = value/2;
            }
           output[i * 8 + j] = temp;
       }
   }
  
   //Uncomment below for loop to print the values.
   /*for (j = 0; j < i * 8; j++)
   {
       printf(\"%lf \", output[j]);
   }
   printf(\"\ \");*/
   return output;
}

 The purpose of this assignment is to simulate the transmission and reception of a text message (ie., character string) over a noisy communications channel. Sup

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site