Laptop Radio Receiver

Notes

  1. Work on this assignment individually.
  2. Feel free to ask your TA or your fellow students questions. But don’t share code.
  3. If you find a bug or typo feel free to reach out to me and I’ll fix it.

Download Load Skeleton Code and Wav File.

Read the samples from Wav File

Let’s get started by reading the sample from the WAV file you downloaded earlier. Implement the read_samples_from_wav function. Use Tinywav library https://github.com/mhroth/tinywav to read in the samples. I’ve included the library in skeleton code.

float* read_samples_from_wav(char* path_to_file, int length){
     ........
}

Extract the signal by computing the cross correlation.

We’ll extract the signal by computing the correlation filter (matched filter) [link] with the pulse corresponding to a 1 value. You can use the pulse implementation from HW 1. (If you want my implementation of this function just ask the TA)

float * generate_pulse( bool is_a_one){
    .....
}
float* corrFilter(float* pulse, int pulse_size, float* signal, int total_points){  
      float* output = malloc(total_points * sizeof(float));
      float sum = 0;
      for (int j = 0; j < total_points; j++){
        sum = 0;
        for (int i = 0; i < pulse_size; i++){    
            sum += pulse[i] * signal[j+i];
        }
        output[j] = sum;      
      }
      return output;
    }
    

Once you written this helper functions. Write the function that will convert the samples array into binary string representing the data.

char* binary_from_samples(float* samples, int length){
   .......
}

Binary String to ASCII String.

First implement the binaryToChar function that converts binary string (8 char long) to Ascii char.

char binaryToChar(char *binary, int length){
    int i;
    unsigned long decimal = 0;
    unsigned long weight = 1;
    binary += length - 1;
    weight = 1;
    for(i = 0; i < length; ++i, --binary){
        if(*binary == '1')
            decimal += weight;
        weight *= 2;
    }
    return (char)decimal;
}

Now implement the function that converts the whole binary string to ascii string.

char* ascii_from_binary(char* binary){
  ....
}

Test

Now let’s test you receive download the wav file below. This file contain the encoding for the string “hello”. Make the project and then run the receiver program. You’ll also need to modify you program so that reads an extra parameter which is the length of number of characters contained in file. This wav file contain 5 characters.

make
./receiver "path/to/file" <length> 

Submitting

Great now you’ve worked the bugs out your program Download

Decode wav file and save the contents to file called page.html. The wav file contains 104 characters.

make
./receiver "path/to/file" <length> > page.html

Check that you’ve decoded the file correctly by opening it in your browsers. Upload a screenshot of what your browser displays.