1 %% Common transmitter code
3 data_in_b = logical(randi([0 1],[log2(M) N]));
4 data_in_s = bits2symb(data_in_b,M);
5 % data_in_s = randi(M,[N 1],
'uint16'); % Generate data (symbols 1:M obtained from converting binary data)
6 [c,P] = constref(
'QAM',M); % Generate reference constellation
7 [map,demap] = constmap(
'QAM',M,
'gray'); % Create Gray constellation map/demap
11 %% Version with constellation map encoding
12 c_enc = c(map); % Encode constellation
13 tx_data = c_enc(data_in_s); % Map symbols to constellation points
14 rx_data = tx_data; % Transmit
15 data_out_s =
hd_euclid(rx_data,c_enc); % Hard decision mapping of constellation points to symbols
16 data_out_b = symb2bits(data_out_s,M);
17 if any(xor(data_in_b,data_out_b))
18 warning('Data different.');
20 fprintf(1,'Data the same.\n');
25 %% Version with symbols mapped to transmitted symbols
26 % Map data to symbols. For linear mapping, map == demap = 1:M;
27 tx_symbols = map(data_in_s);
28 tx_data = c(tx_symbols); % Map symbols to constellation points
29 rx_data = tx_data; % Transmit
30 rx_symbols =
hd_euclid(rx_data,c); % Hard decision mapping of constellation points to symbols
31 data_out_s = demap(rx_symbols); % Demap symbols to data
32 data_out_b = symb2bits(data_out_s,M);
33 if any(xor(data_in_b,data_out_b))
34 warning('Data different.');
36 fprintf(1,'Data the same.\n');
41 %% Version with averaged constellation power
42 c_norm = c/sqrt(P); % Normalize constellation
43 % Map data to symbols. For linear mapping, map == demap = 1:M;
44 tx_symbols = map(data_in_s);
45 tx_data = c_norm(tx_symbols); % Map symbols to constellation points
46 rx_data = tx_data; % Transmit
47 rx_data_norm =
pwr.normpwr(rx_data); % Normalize received constellation
48 rx_symbols =
hd_euclid(rx_data_norm,c_norm); % Hard decision mapping of constellation points to symbols
49 data_out_s = demap(rx_symbols); % Demap symbols to data
50 data_out_b = symb2bits(data_out_s,M);
51 if any(xor(data_in_b,data_out_b))
52 warning('Data different.');
54 fprintf(1,'Data the same.\n');
function hd_euclid(in X, in c)
Euclidean metric hard decision digital demodulation.