# Question regarding 16 QAM digital modulation

Below is an example of a digital modulation system using 16-QAM. I have copied this example from MATLAB communications toolbox,

   M = 16;                     % Size of signal constellation
k = log2(M);                % Number of bits per symbol
n = 30000;                  % Number of bits to process
numSamplesPerSymbol = 1;    % Oversampling factor
dataIn = randi([0 1],n,1);
dataInMatrix = reshape(dataIn, length(dataIn)/4, 4); % Reshape data into binary 4-tuples
dataSymbolsIn = bi2de(dataInMatrix);
dataMod = qammod(dataSymbolsIn, M);


I am wondering if

1) there is a need to reshape the bits into tuples of 4 bits

2) there is a need to do the mapping from binary to decimal and then do the QAM modulation, couldn't I just have done

dataMod = qammod(dataIn, M);

Thanks.

First of all, I recommend getting familiar with Matlab's doc command. doc qammod has the answers to your second question: qammod requires a vector of integers between 0 and M-1.
Regarding your first question: the reason to reshape your bits into groups of four is that 16-QAM transmits $\log_2(16)=4$ bits per symbol. So, your bi2de command requires binary numbers of four bits to get decimal integers betwen 0 and 15.
If you want to save lines of code, what you could do is generate integers between 0 and 15 directly, with dataSymbolsIn = randi([0 15], n/4, 1). However, doing this has one disadvantage: calculating the bit error rate at the receiver is more complicated if all you have are the integers. Let's say that you transmit a 15 and receive a 13 (obtained with qamdemod), how many bit errors there were? This is why it's common practice to start with actual bits in the transmitter and compare them one-to-one with the received bits.
• @Tyrone You are correct that one always maps bits to symbols. The requirement of having a vector of integers as argument is particular to qammod. Personally, in my simulations I prefer to map groups of bits to the actual analog amplitude that the transmitted signal will have, because this makes it easier to calculate the noise power that results in a specific SNR. – MBaz Apr 14 '15 at 22:59