This week I coded the analogue version of μ-law. Implementing this in matlab caused some problems. For one, implementing the equation below in matlab requires multiple per element multiplication and it can get tricky when you can use normal operations and when per element operations are required.

It also becomes cumbersome for matlab to produce a new figure for each graph, so used the tiledlayout(x,y) function to have all 6 graphs produced be laid out in the same figure.

We can see what mu function is doing: amplifying smaller values and attenuating larger values, resulting the in the 2 waves marked "mu waveform" and "q mu waveform". In order to investigate how quantisation would affect the waveform I quantised the input waveform, the waveform after mu transform and the output result. The difference betweeen quantisation before and after was neglible.
I also notice that an almost pefect representation of the input could be recreated at the output, with the largest error between the two equal to 0.000118, insignificant. To test the compression decompression as it is used in real life, I needed to implemented the digital version.
Looking on the wikipedia page for the mu law, I found this table of input vs output values

There are some things to note. For one, the linear input value (and output value) are expressed as signed magnitude representation, Essentially the most significant bit represents a plus (0) or a minus (1). the rest is identical to the two's compliment value expressed as a positive number (this means that there are two ways to represent zero). 33 is also added, to the magnitude, so that low values are recorded as non-zero. Also the x's represent don't care values: essentially we ignore any values 5 away from the first 1 in the binary number.
Initially the implementation was done using the same technique as above, performing a function on the entire matrix, but this proved to be difficult to do especially taking into consideration negative values. Thus I implemented it via bitwise functions, seemingly with success.
Comentarios