-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTransmit_diversity_precoding.m
133 lines (104 loc) · 4.61 KB
/
Transmit_diversity_precoding.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
function [y_PxC_ts] = Transmit_diversity_precoding(x_PxC_ss, N_TS)
% Technical Specification assumes first index is 0, matlab 1
MATLAB_INDEX_SHIFT = 1;
% sanity check
if ismember(N_TS, [2,4,8]) == false
error('For transmit diversity coding N_TS must be 2, 4 or 8.');
end
% always 98 elements in case of PCC
x_PxC_ss = cell2mat(x_PxC_ss);
n_x_PxC_ss = numel(x_PxC_ss);
% sanity check
if mod(n_x_PxC_ss,2) ~= 0
error('Number of PxC symbols in spatial stream is not a multiple of 2.');
end
% how many pairs of symbols do we have?, see 6.3.3.2
i_max = n_x_PxC_ss/2;
% modulo according to Table 6.3.3.2-1 to 6.3.3.2-3
switch N_TS
case 2
modulo = 1;
case 4
modulo = 6;
case 8
modulo = 12;
end
% create vector of pairs (split real and imag) as shown in 6.3.3.2
x_PxC_real = reshape(real(x_PxC_ss), 2, i_max);
x_PxC_imag = reshape(imag(x_PxC_ss), 2, i_max);
pair_of_symbols_vec = [x_PxC_real; x_PxC_imag];
% load precoding matrix in cells
[Y, ~, ~] = lib_6_generic_procedures.Transmit_diversity_precoding_Y(N_TS);
[row,col,page] = size(Y);
% this block of code is optimized for fast calculation, for-loop below can be used instead
pair_of_symbols_vec_serial = reshape(pair_of_symbols_vec,1,numel(pair_of_symbols_vec));
pair_of_symbols_vec_serial = repmat(pair_of_symbols_vec_serial,row,1);
Y_serial = reshape(Y, row, col*page);
Y_serial = repmat(Y_serial, 1, ceil(numel(pair_of_symbols_vec)/(col*page)));
Y_serial = Y_serial(:,1:size(pair_of_symbols_vec_serial,2));
y_PxC_ts = pair_of_symbols_vec_serial.*Y_serial;
y_PxC_ts = y_PxC_ts.';
y_PxC_ts = reshape(y_PxC_ts,4,[]);
y_PxC_ts = sum(y_PxC_ts,1);
y_PxC_ts = reshape(y_PxC_ts,[],row);
y_PxC_ts = y_PxC_ts.';
% % compatible, but much slower code
% if 1==1
% % preallocate output
% y_PxC_ts_check = zeros(2*N_TS,i_max);
%
% % symbol by symbol
% for i=0:1:i_max-1
%
% % load correct Y matrix
% i_mod = mod(i,modulo);
% Y_mod = Y(:,:,i_mod+MATLAB_INDEX_SHIFT);
%
% % multiply
% i_matlab = i + MATLAB_INDEX_SHIFT;
% y_PxC_ts_check(:,i_matlab) = Y_mod*pair_of_symbols_vec(:,i_matlab);
% end
%
% diff = abs(y_PxC_ts - y_PxC_ts_check);
% if max(diff) > 10e-6
% error('y_PcX not equal.');
% end
% end
% rearrange output and convert to cell
switch N_TS
case 2
y_PxC_TS_0 = y_PxC_ts([1,3],:);
y_PxC_TS_0 = reshape(y_PxC_TS_0,numel(y_PxC_TS_0),1);
y_PxC_TS_1 = y_PxC_ts([2,4],:);
y_PxC_TS_1 = reshape(y_PxC_TS_1,numel(y_PxC_TS_1),1);
y_PxC_ts = {y_PxC_TS_0, y_PxC_TS_1};
case 4
y_PxC_TS_0 = y_PxC_ts([1,5],:);
y_PxC_TS_0 = reshape(y_PxC_TS_0,numel(y_PxC_TS_0),1);
y_PxC_TS_1 = y_PxC_ts([2,6],:);
y_PxC_TS_1 = reshape(y_PxC_TS_1,numel(y_PxC_TS_1),1);
y_PxC_TS_2 = y_PxC_ts([3,7],:);
y_PxC_TS_2 = reshape(y_PxC_TS_2,numel(y_PxC_TS_2),1);
y_PxC_TS_3 = y_PxC_ts([4,8],:);
y_PxC_TS_3 = reshape(y_PxC_TS_3,numel(y_PxC_TS_3),1);
y_PxC_ts = {y_PxC_TS_0; y_PxC_TS_1; y_PxC_TS_2; y_PxC_TS_3};
case 8
y_PxC_TS_0 = y_PxC_ts([1,9],:);
y_PxC_TS_0 = reshape(y_PxC_TS_0,numel(y_PxC_TS_0),1);
y_PxC_TS_1 = y_PxC_ts([2,10],:);
y_PxC_TS_1 = reshape(y_PxC_TS_1,numel(y_PxC_TS_1),1);
y_PxC_TS_2 = y_PxC_ts([3,11],:);
y_PxC_TS_2 = reshape(y_PxC_TS_2,numel(y_PxC_TS_2),1);
y_PxC_TS_3 = y_PxC_ts([4,12],:);
y_PxC_TS_3 = reshape(y_PxC_TS_3,numel(y_PxC_TS_3),1);
y_PxC_TS_4 = y_PxC_ts([5,13],:);
y_PxC_TS_4 = reshape(y_PxC_TS_4,numel(y_PxC_TS_4),1);
y_PxC_TS_5 = y_PxC_ts([6,14],:);
y_PxC_TS_5 = reshape(y_PxC_TS_5,numel(y_PxC_TS_5),1);
y_PxC_TS_6 = y_PxC_ts([7,15],:);
y_PxC_TS_6 = reshape(y_PxC_TS_6,numel(y_PxC_TS_6),1);
y_PxC_TS_7 = y_PxC_ts([8,16],:);
y_PxC_TS_7 = reshape(y_PxC_TS_7,numel(y_PxC_TS_7),1);
y_PxC_ts = {y_PxC_TS_0; y_PxC_TS_1; y_PxC_TS_2; y_PxC_TS_3; y_PxC_TS_4; y_PxC_TS_5; y_PxC_TS_6; y_PxC_TS_7};
end
end