Robochameleon  v1.0
constutils_example.m
1 %% Common transmitter code
2 M = 16; N = 100;
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
8 
9 %return;
10 
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.');
19 else
20  fprintf(1,'Data the same.\n');
21 end
22 
23 return;
24 
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.');
35 else
36  fprintf(1,'Data the same.\n');
37 end
38 
39 
40 
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.');
53 else
54  fprintf(1,'Data the same.\n');
55 end
power description class
Definition: pwr.m:27
function hd_euclid(in X, in c)
Euclidean metric hard decision digital demodulation.