Sunday, 30 June 2019

Quantisation - Sampling the signal

I'm sure we have all heard of the concept of sampling, namely where we convert an analogue sound into digital sound. Actually, this was something that was bandied about when I was much younger, and seemed to refer to when you would take parts of songs and then meld them together to create a different song, much in the way many of the electronic musicians would do. However, in the world of data comms it is where we convert an analogue signal into a digital signal, and it usually involves sound, namely because that is the easiest.

Actually, the best way to describe how it is done is to actually show you, so let us consider the graph below (from my lecture notes, though I not will mention that from this point on, if I don't source the image, then it is either public domain, or from my lecture notes):

Actually, it looks as if it came from wikipedia: By Aquegg - Own work, CC BY-SA 3.0,
What we see above is an analogue signal with a number of blue spots on it. These spots are where we are mapping the signal. Now the whole idea of this is to digitise the signal, send it across some medium, and then when we reach the other end reproduce it as faithfully as possible.

So, the signal is being mapped as above, and at each of the points we make a record of where the signal is on the graph. As we can see, the bit level is actually 16 bits, so each of the points are translated as follows: -4, 0, 4, 7, 6, 3, 0, -1 ...

Now, I should mention sensitivity - basically that involves how close to the original signal we actually are - the greater the bit depth the more accurate the signal. I'm not sure if you actually know what a ruler is, but it is basically a length of wood (or plastic, or metal) that has two straight edges and a series of markings along the side. As well as being used to draw margins down the side of our paper in primary school, rulers were also used to measure length. Now, the sensitivity of the ruler was determined by how far apart the notches were. So, a ruler where the notches were half a centimetre apart was a lot less sensitive than a ruler where the notches were a millimetre apart.


So, once we have sampled the data, we can then convert it into 0s and 1s, but this is automatically done by our computers, the only reason we would do this is if we were writing something down on paper, or doing something a lot more detailed than simply writing a program using javascript.

However, this brings us to another problem, and that is called quantisation error, or sampling error. Basically, depending on how sensitive our readings are, we may not actually be able to sample the sound as perfectly as we will like. In fact in some cases it might actually be off somewhat. The problem is that the more sensitive the sampling is, the more bit depth is required, and the deeper the bit depth, the larger the amount of data that will be produced. As such, there needs to be a trade off - smaller files produced a lesser quality while a greater quality produces larger files.


Now that we have sampled the sounds, it is time to transmit the sound across the medium. Once again we have this trade off - for a better, and faster, transmission we need a greater bandwidth, but greater bandwidth leads to greater cost. Yet, if we lower the costs by lowering the bandwidth, we produce not so much less quality sound, but also distortion. Look, that is probably not too problematic if we aren't listening to the sounds live, since we can buffer it, but when it comes to live transmissions, then we need the higher bandwidth.

The next problem we need to consider is how often we sample the sine wave. Consider the graphs below:


Looking above we can see if we take a sample every half frequency we basically get absolutely nothing. If we take it 2/3 of the frequency, we can something but it looks like it is simply going to be a jumble of noise. Looking at the next one, I'm not sure if the 'wave frequency' is correct, because if we took it at the wave frequency, it would be the same the half frequency. What looks like is being done here, is that it is being taken at four times the frequency, and the next one at eight times the frequency. Here we are getting a much better sample, though obviously the more we sample, the better we get, but the problem of the trade off then arises in that the more we sample, the larger the amount of data that is produced.

In fact, the sampling rate is also measured in hz, being the number of samples per second. So, once again, the greater the number of samples that are taken, the better the quality. The standard sampling rate is something along the lines 44,100 hz.

Finally, we have interpolation, which is the way that the sound is turned back into an analogue form. Now, if we simply relied on the sampling levels, we would get a blocky, and rather horrid, sound. So, interpolation is an algorithm that is used to make the wave as smooth as possible to reproduce the sound in the best way possible.

Oh, before I finish off, let us go back to our sampling at the beginning where we got the numbers: -4, 0, 4, 7, 6, 3, 0, -1.

Now, the next step is to write them down as positive numbers, so we will have 4, 8, 12, 15, 14, 11, 8, 7. Now that we have done that, we convert them into binary, however because the graph went from -ve to +ve, once we have done that we need to then place another bit in front of them where 0 represents negative, and 1 represents positive.

Creative Commons License

Quantisation - Sampling the signal by David Alfred Sarkies is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. This license only applies to the text and any image that is within the public domain. Any images or videos that are the subject of copyright are not covered by this license. Use of these images are for illustrative purposes only are are not intended to assert ownership. If you wish to use this work commercially please feel free to contact me

No comments:

Post a Comment