-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelperSpecSenseNRSignal_v1.m
More file actions
338 lines (293 loc) · 9.16 KB
/
Copy pathhelperSpecSenseNRSignal_v1.m
File metadata and controls
338 lines (293 loc) · 9.16 KB
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
%"Copyright 2023 - 2024 The MathWorks, Inc."
function [txWaveInt, dlWaveInfo] = helperSpecSenseNRSignal_v1(scs,chBW,SSBPeriod,timeShift,numSF,outputFs)
%helperSpecSenseNRSignal 5G NR signal generator
% [X,INFO] = helperSpecSenseNRSignal(SCS,BW,TSSB,TD,NSF,FS) generates a
% downlink 5G NR signal with subcarrier spacing set to SCS kHz, channel
% bandwidth set to BW MHz, SSB period set to TSSB ms, time delay of the
% start of the frame is set to TD in ms, number of subframes set to NSF,
% and output sample rate set to FS. X contains the generated frame I/Q
% samples and INFO contains the information on the generated waveform.
%
% See also nrWaveformGenerator.
% Copyright 2021 The MathWorks, Inc.
% Create configuration object
startGrid = 3;
cfgDL = specSenseNRConfig(chBW,scs,startGrid,SSBPeriod,numSF);
% Generate waveform
[txWave,dlWaveInfo] = nrWaveformGenerator(cfgDL);
sr = dlWaveInfo.ResourceGrids.Info.SampleRate;
dlWaveInfo.Bandwidth = chBW*1e6;
% Time shift
txWave = circshift(txWave,floor(timeShift*1e-3*sr));
% Interpolate
factor = gcd(outputFs, sr);
%rate = outputFs / sr;
L = outputFs/factor;
M = sr/factor;
num = designMultirateFIR(L,M);
num = num / sum(num);
firrc = dsp.FIRRateConverter(L,M, num);
txWaveInt = firrc (txWave);
dlWaveInfo.ResourceGrids.Info.SampleRate = (sr*firrc.InterpolationFactor)/firrc.DecimationFactor;
end
function cfgDL = specSenseNRConfig(chBW,scs,startGrid,SSBPeriod,numSF)
%specSenseNRConfig 5G NR downlink configuration
% CFG = specSenseNRConfig(BW,SCS,TSG,TSSB,NSF) generates a downlink
% 5G NR configuration with subcarrier spacing set to SCS kHz, channel
% bandwidth set to BW MHz, SSB period set to TSSB ms, starting grid set
% to TSG, number of subframes set to NSF.
if nargin == 0
chBW = 20;
scs = 15;
startGrid = 3;
SSBPeriod = 40;
numSF = 40;
end
if scs == 15
blockPattern = 'Case A';
else % 30
blockPattern = 'Case B';
end
gridSize = FR1GridSize(chBW,scs);
[PRBs, slots] = assignREs(gridSize);
try
%% Generate Downlink Waveform
% Downlink configuration:
cfgDL = nrDLCarrierConfig;
cfgDL.Label = 'Carrier1';
cfgDL.FrequencyRange = 'FR1';
cfgDL.ChannelBandwidth = chBW;
cfgDL.NCellID = 1;
cfgDL.NumSubframes = numSF;
cfgDL.WindowingPercent = 0;
cfgDL.SampleRate = [];
cfgDL.CarrierFrequency = 0;
%% SCS specific carriers
scscarrier = nrSCSCarrierConfig;
scscarrier.SubcarrierSpacing = scs;
scscarrier.NSizeGrid = gridSize;
scscarrier.NStartGrid = startGrid;
cfgDL.SCSCarriers = {scscarrier};
%% Bandwidth Parts
bwp = nrWavegenBWPConfig;
bwp.BandwidthPartID = 1;
bwp.Label = 'BWP1';
bwp.SubcarrierSpacing = scs;
bwp.CyclicPrefix = 'normal';
bwp.NSizeBWP = gridSize;
bwp.NStartBWP = 3;
cfgDL.BandwidthParts = {bwp};
%% Synchronization Signals Burst
if rand > 0.5
len = 4;
else
len = 8;
end
ssburst = nrWavegenSSBurstConfig;
ssburst.BlockPattern = blockPattern;
ssburst.TransmittedBlocks = randi([0 1],1,len);
ssburst.Period = SSBPeriod;
ssburst.NCRBSSB = [];
ssburst.KSSB = 0;
ssburst.DataSource = 'MIB';
ssburst.DMRSTypeAPosition = 2;
ssburst.CellBarred = false;
ssburst.IntraFreqReselection = false;
ssburst.PDCCHConfigSIB1 = 0;
ssburst.SubcarrierSpacingCommon = scs;
ssburst.Enable = true;
ssburst.Power = 0;
cfgDL.SSBurst = ssburst;
%% CORESET and Search Space Configuration
maxCORESETRB = floor(gridSize / 6);
% CORESET 1
coreset1 = nrCORESETConfig;
coreset1.CORESETID = 0;
coreset1.Label = 'CORESET0';
coreset1.FrequencyResources = ones(1,maxCORESETRB); % Use the full band
coreset1.Duration = 2;
coreset1.CCEREGMapping = 'interleaved';
coreset1.REGBundleSize = 6;
coreset1.InterleaverSize = 2;
coreset1.ShiftIndex = 0;
cfgDL.CORESET = {coreset1};
% Search Spaces
searchspace = nrSearchSpaceConfig;
searchspace.SearchSpaceID = 1;
searchspace.Label = 'SearchSpace1';
searchspace.CORESETID = 0;
searchspace.SearchSpaceType = 'ue';
searchspace.StartSymbolWithinSlot = 0;
searchspace.SlotPeriodAndOffset = [1 0];
searchspace.Duration = 1;
searchspace.NumCandidates = [8 8 4 2 1];
%% PDCCH Instances Configuration
pdcch = nrWavegenPDCCHConfig;
pdcch.Enable = true;
pdcch.Label = 'PDCCH1';
pdcch.Power = 0;
pdcch.BandwidthPartID = 1;
pdcch.SearchSpaceID = 1;
fr = sum(coreset1.FrequencyResources)*coreset1.Duration;
pdcch.AggregationLevel = min(8,2^(floor(log2(fr))));
% Update num candidates based on aggregation level
aggregationLevels = [1 2 4 8 16];
searchspace.NumCandidates(aggregationLevels > pdcch.AggregationLevel) = 0;
cfgDL.SearchSpaces = {searchspace};
pdcch.AllocatedCandidate = 1;
pdcch.SlotAllocation = 0;
pdcch.Period = 1;
pdcch.Coding = true;
pdcch.DataBlockSize = 20;
pdcch.DataSource = 'PN9-ITU';
pdcch.RNTI = 1;
pdcch.DMRSScramblingID = 2;
pdcch.DMRSPower = 0;
cfgDL.PDCCH = {pdcch};
%% PDSCH Instances Configuration
% PDSCH 1
pdsch1 = nrWavegenPDSCHConfig;
pdsch1.Enable = true;
pdsch1.Label = 'PDSCH1';
pdsch1.Power = 0;
pdsch1.BandwidthPartID = 1;
pdsch1.Modulation = 'QPSK';
pdsch1.NumLayers = 1;
pdsch1.MappingType = 'A';
pdsch1.ReservedCORESET = [];
pdsch1.SymbolAllocation = [0 14];
pdsch1.SlotAllocation = slots;
pdsch1.Period = 20;
pdsch1.PRBSet = PRBs; %0:130;
pdsch1.VRBToPRBInterleaving = false;
pdsch1.VRBBundleSize = 2;
pdsch1.NID = 1;
pdsch1.RNTI = 1;
pdsch1.Coding = true;
pdsch1.TargetCodeRate = 0.513671875;
pdsch1.TBScaling = 1;
pdsch1.XOverhead = 0;
pdsch1.RVSequence = [0 2 3 1];
pdsch1.DataSource = 'PN9-ITU';
pdsch1.DMRSPower = 0;
pdsch1.EnablePTRS = false;
pdsch1.PTRSPower = 0;
% PDSCH Reserved PRB
pdsch1ReservedPRB = nrPDSCHReservedConfig;
pdsch1ReservedPRB.PRBSet = [];
pdsch1ReservedPRB.SymbolSet = [];
pdsch1ReservedPRB.Period = [];
pdsch1.ReservedPRB = {pdsch1ReservedPRB};
% PDSCH DM-RS
pdsch1DMRS = nrPDSCHDMRSConfig;
pdsch1DMRS.DMRSConfigurationType = 1;
pdsch1DMRS.DMRSReferencePoint = 'CRB0';
pdsch1DMRS.DMRSTypeAPosition = 3;%pdsch1.SymbolAllocation(1);
pdsch1DMRS.DMRSAdditionalPosition = 0;
pdsch1DMRS.DMRSLength = 1;
pdsch1DMRS.CustomSymbolSet = [];
pdsch1DMRS.DMRSPortSet = [];
pdsch1DMRS.NIDNSCID = [];
pdsch1DMRS.NSCID = 0;
pdsch1DMRS.NumCDMGroupsWithoutData = 2;
pdsch1.DMRS = pdsch1DMRS;
% PDSCH PT-RS
pdsch1PTRS = nrPDSCHPTRSConfig;
pdsch1PTRS.TimeDensity = 1;
pdsch1PTRS.FrequencyDensity = 2;
pdsch1PTRS.REOffset = '00';
pdsch1PTRS.PTRSPortSet = [];
pdsch1.PTRS = pdsch1PTRS;
cfgDL.PDSCH = {pdsch1};
%% CSI-RS Instances Configuration
csirs = nrWavegenCSIRSConfig;
csirs.Enable = false;
csirs.Label = 'CSIRS1';
csirs.Power = 0;
csirs.BandwidthPartID = 1;
csirs.CSIRSType = 'nzp';
csirs.CSIRSPeriod = 'on';
csirs.RowNumber = 3;
csirs.Density = 'one';
csirs.SymbolLocations = 0;
csirs.SubcarrierLocations = 0;
csirs.NumRB = 52;
csirs.RBOffset = 0;
csirs.NID = 0;
cfgDL.CSIRS = {csirs};
catch ME
save localVariables
rethrow(ME)
end
end
function gridSize = FR1GridSize(chBW,scs)
% TS 38.104 Table 5.3.2-1: Transmission bandwidth configuration NRB for FR1
% TS 38.101-1 Table 5.3.2-1: Maximum transmission bandwidth configuration NRB (FR1)
% NRB, for BW and SCS
colIdx = [5 10 15 20 25 30 40 50 60 70 80 90 100] == chBW;
rowIdx = [15 30 60] == scs;
% BW MHz 5 10 15 20 25 30 40 50 60 70 80 90 100
nrbtable = [25 52 79 106 133 160 216 270 NaN NaN NaN NaN NaN; % 15 kHz
11 24 38 51 65 78 106 133 162 189 217 245 273; % 30 kHz
NaN 11 18 24 31 38 51 65 79 93 107 121 135]; % 60 kHz
gridSize = nrbtable(rowIdx,colIdx);
end
function [PRBs, slots] = assignREs(gridSize)
maxNumSlots = 8;
numSlotGroups = randi(3);
fillRatio = rand()*0.7+0.1; % Random fill ratio between 10% and 80%
numSlots = randFixSum(numSlotGroups,max(numSlotGroups,round(maxNumSlots*fillRatio)));
numRBGroups = randi(3);
fillRatio = rand()*0.5+0.2; % Random fill ratio between 20% and 70%
numRBs = randFixSum(numRBGroups,max(numRBGroups,round(gridSize*fillRatio)));
PRBLimits = zeros(1,numRBGroups*2);
startRB = 0;
for p=1:numRBGroups
if gridSize - sum(numRBs(p:end)) - startRB > 0
startRB = startRB + randi(gridSize - sum(numRBs(p:end)) - startRB);
PRBLimits(2*p-1) = startRB;
PRBLimits(2*p) = PRBLimits(2*p-1)+numRBs(p);
startRB = PRBLimits(2*p);
elseif gridSize - sum(numRBs(p:end)) - startRB == 0
startRB = startRB + 1;
PRBLimits(2*p-1) = startRB;
PRBLimits(2*p) = min(gridSize-1, startRB+numRBs(p));
startRB = PRBLimits(2*p);
end
end
PRBLimits(PRBLimits >= gridSize) = gridSize - 1;
PRBs = "[";
for p=1:numRBGroups
PRBs = PRBs + PRBLimits(2*p-1) + ":" + PRBLimits(2*p) + " ";
end
PRBs = PRBs + "]";
PRBs = unique(eval(PRBs));
slotLimits = zeros(1,numSlotGroups*2);
startSlot = 2;
for p=1:numSlotGroups
if 8 - sum(numSlots(p:end)) - startSlot > 0
startSlot = startSlot + randi(8 - sum(numSlots(p:end)) - startSlot);
slotLimits(2*p-1) = startSlot;
slotLimits(2*p) = slotLimits(2*p-1)+numSlots(p);
startSlot = slotLimits(2*p);
elseif 8 - sum(numSlots(p:end)) - startSlot == 0
startSlot = startSlot + 1;
slotLimits(2*p-1) = startSlot;
slotLimits(2*p) = min(10, startSlot+numSlots(p));
startSlot = slotLimits(2*p);
end
end
slotLimits(slotLimits==0) = [];
slots = "[";
for p=1:2:numel(slotLimits)
slots = slots + slotLimits(p) + ":" + slotLimits(p+1) + " ";
end
slots = slots + "]";
slots = unique(eval(slots));
function x = randFixSum(n,s)
m=1:s;
a=m(sort(randperm(s,n)));
x=diff(a);
x(end+1)=s-sum(x);
end
end