-
Notifications
You must be signed in to change notification settings - Fork 0
/
hNRCustomScheduler.m
277 lines (257 loc) · 14.5 KB
/
hNRCustomScheduler.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
classdef hNRCustomScheduler < hNRScheduler
%hCustomScheduler Implements custom scheduling strategy.
% The class implements round-robin scheduling strategy without
% support for retransmissions. Each user equipment (UE) gets every
% 'N'th resource block group (RBG) in the bandwidth, where 'N' is the
% number of UEs in the cell. Uplink and downlink scheduling assigns
% RBGs to a UE only if there is non-zero buffer amount for the UE in
% the corresponding direction. The class implements FDD mode
% scheduling.
% Copyright 2021 The MathWorks, Inc.
properties(Access = private)
% NumUEs Number of UEs in the cell
NumUEs;
% CurrHarqUL Last HARQ ID used for uplink direction
% 1-by-N cell array where 'N' is the number of UEs. Value at index
% 'i' indicates the HARQ ID of the last UL HARQ process used for UE
% with RNTI as 'i'
CurrHarqUL;
% CurrHarqDL Last HARQ ID used for downlink direction
% 1-by-N cell array where 'N' is the number of UEs. Value at index
% 'i' indicates the HARQ ID of the last DL HARQ process used for UE
% with RNTI as 'i'
CurrHarqDL;
StandardRate=[1,2,4,1000];
end
methods
function obj = hNRCustomScheduler(simParameters)
% Construct an instance of this class
% Invoke the super class constructor to initialize the properties
obj = obj@hNRScheduler(simParameters);
obj.NumUEs = length(obj.UEs); % Number of UEs in the cell
obj.CurrHarqUL = -1 * ones(1, obj.NumUEs); % Initialize current UL HARQ process ID
obj.CurrHarqDL = -1 * ones(1, obj.NumUEs); % Initialize current DL HARQ process ID
end
end
methods(Access = protected)
function uplinkGrants = scheduleULResourcesSlot(obj, slotNum)
%scheduleULResourcesSlot Schedule UL resources of a slot
% UPLINKGRANTS = scheduleULResourcesSlot(OBJ, SLOTNUM)
% assigns UL resources of the slot, SLOTNUM. UPLINKGRANTS are
% returned as output to convey the resource assignment by
% uplink scheduler using custom scheduling strategy for
% different UEs.
%
% SLOTNUM is the slot number in the 10 ms frame whose UL
% resources are getting scheduled.
%
% UPLINKGRANTS is a cell array where each cell-element is a
% structure representing an uplink grant and has the
% following fields:
%
% RNTI Uplink grant is for this UE
%
% Type Assignment is for new transmission ('newTx')
%
% HARQID Selected uplink UE HARQ process ID
%
% RBGAllocationBitmap Frequency-domain resource assignment.
% A bitmap of RBGs of the PUSCH bandwidth.
% Value 1 indicates RBG is assigned to
% the UE
%
% StartSymbol Start symbol of time-domain resources. Assumed to be
% 0 as time-domain assignment granularity is kept as
% full slot
%
% NumSymbols Number of symbols allotted in time-domain
%
% SlotOffset Slot-offset of PUSCH assignments for upcoming slot
% w.r.t the current slot
%
% MCS Selected modulation and coding scheme for UE with
% respect to the resource assignment done
%
% NDI New data indicator flag
%
% DMRSLength DM-RS length
%
% MappingType Mapping type
%
% NumLayers Number of transmission layers
%
% NumAntennaPorts Number of antenna ports
%
% TPMI Transmitted precoding matrix indicator
%
% NumCDMGroupsWithoutData Number of DM-RS code division multiplexing (CDM) groups without data
% Calculate offset of the slot to be scheduled, from the
% current slot
if slotNum >= obj.CurrSlot % Slot to be scheduled is in the current frame
slotOffset = slotNum - obj.CurrSlot;
else % Slot to be scheduled is in the next frame
slotOffset = (obj.NumSlotsFrame + slotNum) - obj.CurrSlot;
end
uplinkGrants = cell(1, obj.NumUEs); % Array of uplink grants
grantIndex = 0; % Grant index
for i = 1: obj.NumUEs % For each UE
if(sum(obj.BufferStatusUL(i, :)) > 0)
grantIndex = grantIndex + 1; % Increment grant index
uplinkGrants{grantIndex}.RNTI = i;
uplinkGrants{grantIndex}.Type = 'newTx';
uplinkGrants{grantIndex}.RBGAllocationBitmap = zeros(1,obj.NumRBGsUL);
% Modified
jump = int16(obj.NumRBGsUL/obj.StandardRate(i));
if(jump==0)
jump=1;
end
disp(i);
uplinkGrants{grantIndex}.RBGAllocationBitmap(i:jump:obj.NumRBGsUL) = 1; % ith RBG is assigned to ith UE
disp(uplinkGrants{grantIndex}.RBGAllocationBitmap);
%disp(uplinkGrants{grantIndex}.RBGAllocationBitmap);
uplinkGrants{grantIndex}.StartSymbol = 0;
uplinkGrants{grantIndex}.NumSymbols = 14;
uplinkGrants{grantIndex}.SlotOffset = slotOffset;
uplinkGrants{grantIndex}.MappingType = 'A';
uplinkGrants{grantIndex}.DMRSLength = 1;
uplinkGrants{grantIndex}.NumLayers = 1;
uplinkGrants{grantIndex}.NumCDMGroupsWithoutData = 2;
uplinkGrants{grantIndex}.NumAntennaPorts = 1;
% Convert RBGBitmap to corresponding RB indices
rbSet = convertRBGBitmapToRBs(obj,uplinkGrants{grantIndex}.RBGAllocationBitmap,1); % Uplink
% Obtain the measured CQI index for corresponding UE
ueCQI = obj.CSIMeasurementUL(i).CQI;
% Average the CQI index corresponding to the grant allocation
avgCQIGrantRBs = mean(ueCQI(rbSet+1));
% Map the average CQI index in MCS table to obtain corresponding MCS index
uplinkGrants{grantIndex}.MCS = getMCSIndex(obj,floor(avgCQIGrantRBs)-1);
uplinkGrants{grantIndex}.TPMI = 0;
uplinkGrants{grantIndex}.RV = 0;
obj.CurrHarqUL(i) = mod(obj.CurrHarqUL(i) + 1, obj.NumHARQ);
uplinkGrants{grantIndex}.HARQID = obj.CurrHarqUL(i);
uplinkGrants{grantIndex}.NDI = ~obj.HarqNDIUL(i,obj.CurrHarqUL(i) + 1); % Toggle NDI to indicate new transmission
end
end
uplinkGrants = uplinkGrants(1:grantIndex);
end
function downlinkGrants = scheduleDLResourcesSlot(obj, slotNum)
%scheduleDLResourcesSlot Schedule DL resources of a slot
% DOWNLINKGRANTS = scheduleDLResourcesSlot(OBJ, SLOTNUM)
% assigns DL resources of the slot, SLOTNUM. DOWNLINKGRANTS
% are returned as output to convey the resource assignment by
% downlink scheduler using custom scheduling strategy for
% different UEs.
%
% SLOTNUM is the slot number in the 10 ms frame whose DL
% resources are getting scheduled.
%
% DOWNLINKGRANTS is a cell array where each cell-element is a
% structure representing a downlink grant and has the
% following fields:
%
% RNTI Downlink grant is for this UE
%
% Type Assignment is for new transmission ('newTx')
%
% HARQID Selected downlink HARQ process ID
%
% RBGAllocationBitmap Frequency-domain resource assignment.
% A bitmap of RBGs of the PDSCH bandwidth.
% Value 1 indicates RBG is assigned to
% the UE
%
% StartSymbol Start symbol of time-domain resources
%
% NumSymbols Number of symbols allotted in time-domain
%
% SlotOffset Slot offset of PDSCH assignment
% w.r.t the current slot
%
% MCS Selected modulation and coding scheme for UE with
% respect to the resource assignment done
%
% NDI New data indicator flag
%
% FeedbackSlotOffset Slot offset of PDSCH ACK/NACK from
% PDSCH transmission slot (i.e. k1).
% Currently, only a value >=2 is supported
%
% DMRSLength DM-RS length
%
% MappingType Mapping type
%
% NumLayers Number of transmission layers
%
% NumCDMGroupsWithoutData Number of CDM groups without data (1...3)
%
% PrecodingMatrix Selected precoding matrix.
% It is an array of size NumLayers-by-P-by-NPRG, where NPRG is the
% number of precoding resource block groups (PRGs) in the carrier
% and P is the number of CSI-RS ports. It defines a different
% precoding matrix of size NumLayers-by-P for each PRG. The effective
% PRG bundle size (precoder granularity) is Pd_BWP = ceil(NRB / NPRG).
% For SISO, set it to 1
% Calculate offset of the slot to be scheduled, from the
% current slot
if slotNum >= obj.CurrSlot % Slot to be scheduled is in the current frame
slotOffset = slotNum - obj.CurrSlot;
else % Slot to be scheduled is in the next frame
slotOffset = (obj.NumSlotsFrame + slotNum) - obj.CurrSlot;
end
downlinkGrants = cell(1,obj.NumUEs); % Array of downlink grants
grantIndex = 0; % Grant index
for i = 1: obj.NumUEs % For each UE
if(sum(obj.BufferStatusDL(i, :)) > 0)
grantIndex = grantIndex + 1; % Increment grant index
downlinkGrants{grantIndex}.RNTI = i;
downlinkGrants{grantIndex}.Type = 'newTx';
downlinkGrants{grantIndex}.RBGAllocationBitmap = zeros(1,obj.NumRBGsDL);
downlinkGrants{grantIndex}.RBGAllocationBitmap(i:obj.NumUEs:obj.NumRBGsDL) = 1; % ith RBG is assigned to ith UE
downlinkGrants{grantIndex}.StartSymbol = 0;
downlinkGrants{grantIndex}.NumSymbols = 14;
downlinkGrants{grantIndex}.SlotOffset = slotOffset;
downlinkGrants{grantIndex}.MappingType = 'A';
downlinkGrants{grantIndex}.DMRSLength = 1;
downlinkGrants{grantIndex}.NumLayers = 1;
downlinkGrants{grantIndex}.NumCDMGroupsWithoutData = 2;
downlinkGrants{grantIndex}.PrecodingMatrix = 1;
% Convert RBGBitmap to corresponding RB indices
rbSet = convertRBGBitmapToRBs(obj,downlinkGrants{grantIndex}.RBGAllocationBitmap,0); % Downlink
% Obtain the measured CQI index for corresponding UE
ueCQI = obj.CSIMeasurementDL(i).CQI;
% Average the CQI index corresponding to the grant allocation
avgCQIGrantRBs = mean(ueCQI(rbSet+1));
% Map the average CQI index in MCS table to obtain corresponding MCS index
downlinkGrants{grantIndex}.MCS = getMCSIndex(obj,floor(avgCQIGrantRBs)-1);
downlinkGrants{grantIndex}.FeedbackSlotOffset = 2;
downlinkGrants{grantIndex}.RV = 0;
obj.CurrHarqDL(i) = mod(obj.CurrHarqDL(i) + 1, obj.NumHARQ);
downlinkGrants{grantIndex}.HARQID = obj.CurrHarqDL(i);
downlinkGrants{grantIndex}.NDI = ~obj.HarqNDIDL(i,obj.CurrHarqDL(i) + 1); % Toggle NDI to indicate new transmission
end
end
downlinkGrants = downlinkGrants(1:grantIndex);
end
function mcsIndex = getMCSIndex(obj, cqiIndex)
%getMCSIndex Returns the mcsIndex based on cqiIndex
% Valid rows in MCS table (Indices 28, 29, 30, 31 are reserved)
% Indexing starts from 1
validRows = (0:27) + 1;
cqiRow = obj.CQITableUL(cqiIndex + 1, :);
modulation = cqiRow(1);
coderate = cqiRow(2);
% List of matching indices in MCS table for modulation scheme
% as per 'cqiIndex'
modulationList = find(modulation == obj.MCSTableUL(validRows, 1));
% Indices in 'modulationList' which have code rate less than or
% equal to the code rate as per the 'cqiIndex'
coderateList = find(obj.MCSTableUL(modulationList, 2) <= coderate);
if isempty(coderateList)
% If no match found, take the first value in 'modulationList'
coderateList = modulationList(1);
end
% Take the value from 'modulationList' with highest code rate
mcsIndex = modulationList(coderateList(end)) - 1;
end
end
end