Guide Converting Data - UQ-Communication-Systems/public GitHub Wiki
Let's consider the ascii character W
in this example.
input = 'W';
We know that in Hexadecimal this is represented as 0x57
and in decimal as 87
. However, when we want to convert this into bits, the bit ordering is very important. We can have least significant bit (LSB) ordering which means we first send the "least significant bit" and most significant bit ordering (MSB).
LSB bit ordering
In Matlab/Octave we can use the bitget
function to convert the ASCII character into bits.
bits = bitget(input + 0, 1:8);
Note that we needed to convert the string into a number by adding 0
to it, and we want to output bits 1 to 8 in that order. Matlab/Octave always indexes arrays and bits from 1, therefore what normally would be called bit 0-7 is called 1-8. Here is a diagram of the meaning of each of those bits:
If we want to send BPSK information, then this is all we need. However if we want to send QPSK, or 16-QAM data, then we need to group bits into symbols.
For QPSK, we have 2 bits per symbol, and therefore we would send: 3 1 1 1
.
For 16-QAM we would have 4 bits per symbol and therefore we would send: 7 5
.
MSB bit ordering
Similarly for MSB ordering we can use the following functions:
bits = bitget(input + 0, 8:-1:1);
and for the character W
the following outputs will occur:
block
columns 8
a["'W' = 87(dec) = 0x57"]:8
b["0 1 0 1 = 0x5"]:4 c["0 1 1 1 = 0x7"]:4
d["0 1 = 1"]:2 e["0 1 = 1"]:2 f["0 1 = 1"]:2 g["1 1 = 3"]:2
h["0"]:1 i["1"] j["0"] k["1"] l["0"] m["1"] n["1"] o["1"]
As you can see: 2 bits per symbol: 1 1 1 3
and 4 bits per symbol: 5 7