top of page
Search

Week 3

Dan

Last week I ended with the creation of the u-law function. This week I had tried to get the A-law equilivent working as well. A-law is slightly different in terms of it's encoding scheme, as shown below. It uses 13 bits instead of 14 and there is no zero, since we don't add/subtract 33 to get low values into the range, instead simply using a shorter range.

As with the u-law, the a-law works with signed magnitude values. Also notice that 6th output bit can be zero. What this means is that the code had to be slightly modified to account for that exception. However I had difficulty getting it to work with any values. Then the thought occured...

How do I... test to make sure every input value gives the correct output value? Without spending an incredible amount of time, or just guessing random values and hoping to spot errors?


So, I wrote a function to check every input/ouput value gotten from the u-law compression/decompression, and it turns out the function didn't even convert the first value correctly. When I was testing the function manually in week 2 I had used positive values, turns out the original code was not going to work with negative values. Here is where I realised that I had to work with signed magnitude values rather than hacking a version that worked with two's compliment. I also realised that there was a pattern, that the function could be implemented using bitwise functions.

Two's compliment fundamently represents values different from signed-magnitude - the negative values are *almost* an inverse, with a -1 difference. Also, it's important to realise that representing the same negative value in two's compliment varies depending on the length of the value.

So, I wrote two functions to convert numbers to and from signed magnitude. And by using this function I was able to successfully implement both a-law and u-law compression/decompression functions! Now all I needed was some test data. I recorded myself saying my own name into a microphone and converted the wav file to the correct sampling frequency and bit rate using Audacity. Also, it was becoming clear that using the terminal was getting cumbersome, so I started writting a graphical interface to speed up the testing process.

 
 
 

Recent Posts

See All

Comments


Post: Blog2_Post

©2021 by Data compression project. Proudly created with Wix.com

bottom of page