nr cell search and mib and sib1 recovery -凯发k8网页登录
this example demonstrates how to use 5g toolbox™ to synchronize, demodulate, and decode a live gnodeb signal. the example decodes the mib and the first of the system information blocks (sib1). decoding mib and sib1 requires a comprehensive receiver, capable of demodulating and decoding the majority of the downlink channels and signals.
introduction
before user equipment (ue) can communicate with the network, it must perform cell search and selection procedures and obtain initial system information. the first steps in that process are acquiring frame synchronization, finding out the cell identity and decoding the mib and sib1. this example shows how to perform these steps by using 5g toolbox.
you can use this example with a captured waveform of i/q samples or generate a local waveform containing a synchronization signal (ss) burst and sib1 using nrwaveformgenerator
. for locally generated waveforms, the example performs these steps:
waveform generation: configure and generate a synchronization signal burst carrying the mib, coreset 0, pdcch and pdsch carrying sib1 by using the downlink waveform generator from 5g toolbox. the transmitter can enhance the snr of one ss block, but it does not perform beamforming. for more information on ssb beamforming, see nr ssb beam sweeping.
awgn: apply additive white gaussian noise (awgn) to the waveform.
receiver: apply various synchronization and demodulation processes to the received waveform to establish the system frame number, cell identity and ssb, and decode the mib. these provide the information required for blind decoding of downlink control information (dci) in a pdcch. the receiver uses dci to configure the pdsch demodulator, decode dl-sch and finally recover the sib1.
these figures show the processing steps inside the receiver.
receiver configuration
to synchronize and demodulate the received waveform, this information is needed:
the waveform sample rate to demodulate the received waveform.
the carrier center frequency to apply symbol phase compensation to the received waveform.
the minimum channel bandwidth to determine coreset 0 frequency resources. ts 38.101-1 table 5.3.5-1 [ 1 ] describes the channel bandwidths for each nr band.
the ss block pattern (case a...e) to determine the subcarrier spacing of the ss/pbch blocks. ue searches for ss block patterns based on the nr operating band. for more information, see ts 38.104 tables 5.4.3.3-1 and 5.4.3.3-2 [ 2 ].
the number of ss/pbch blocks in a burst () to calculate parameters of the pbch dm-rs sequences and pbch descrambling. these parameters depend on the ss/pbch block index as described in ts 38.211 sections 7.3.3.1 and 7.4.1.4.1 [ 3 ]. ts 38.213 section 4.1 [ 5 ] describes the set of ss/pbch blocks in a burst in each case. ue knows the value of based on the ss block pattern and the nr operating band.
loadfromfile = 0; % set to 1 to load a captured waveform if loadfromfile % load captured waveform rx = load('capturedwaveformsib1.mat'); rxwaveform = rx.waveform; % configure receiver sample rate (samples/second) samplerate = rx.samplerate; % symbol phase compensation frequency. specify the carrier center % frequency or set to 0 to disable symbol phase compensation fphasecomp = rx.fphasecomp; % carrier center frequency (hz) % set the minimum channel bandwidth for the nr band required to % configure coreset 0 in fr1 (see ts 38.101-1 table 5.3.5-1) minchannelbw = rx.minchannelbw; % 5, 10, 40 mhz % configure necessary burst parameters at the receiver. the ssb pattern % can be 'case a','case b','case c' for fr1 or 'case d','case e' for % fr2. the maximum number of blocks l_max can be 4 or 8 for fr1 and 64 % for fr2. refburst.blockpattern = rx.ssbblockpattern; refburst.l_max = rx.l_max; else % generate waveform containing ss burst and sib1 % configure the cell identity config = struct(); config.ncellid = 102; % configure an ss burst config.blockpattern = 'case b'; % fr1: 'case a','case b','case c'. fr2: 'case d','case e' config.transmittedblocks = ones(1,8); % bitmap of ss blocks transmitted config.subcarrierspacingcommon = 15; % sib1 subcarrier spacing in khz (15 or 30 for fr1. 60 or 120 for fr2) config.enablesib1 = 1; % set to 0 to disable sib1 % set the minimum channel bandwidth for the nr band required to % configure coreset 0 in fr1 (see ts 38.101-1 table 5.3.5-1) config.minchannelbw = 5; % 5, 10, 40 mhz % introduce a beamforming gain by boosting the power (and therefore % snr) of one ssb and associated sib1 pdcch and pdsch boost = 6; % snr boost in db config.power = zeros(size(config.transmittedblocks)); config.power(1) = boost; % boost the first ssb % configure and generate a waveform containing an ss burst and sib1 wavegenconfig = hsib1waveformconfiguration(config); [txwaveform,waveinfo] = nrwaveformgenerator(wavegenconfig); txofdminfo = waveinfo.resourcegrids(1).info; % add white gaussian noise to the waveform. note that the snr only % applies to the boosted ssb / sib1 rng('default'); % reset the random number generator snrdb = 20; % snr for awgn rxwaveform = awgn(txwaveform,snrdb-boost,-10*log10(double(txofdminfo.nfft))); % configure receiver % sample rate samplerate = txofdminfo.samplerate; % symbol phase compensation frequency (hz). the function % nrwaveformgenerator does not apply symbol phase compensation to the % generated waveform. fphasecomp = 0; % carrier center frequency (hz) % minimum channel bandwidth (mhz) minchannelbw = config.minchannelbw; % configure necessary burst parameters at the receiver refburst.blockpattern = config.blockpattern; refburst.l_max = numel(config.transmittedblocks); end % get ofdm information from configured burst and receiver parameters nrbssb = 20; scsssb = hssburstsubcarrierspacing(refburst.blockpattern); rxofdminfo = nrofdminfo(nrbssb,scsssb,'samplerate',samplerate); % display spectrogram of received waveform figure; nfft = rxofdminfo.nfft; spectrogram(rxwaveform(:,1),ones(nfft,1),0,nfft,'centered',samplerate,'yaxis','minthreshold',-130); title('spectrogram of the received waveform')
pss search and frequency offset correction
the receiver performs pss search and coarse frequency offset estimation following these steps:
frequency shift the received waveform with a candidate frequency offset. candidate offsets are spaced half subcarrier apart. use
searchbw
to control the frequency offset search bandwidth.correlate the frequency-shifted received waveform with each of the three possible pss sequences (nid2) and extract the strongest correlation peak. the reference pss sequences are centered in frequency. therefore, the strongest correlation peak provides a measure of coarse frequency offset with respect to the center frequency of the carrier. the peak also indicates which of the three pss (nid2) has been detected in the received waveform and the time instant of the best channel conditions.
estimate frequency offsets below half subcarrier by correlating the cyclic prefix of each ofdm symbol in the ssb with the corresponding useful parts of the ofdm symbols. the phase of this correlation is proportional to the frequency offset in the waveform.
disp(' -- frequency correction and timing estimation --') % specify the frequency offset search bandwidth in khz searchbw = 6*scsssb; [rxwaveform,freqoffset,nid2] = hssburstfrequencycorrect(rxwaveform,refburst.blockpattern,samplerate,searchbw); disp([' frequency offset: ' num2str(freqoffset,'%.0f') ' hz'])
-- frequency correction and timing estimation -- frequency offset: 65 hz
time synchronization and ofdm demodulation
the receiver estimates the timing offset to the strongest ss block by using the reference pss sequence detected in the frequency search process. after frequency offset correction, the receiver can assume that the center frequencies of the reference pss and received waveform are aligned. finally, the receiver ofdm demodulates the synchronized waveform and extracts the ss block.
% create a reference grid for timing estimation using detected pss. the pss % is placed in the second ofdm symbol of the reference grid to avoid the % special cp length of the first ofdm symbol. refgrid = zeros([nrbssb*12 2]); refgrid(nrpssindices,2) = nrpss(nid2); % second ofdm symbol for correct cp length % timing estimation. this is the timing offset to the ofdm symbol prior to % the detected ssb due to the content of the reference grid nslot = 0; timingoffset = nrtimingestimate(rxwaveform,nrbssb,scsssb,nslot,refgrid,'samplerate',samplerate); % synchronization, ofdm demodulation, and extraction of strongest ss block rxgrid = nrofdmdemodulate(rxwaveform(1 timingoffset:end,:),nrbssb,scsssb,nslot,'samplerate',samplerate); rxgrid = rxgrid(:,2:5,:); % display the timing offset in samples. as the symbol lengths are measured % in fft samples, scale the symbol lengths to account for the receiver % sample rate. srratio = samplerate/(scsssb*1e3*rxofdminfo.nfft); firstsymbollength = rxofdminfo.symbollengths(1)*srratio; str = sprintf(' time offset to synchronization block: %%.0f samples (%%.%.0ff ms) \n',floor(log10(samplerate))-3); fprintf(str,timingoffset firstsymbollength,(timingoffset firstsymbollength)/samplerate*1e3);
time offset to synchronization block: 2200 samples (0.1432 ms)
sss search
the receiver extracts the resource elements associated to the sss from the received grid and correlates them with each possible sss sequence generated locally. the indices of the strongest pss and sss sequences combined give the physical layer cell identity, which is required for pbch dm-rs and pbch processing.
% extract the received sss symbols from the ss/pbch block sssindices = nrsssindices; sssrx = nrextractresources(sssindices,rxgrid); % correlate received sss symbols with each possible sss sequence sssest = zeros(1,336); for nid1 = 0:335 ncellid = (3*nid1) nid2; sssref = nrsss(ncellid); sssest(nid1 1) = sum(abs(mean(sssrx .* conj(sssref),1)).^2); end % plot sss correlations figure; stem(0:335,sssest,'o'); title('sss correlations (frequency domain)'); xlabel('$n_{id}^{(1)}$','interpreter','latex'); ylabel('magnitude'); axis([-1 336 0 max(sssest)*1.1]); % determine nid1 by finding the strongest correlation nid1 = find(sssest==max(sssest)) - 1; % plot selected nid1 hold on; plot(nid1,max(sssest),'kx','linewidth',2,'markersize',8); legend(["correlations" "$n_{id}^{(1)}$ = " num2str(nid1)],'interpreter','latex'); % form overall cell identity from estimated nid1 and nid2 ncellid = (3*nid1) nid2; disp([' cell identity: ' num2str(ncellid)])
cell identity: 102
pbch dm-rs search
in a process similar to sss search, the receiver constructs each possible pbch dm-rs sequence and performs channel and noise estimation. the index of the pbch dm-rs with the best snr determines the lsbs of the ss/pbch block index required for pbch scrambling initialization.
% calculate pbch dm-rs indices dmrsindices = nrpbchdmrsindices(ncellid); % perform channel estimation using dm-rs symbols for each possible dm-rs % sequence and estimate the snr dmrsest = zeros(1,8); for ibar_ssb = 0:7 refgrid = zeros([240 4]); refgrid(dmrsindices) = nrpbchdmrs(ncellid,ibar_ssb); [hest,nest] = nrchannelestimate(rxgrid,refgrid,'averagingwindow',[0 1]); dmrsest(ibar_ssb 1) = 10*log10(mean(abs(hest(:).^2)) / nest); end % plot pbch dm-rs snrs figure; stem(0:7,dmrsest,'o'); title('pbch dm-rs snr estimates'); xlabel('$\overline{i}_{ssb}$','interpreter','latex'); xticks(0:7); ylabel('estimated snr (db)'); axis([-1 8 min(dmrsest)-1 max(dmrsest) 1]); % record ibar_ssb for the highest snr ibar_ssb = find(dmrsest==max(dmrsest)) - 1; % plot selected ibar_ssb hold on; plot(ibar_ssb,max(dmrsest),'kx','linewidth',2,'markersize',8); legend(["snrs" "$\overline{i}_{ssb}$ = " num2str(ibar_ssb)],'interpreter','latex');
channel estimation using pbch dm-rs and sss
the receiver estimates the channel for the entire ss/pbch block using the sss and pbch dm-rs detected in previous steps. an estimate of the additive noise on the pbch dm-rs / sss is also performed.
refgrid = zeros([nrbssb*12 4]);
refgrid(dmrsindices) = nrpbchdmrs(ncellid,ibar_ssb);
refgrid(sssindices) = nrsss(ncellid);
[hest,nest,hestinfo] = nrchannelestimate(rxgrid,refgrid,'averagingwindow',[0 1]);
pbch demodulation
the receiver uses the cell identity to determine and extract the resource elements associated with the pbch from the received grid. in addition, the receiver uses the channel and noise estimates to perform mmse equalization. the equalized pbch symbols are then demodulated and descrambled to give bit estimates for the coded bch block.
disp(' -- pbch demodulation and bch decoding -- ') % extract the received pbch symbols from the ss/pbch block [pbchindices,pbchindicesinfo] = nrpbchindices(ncellid); pbchrx = nrextractresources(pbchindices,rxgrid); % configure 'v' for pbch scrambling according to ts 38.211 section 7.3.3.1 % 'v' is also the 2 lsbs of the ss/pbch block index for l_max=4, or the 3 % lsbs for l_max=8 or 64. if refburst.l_max == 4 v = mod(ibar_ssb,4); else v = ibar_ssb; end ssbindex = v; % pbch equalization and csi calculation pbchhest = nrextractresources(pbchindices,hest); [pbcheq,csi] = nrequalizemmse(pbchrx,pbchhest,nest); qm = pbchindicesinfo.g / pbchindicesinfo.gd; csi = repmat(csi.',qm,1); csi = reshape(csi,[],1); % plot received pbch constellation after equalization figure; plot(pbcheq,'o'); xlabel('in-phase'); ylabel('quadrature') title('equalized pbch constellation'); m = max(abs([real(pbcheq(:)); imag(pbcheq(:))])) * 1.1; axis([-m m -m m]); % pbch demodulation pbchbits = nrpbchdecode(pbcheq,ncellid,v,nest); % calculate rms pbch evm pbchref = nrpbch(pbchbits<0,ncellid,v); evm = comm.evm; pbchevmrms = evm(pbchref,pbcheq); % display calculated evm disp([' pbch rms evm: ' num2str(pbchevmrms,'%0.3f') '%']);
-- pbch demodulation and bch decoding -- pbch rms evm: 8.687%
bch decoding
the receiver weights bch bit estimates with channel state information (csi) from the mmse equalizer and decodes the bch. bch decoding consists of rate recovery, polar decoding, crc decoding, descrambling, and separating the 24 bch transport block bits from the 8 additional timing-related payload bits.
% apply csi pbchbits = pbchbits .* csi; % perform bch decoding including rate recovery, polar decoding, and crc % decoding. pbch descrambling and separation of the bch transport block % bits 'trblk' from 8 additional payload bits a...a 7 is also performed: % a ... a 3: 4 lsbs of system frame number % a 4: half frame number % a 5 ... a 7: for l_max=64, 3 msbs of the ss/pbch block index % for l_max=4 or 8, a 5 is the msb of subcarrier offset k_ssb polarlistlength = 8; [~,crcbch,trblk,sfn4lsb,nhalfframe,msbidxoffset] = ... nrbchdecode(pbchbits,polarlistlength,refburst.l_max,ncellid); % display the bch crc disp([' bch crc: ' num2str(crcbch)]); % stop processing mib and sib1 if bch was received with errors if crcbch disp(' bch crc is not zero.'); return end % use 'msbidxoffset' value to set bits of 'k_ssb' or 'ssbindex', depending % on the number of ss/pbch blocks in the burst if (refburst.l_max==64) ssbindex = ssbindex (bit2int(msbidxoffset,3) * 8); k_ssb = 0; else k_ssb = msbidxoffset * 16; end % displaying the ssb index disp([' ssb index: ' num2str(ssbindex)]);
bch crc: 0 ssb index: 0
mib and bch parsing
the example parses the 24 decoded bch transport block bits into a mib message and creates the initialsysteminfo
structure with initial system information. this process includes reconstituting the 10-bit system frame number (sfn) nframe
from the 6 msbs in the mib and the 4 lsbs in the pbch payload bits. it also includes incorporating the msb of the subcarrier offset k_ssb
from the pbch payload bits in the case of l_max=4 or 8 ss/pbch blocks per burst.
% parse the last 23 decoded bch transport block bits into a mib message. % the bch transport block 'trblk' is the rrc message bcch-bch-message, % consisting of a leading 0 bit and 23 bits corresponding to the mib. the % leading bit signals the message type transmitted (mib or empty sequence). mib = frombits(mib,trblk(2:end)); % do not parse leading bit % create a structure containing complete initial system information initialsysteminfo = initsysteminfo(mib,sfn4lsb,k_ssb,refburst.l_max); % display the mib structure disp(' bch/mib content:') disp(initialsysteminfo); % check if a coreset for type0-pdcch common search space (css) is present, % according to ts 38.213 section 4.1 if ~iscoreset0present(refburst.blockpattern,initialsysteminfo.k_ssb) fprintf('coreset 0 is not present (k_ssb > k_ssb_max).\n'); return end
bch/mib content: nframe: 0 subcarrierspacingcommon: 15 k_ssb: 0 dmrstypeaposition: 3 pdcchconfigsib1: [1x1 struct] cellbarred: 0 intrafreqreselection: 0
ofdm demodulation on full bandwidth
once the mib is recovered, the receiver uses common subcarrier spacing and a bandwidth supporting coreset 0 to ofdm demodulate the frame containing the detected ss block. the receiver determines the coreset 0 frequency resources in common numerology through an offset from the location of the ssb detected and a bandwidth specified in ts 38.213 section 13 tables 13-1 through 13-10 [ 5 ]. the frequency correction process aligned the center of the ofdm resource grid with the center frequency of the ss burst. however, these centers are not necessarily aligned with the center frequency of coreset 0. this figure shows the relationship between the ssb, coreset 0 frequency resources and associated pdcch monitoring occasions.
unlike the ss burst, control and data channels must be aligned in frequency with their common resource block (crb) raster. the value of kssb indicates the frequency offset of the ssb from that crb raster. as the frequency correction process centered the ssb in frequency, apply a frequency shift determined by k_ssb
to align data and control channels with their crb before ofdm demodulation
k_ssb = initialsysteminfo.k_ssb; scscommon = initialsysteminfo.subcarrierspacingcommon; scskssb = kssbsubcarrierspacing(scscommon); kfreqshift = k_ssb*scskssb*1e3; rxwaveform = rxwaveform.*exp(1i*2*pi*kfreqshift*(0:length(rxwaveform)-1)'/samplerate); % adjust the symbol phase compensation frequency with the frequency shift % introduced. fphasecomp = fphasecomp - kfreqshift;
adjust timing offset to the frame origin of the first frame that can schedule an ss/pbch block. if the frame offset is negative, the first frame is incomplete. add leading zeros to the waveform to align the wavefom to that frame.
[frameoffset,nleadingframes] = htimingoffsettofirstframe(timingoffset,refburst,ssbindex,nhalfframe,samplerate); % add leading zeros zeropadding = zeros(-min(frameoffset,0),size(rxwaveform,2)); rxwaveform = [zeropadding; rxwaveform(1 max(frameoffset,0):end,:)]; % determine the number of resource blocks and subcarrier spacing for ofdm % demodulation of coreset 0. nrb = hcoreset0demodulationbandwidth(initialsysteminfo,scsssb,minchannelbw); if samplerate < nrb*12*scscommon*1e3 disp(['sib1 recovery cannot continue. coreset 0 resources are beyond '... 'the frequency limits of the received waveform for the sampling rate configured.']); return; end % ofdm demodulate received waveform with common subcarrier spacing nslot = 0; rxgrid = nrofdmdemodulate(rxwaveform, nrb, scscommon, nslot,... 'samplerate',samplerate,'carrierfrequency',fphasecomp); % display ofdm resource grid and highlight strongest ss block plotresourcegrid(rxgrid,refburst,initialsysteminfo,nleadingframes,ssbindex,nhalfframe)
demodulation of pdcch and downlink control information decoding
to blindly search for system information dci messages in coreset/ss, the receiver performs these steps:
determination of pdcch monitoring occasions and extraction of the ofdm resource grid containing control information.
configuration of coreset 0, search spaces and pdcch.
blind search for format 1_0 dci messages.
the receiver determines the pdcch monitoring occasions through a slot and ofdm symbol offset from the location of the ss block detected, as described in ts 38.213 tables 13-11 and 13-12 [ 5 ] . the receiver adjusts the system frame number to account for the new synchronization time to the first frame available in the waveform.
initialsysteminfo.nframe = mod(initialsysteminfo.nframe - nleadingframes,1024); numrxsym = size(rxgrid,2); [csetsubcarriers,monslots,monslotssym,ssstartsym] = hpdcch0monitoringresources(initialsysteminfo,scsssb,minchannelbw,ssbindex,numrxsym); % check if search space is beyond end of waveform if isempty(monslotssym) disp('search space slot is beyond end of waveform.'); return; end % extract slots containing strongest pdcch from the received grid rxmonslotgrid = rxgrid(csetsubcarriers,monslotssym,:);
configure coreset, search space, and other pdcch parameters. coreset resources and search spaces are configured according to ts 38.213 section 13 tables 13-1 through 13-15 [ 5 ]. cce-to-reg interleaved mapping parameters (regbundlesize = 6, interleaversize = 2, and shiftindex = ncellid) are described in ts 38.211 section 7.3.2.2 [ 3 ]. for coreset 0, the bwp is the size of the coreset as described in ts 38.212 section 7.3.1.0 [ 4 ]. the pdcch scrambling parameters are nrnti = 0 and nid = ncellid as described in ts 38.211 section 7.3.2.3 [ 3 ].
scspair = [scsssb scscommon];
[pdcch,csetpattern] = hpdcch0configuration(ssbindex,initialsysteminfo,scspair,ncellid,minchannelbw);
% configure the carrier to span the bwp (coreset 0)
carrier = hcarrierconfigsib1(ncellid,initialsysteminfo,pdcch);
search for dci messages. ue decodes the received pdcch symbols blindly by monitoring all pdcch candidates for every aggregation level using the si-rnti to identify the right candidate (or instance).
% specify dci message with format 1_0 scrambled with si-rnti (ts 38.212 % section 7.3.1.2.1) dci = dciformat1_0_sirnti(pdcch.nsizebwp); disp(' -- downlink control information message search in pdcch -- '); symbolsperslot = 14; sirnti = 65535; % ts 38.321 table 7.1-1 dcicrc = true; mslotidx = 0; % loop over all monitoring slots while (mslotidx < length(monslots)) && dcicrc % update slot number to next monitoring slot carrier.nslot = monslots(mslotidx 1); % get pdcch candidates according to ts 38.213 section 10.1 [pdcchind,pdcchdmrssym,pdcchdmrsind] = nrpdcchspace(carrier,pdcch); % extract resource grid for this monitoring slot and normalize rxslotgrid = rxmonslotgrid(:,(1:symbolsperslot) symbolsperslot*mslotidx,:); rxslotgrid = rxslotgrid/max(abs(rxslotgrid(:))); % proceed to blind decoding only if the pdcch res are not zero. notzero = any(cellfun(@(x)any(rxslotgrid(x),'all'),pdcchind)); % loop over all supported aggregation levels alevidx = 1; while (alevidx <= 5) && dcicrc && notzero % loop over all candidates at each aggregation level in ss cidx = 1; numcandidatesal = pdcch.searchspace.numcandidates(alevidx); while (cidx <= numcandidatesal) && dcicrc % channel estimation using pdcch dm-rs [hest,nvar,pdcchhestinfo] = nrchannelestimate(rxslotgrid,pdcchdmrsind{alevidx}(:,cidx),pdcchdmrssym{alevidx}(:,cidx)); % equalization and demodulation of pdcch symbols [pdcchrxsym,pdcchhest] = nrextractresources(pdcchind{alevidx}(:,cidx),rxslotgrid,hest); pdccheqsym = nrequalizemmse(pdcchrxsym,pdcchhest,nvar); dcicw = nrpdcchdecode(pdccheqsym,pdcch.dmrsscramblingid,pdcch.rnti,nvar); % dci message decoding polarlistlength = 8; [dcibits,dcicrc] = nrdcidecode(dcicw,dci.width,polarlistlength,sirnti); if dcicrc == 0 disp([' decoded pdcch candidate #' num2str(cidx) ' at aggregation level ' num2str(2^(alevidx-1))]) end cidx = cidx 1; end alevidx = alevidx 1; end mslotidx = mslotidx 1; end mslotidx = mslotidx-1; monslotssym = monslotssym(mslotidx*symbolsperslot (1:symbolsperslot)); % highlight coreset 0/ss occasions in resource grid highlightcoreset0ss(csetsubcarriers,monslots,monslots(mslotidx 1),pdcch,dcicrc) if dcicrc disp(' dci decoding failed.'); return end % calculate rms pdcch evm pdcchref = nrpdcch(double(dcicw<0),pdcch.dmrsscramblingid,pdcch.rnti); evm = comm.evm; pdcchevmrms = evm(pdcchref,pdccheqsym); % display calculated evm disp([' pdcch rms evm: ' num2str(pdcchevmrms,'%0.3f') '%']); disp([' pdcch crc: ' num2str(dcicrc)]); % plot received pdcch constellation after equalization figure; plot(pdccheqsym,'o'); xlabel('in-phase'); ylabel('quadrature') title('equalized pdcch constellation'); m = max(abs([real(pdccheqsym(:)); imag(pdccheqsym(:))])) * 1.1; axis([-m m -m m]);
-- downlink control information message search in pdcch -- decoded pdcch candidate #1 at aggregation level 8 pdcch rms evm: 10.759% pdcch crc: 0
demodulation of pdsch, decoding of dl-sch and sib1 extraction
to recover the first system information block, the receiver performs these steps:
determination of pdsch configuration using cell id, bch information, and dci
channel estimation, equalization and demodulation of pdsch symbols
decoding of dl-sch and sib1 extraction
% build dci message structure dci = frombits(dci,dcibits); % get pdsch configuration from cell id, bch information, and dci [pdsch,k0] = hsib1pdschconfiguration(dci,pdcch.nsizebwp,initialsysteminfo.dmrstypeaposition,csetpattern); % for coreset pattern 2, the gnodeb can allocate pdsch in the next slot, % which is indicated by the slot offset k_0 signaled by dci. for more % information, see ts 38.214 table 5.1.2.1.1-4. carrier.nslot = carrier.nslot k0; monslotssym = monslotssym symbolsperslot*k0; if k0 > 0 % display the ofdm grid of the slot containing associated pdsch figure; imagesc(abs(rxgrid(csetsubcarriers,monslotssym,1))); axis xy xlabel('ofdm symbol'); ylabel('subcarrier'); title('slot containing pdsch (slot offset k_0 = 1)'); end % pdsch channel estimation and equalization using pdsch dm-rs pdschdmrsindices = nrpdschdmrsindices(carrier,pdsch); pdschdmrssymbols = nrpdschdmrs(carrier,pdsch);
to compensate for the negative effects of a carrier frequency mismatch in symbol phase compensation and channel estimation, the receiver ofdm demodulates the waveform with a set of carrier frequencies over a search bandwidth around fphasecomp
. the search finishes when dl-sch decoding succeeds or the last frequency has been reached. the minimum search bandwidths that produce equal symbol phase compensation are 1920, 3840, 7680, and 15360 khz for common subcarrier spacings 15, 30, 60, and 120 khz, respectively. increase the search bandwidth up to these values when sib1 decoding fails and the equalized pdsch symbols result in a heavily distorted and rotated constellation.
disp(' -- pdsch demodulation and dl-sch decoding -- ') mu = log2(scscommon/15); bw = 2^mu*100; % search bandwidth (khz) freqstep = 2^mu; % frequency step (khz) freqsearch = -bw/2:freqstep:bw/2-freqstep; [~,fsearchidx] = sort(abs(freqsearch)); % sort frequencies from center freqsearch = freqsearch(fsearchidx); for fpc = fphasecomp 1e3*freqsearch % ofdm demodulate received waveform nslot = 0; rxgrid = nrofdmdemodulate(rxwaveform, nrb, scscommon, nslot,... 'samplerate',samplerate,'carrierfrequency',fpc); % extract monitoring slot from the received grid rxslotgrid = rxgrid(csetsubcarriers,monslotssym,:); rxslotgrid = rxslotgrid/max(abs(rxslotgrid(:))); % normalization of received re magnitude % channel estimation and equalization of pdsch symbols [hest,nvar,pdschhestinfo] = nrchannelestimate(rxslotgrid,pdschdmrsindices,pdschdmrssymbols); [pdschindices,pdschindicesinfo] = nrpdschindices(carrier,pdsch); [pdschrxsym,pdschhest] = nrextractresources(pdschindices,rxslotgrid,hest); pdscheqsym = nrequalizemmse(pdschrxsym,pdschhest,nvar); % pdsch demodulation cw = nrpdschdecode(carrier,pdsch,pdscheqsym,nvar); % create and configure dl-sch decoder with target code rate and % transport block size decodedlsch = nrdlschdecoder; decodedlsch.ldpcdecodingalgorithm = 'normalized min-sum'; xoh_pdsch = 0; % ts 38.214 section 5.1.3.2 tcr = hmcs(dci.modulationcoding); nreperprb = pdschindicesinfo.nreperprb; tbslength = nrtbs(pdsch.modulation,pdsch.numlayers,length(pdsch.prbset),nreperprb,tcr,xoh_pdsch); decodedlsch.transportblocklength = tbslength; decodedlsch.targetcoderate = tcr; % decode dl-sch [sib1bits,sib1crc] = decodedlsch(cw,pdsch.modulation,pdsch.numlayers,dci.redundancyversion); if sib1crc == 0 break; end end % highlight pdsch and pdsch dm-rs in resource grid. pdcch.aggregationlevel = 2^(alevidx-2); pdcch.allocatedcandidate = cidx-1; plotresourcegridsib1(rxslotgrid,carrier,pdcch,pdsch,tcr,k0); % plot received pdsch constellation after equalization figure; plot(pdscheqsym,'o'); xlabel('in-phase'); ylabel('quadrature') title('equalized pdsch constellation'); m = max(abs([real(pdscheqsym(:)); imag(pdscheqsym(:))])) * 1.1; axis([-m m -m m]); % calculate rms pdsch evm, including normalization of pdsch symbols for any % offset between dm-rs and pdsch power pdschref = nrpdsch(carrier,pdsch,double(cw{1}<0)); evm = comm.evm; pdschevmrms = evm(pdschref,pdscheqsym/sqrt(var(pdscheqsym))); % display pdsch evm and dl-sch crc disp([' pdsch rms evm: ' num2str(pdschevmrms,'%0.3f') '%']); disp([' pdsch crc: ' num2str(sib1crc)]); if sib1crc == 0 disp(' sib1 decoding succeeded.'); else disp(' sib1 decoding failed.'); end
-- pdsch demodulation and dl-sch decoding -- pdsch rms evm: 10.832% pdsch crc: 0 sib1 decoding succeeded.
references
3gpp ts 38.101-1. "nr; user equipment (ue) radio transmission and reception; part 1: range 1 standalone" 3rd generation partnership project; technical specification group radio access network.
3gpp ts 38.104. "nr; base station (bs) radio transmission and reception." 3rd generation partnership project; technical specification group radio access network.
3gpp ts 38.211. "nr; physical channels and modulation." 3rd generation partnership project; technical specification group radio access network.
3gpp ts 38.212. "nr; multiplexing and channel coding." 3rd generation partnership project; technical specification group radio access network.
3gpp ts 38.213. "nr; physical layer procedures for control." 3rd generation partnership project; technical specification group radio access network.
3gpp ts 38.214. "nr; physical layer procedures for data." 3rd generation partnership project; technical specification group radio access network.
3gpp ts 38.321. "nr; medium access control (mac) protocol specification." 3rd generation partnership project; technical specification group radio access network.
local functions
function present = iscoreset0present(ssbblockpattern,kssb) switch ssbblockpattern case {'case a','case b','case c'} % fr1 kssb_max = 23; case {'case d','case e'} % fr2 kssb_max = 11; end if (kssb <= kssb_max) present = true; else present = false; end end function [timingoffset,nleadingframes] = htimingoffsettofirstframe(offset,burst,ssbidx,nhalfframe,samplerate) % as the symbol lengths are measured in fft samples, scale the symbol % lengths to account for the receiver sample rate. non-integer delays % are approximated at the end of the process. scs = hssburstsubcarrierspacing(burst.blockpattern); ofdminfo = nrofdminfo(1,scs,'samplerate',samplerate); % smallest fft size for scs-sr srratio = samplerate/(scs*1e3*ofdminfo.nfft); symbollengths = ofdminfo.symbollengths*srratio; % adjust timing offset to the start of the ss block. this step removes % the extra offset introduced in the reference grid during pss search, % which contained the pss in the second ofdm symbol. offset = offset symbollengths(1); % timing offset is adjusted so that the received grid starts at the % frame head i.e. adjust the timing offset for the difference between % the first symbol of the strongest ssb, and the start of the frame burststartsymbols = hssburststartsymbols(burst.blockpattern,burst.l_max); % start symbols in ssb numerology ssbfirstsym = burststartsymbols(ssbidx 1); % 0-based % adjust for whole subframes symbolspersubframe = length(symbollengths); subframeoffset = floor(ssbfirstsym/symbolspersubframe); samplespersubframe = sum(symbollengths); timingoffset = offset - (subframeoffset*samplespersubframe); % adjust for remaining ofdm symbols symboloffset = mod(ssbfirstsym,symbolspersubframe); timingoffset = timingoffset - sum(symbollengths(1:symboloffset)); % the first ofdm symbol of the ssb is defined with respect to the % half-frame where it is transmitted. adjust for half-frame offset timingoffset = timingoffset - nhalfframe*5*samplespersubframe; % adjust offset to the first frame in the waveform that is scheduled % for ssb transmission. repetitions = ceil(timingoffset/(20*samplespersubframe)); timingoffset = round(timingoffset - repetitions*20*samplespersubframe); % calculate the number of leading frames before the detected one nleadingframes = 2*repetitions; end function initsysteminfo = initsysteminfo(mib,sfn4lsb,k_ssb,l_max) % create set of subcarrier spacings signaled by the 7th bit of the % decoded mib, the set is different for fr1 (l_max=4 or 8) and fr2 % (l_max=64) if (l_max==64) scscommon = [60 120]; else scscommon = [15 30]; end initsysteminfo = struct(); initsysteminfo.nframe = mib.systemframenumber*2^4 bit2int(sfn4lsb,4); initsysteminfo.subcarrierspacingcommon = scscommon(mib.subcarrierspacingcommon 1); initsysteminfo.k_ssb = k_ssb mib.ssb_subcarrieroffset; initsysteminfo.dmrstypeaposition = 2 mib.dmrs_typea_position; initsysteminfo.pdcchconfigsib1 = info(mib.pdcch_configsib1); initsysteminfo.cellbarred = mib.cellbarred; initsysteminfo.intrafreqreselection = mib.intrafreqreselection; end function nrb = hcoreset0demodulationbandwidth(sysinfo,scsssb,minchannelbw) % determine the ofdm demodulation bandwidth from coreset 0 bandwidth cset0idx = sysinfo.pdcchconfigsib1.controlresourcesetzero; scscommon = sysinfo.subcarrierspacingcommon; scspair = [scsssb scscommon]; [csetnrb,~,csetfreqoffset] = hcoreset0resources(cset0idx,scspair,minchannelbw,sysinfo.k_ssb); % calculate a suitable bandwidth in rb that includes coreset 0 in % received waveform. c0 = csetfreqoffset 10*scsssb/scscommon; % coreset frequency offset from carrier center nrb = 2*max(c0,csetnrb-c0) 2; % number of rb to cover coreset 0 end function [k,slots,slotsymbols,ssstartsym] = hpdcch0monitoringresources(systeminfo,scsssb,minchannelbw,ssbindex,numrxsym) cset0idx = systeminfo.pdcchconfigsib1.controlresourcesetzero; scscommon = systeminfo.subcarrierspacingcommon; scspair = [scsssb scscommon]; k_ssb = systeminfo.k_ssb; [c0nrb,c0duration,c0freqoffset,c0pattern] = hcoreset0resources(cset0idx,scspair,minchannelbw,k_ssb); ssidx = systeminfo.pdcchconfigsib1.searchspacezero; [ssslot,ssstartsym,isoccasion] = hpdcch0monitoringoccasions(ssidx,ssbindex,scspair,c0pattern,c0duration,systeminfo.nframe); % pdcch monitoring occasions associated to different ss blocks can be % in different frames. if there are no monitoring occasions in this % frame, there must be one in the next one. adjust the slots associated % to the search space by one frame if needed. slotsperframe = 10*scscommon/15; ssslot = ssslot (~isoccasion)*slotsperframe; % for fr1, ue monitors pdcch in the type0-pdcch css over two consecutive % slots for coreset pattern 1 monslotsperperiod = 1 (c0pattern==1); % calculate 1-based subscripts of the subcarriers and ofdm symbols for % the slots containing the pdcch0 associated to the detected ss block % in this and subsequent 2-frame blocks nrb = hcoreset0demodulationbandwidth(systeminfo,scsssb,minchannelbw); k = 12*(nrb-20*scsssb/scscommon)/2 - c0freqoffset*12 (1:c0nrb*12); symbolsperslot = 14; numrxslots = ceil(numrxsym/symbolsperslot); slots = ssslot (0:monslotsperperiod-1)' (0:2*slotsperframe:(numrxslots-ssslot-1)); slots = slots(:)'; slotsymbols = slots*symbolsperslot (1:symbolsperslot)'; slotsymbols = slotsymbols(:)'; % remove monitoring symbols exceeding waveform limits slotsymbols(slotsymbols>numrxsym) = []; % calculate the monitoring slots after removing symbols slots = (slotsymbols(1:symbolsperslot:end)-1)/symbolsperslot; end function scskssb = kssbsubcarrierspacing(scscommon) % subcarrier spacing of k_ssb, as defined in ts 38.211 section 7.4.3.1 if scscommon > 30 % fr2 scskssb = scscommon; else scskssb = 15; end end function c = hcarrierconfigsib1(ncellid,initsysteminfo,pdcch) c = nrcarrierconfig; c.subcarrierspacing = initsysteminfo.subcarrierspacingcommon; c.nstartgrid = pdcch.nstartbwp; c.nsizegrid = pdcch.nsizebwp; c.nslot = pdcch.searchspace.slotperiodandoffset(2); c.nframe = initsysteminfo.nframe; c.ncellid = ncellid; end function plotresourcegrid(rxgrid,refburst,systeminfo,nleadingframes,ssbindex,nhalfframe) % extract ssb and common scs from reference ss burst and initial system % information scsssb = hssburstsubcarrierspacing(refburst.blockpattern); scscommon = systeminfo.subcarrierspacingcommon; scsratio = scsssb/scscommon; % number of subcarriers, symbols and frames. [k,l] = size(rxgrid); symbolspersubframe = 14*scscommon/15; numframes = ceil(l/(10*symbolspersubframe)); % define colors and auxiliary plotting function baseplotprops = {'linestyle','-','linewidth',1}; occasioncolor = 0.7*[1 1 1]; detectioncolor = [200,0,0]/255; frameboundarycolor = 0.1*[1 1 1]; boundingbox = @(y,x,h,w,varargin)rectangle('position',[x 0.5 y-0.5 w h],baseplotprops{:},varargin{:}); % create figure and display resource grid figure; imagesc(abs(rxgrid(:,:,1))); axis xy; hold on; % add vertical frame lines x = repmat((0:numframes-1)*10*symbolspersubframe,3,1); x(3,:) = nan; y = repmat([0;k;nan],1,numframes); plot(x(:),y(:),'color',frameboundarycolor); % determine frequency origin of the ssb in common numerology ssbcenter = k/2; halfssb = 10*12*scsratio; scskssb = kssbsubcarrierspacing(scscommon); kssbfreqoff = systeminfo.k_ssb*scskssb/scscommon; ssbfreqorig = ssbcenter - halfssb kssbfreqoff 1; % determine time origin of the ssb in common numerology ssbstartsymbols = hssburststartsymbols(refburst.blockpattern,refburst.l_max); ssbstartsymbols = ssbstartsymbols 5*symbolspersubframe*nhalfframe; ssbheadsymbol = ssbstartsymbols(ssbindex 1)/scsratio; ssbtailsymbol = floor((ssbstartsymbols(ssbindex 1) 4)/scsratio)-1; % draw bounding boxes around all ss/pbch block occasions w = ssbtailsymbol - ssbheadsymbol 1; for i = 1:ceil(numframes/2) s = ssbheadsymbol (i-1)*2*10*symbolspersubframe 5*symbolspersubframe*nhalfframe; if s <= (l - w) boundingbox(ssbfreqorig,s,240*scsratio,w,'edgecolor',occasioncolor); end end % draw bounding box for detected ss/pbch block s = ssbheadsymbol nleadingframes*10*symbolspersubframe 5*symbolspersubframe*nhalfframe; boundingbox(ssbfreqorig,s,240*scsratio,w,baseplotprops{:},'edgecolor',detectioncolor) % add text next to detected ss/pbch block str = sprintf('ssb#%d',ssbindex); text(s w 1,ssbfreqorig 24,0,str,'fontsize',10,'color','w') % create legend. since rectangles don't show up in legend, create a % placeholder for bounding boxes. plot(nan,nan,baseplotprops{:},'color',occasioncolor); plot(nan,nan,baseplotprops{:},'color',detectioncolor); legend('frame boundary','occasion','detected') xlabel('ofdm symbol'); ylabel('subcarrier'); % add title including frame numbers firstnframe = systeminfo.nframe - nleadingframes; nframes = mod(firstnframe (0:numframes-1),1024); sfns = sprintf('(%d...%d)',nframes(1),nframes(end)); title(['received resource grid. system frame number: ' sfns]); end function highlightcoreset0ss(csetsubcarriers,monslots,detslot,pdcch,dcicrc) ssfirstsym = pdcch.searchspace.startsymbolwithinslot; csetduration = pdcch.coreset.duration; % define colors and plotting function baseplotprops = {'linestyle','-','linewidth',1}; occasioncolor = 0.7*[1 1 1]; detectioncolor = [200,0,0]/255; boundingbox = @(y,x,h,w,varargin)rectangle('position',[x 0.5 y-0.5 w h],baseplotprops{:},varargin{:}); % highlight all coreset 0/ss occasions related to the detected ssb k0 = csetsubcarriers(1); k = length(csetsubcarriers); sssym = 14*monslots ssfirstsym ; for i = 1:length(sssym) boundingbox(k0,sssym(i),k,csetduration,'edgecolor',occasioncolor); end if dcicrc == 0 % highlight decoded pdcch sssym = 14*detslot ssfirstsym; boundingbox(k0,sssym,k,csetduration,'edgecolor',detectioncolor); % add text next to decoded pdcch text(sssym csetduration 1,k0 24,0,'pdcch','fontsize',10,'color','w') end end function plotresourcegridsib1(slotgrid,carrier,pdcch,pdsch,tcr,k0) % display the ofdm grid of the slot containing decoded pdcch figure; imagesc(abs(slotgrid(:,:,1))); axis xy xlabel('ofdm symbol'); ylabel('subcarrier'); title('slot containing decoded pdcch'); aggregationlevelindex = log2(pdcch.aggregationlevel) 1; candidate = pdcch.allocatedcandidate; % define auxiliary plotting function color = [200,0,0]/255; boundingbox = @(y,x,h,w,varargin)rectangle('position',[x 0.5 y-0.5 w h],'edgecolor',color,varargin{:}); % highlight pdcch in resource grid carrier.nslot = carrier.nslot - k0; % substract slot offset k0 for subscripts calculations subspdcch = nrpdcchspace(carrier,pdcch,'indexstyle','subs'); subspdcch = double(subspdcch{aggregationlevelindex}(:,:,candidate)); x = min(subspdcch(:,2))-1; x = max(subspdcch(:,2))-x; y = min(subspdcch(:,1)); y = max(subspdcch(:,1))-y 1; boundingbox(y,x,y,x); str = sprintf('pdcch \naggregation level: %d\ncandidate: %d',2.^(aggregationlevelindex-1),candidate-1); text(x x 1,y y/2,0,str,'fontsize',10,'color','w') % highlight pdsch and pdsch dm-rs in resource grid carrier.nslot = carrier.nslot k0; % add back slot offset k0 for subscripts calculations subspdschsym = double(nrpdschindices(carrier,pdsch,'indexstyle','subscript')); subspdschdmrs = double(nrpdschdmrsindices(carrier,pdsch,'indexstyle','subscript')); subspdsch = [subspdschsym;subspdschdmrs]; x = min(subspdsch(:,2))-1; x = max(subspdsch(:,2))-x; y = min(subspdsch(:,1)); y = max(subspdsch(:,1))-y 1; boundingbox(y,x,y,x); str = sprintf('pdsch (sib1) \nmodulation: %s\ncode rate: %.2f',pdsch.modulation,tcr); text(x 4,y y 60,0, str,'fontsize',10,'color','w') end