NR HDL Cell Search MATLAB Reference

This example shows how to model a 5G NR cell search hardware algorithm in MATLAB as a step towards developing a Simulink HDL implementation. Use this MATLAB reference to verify the Simulink model in the NR HDL Cell Search example.

Introduction

The NR HDL Cell Search MATLAB Reference example bridges the gap between a mathematical algorithm and its hardware implementation by providing a MATLAB model of the algorithms that are implemented in hardware. The MATLAB reference is created to evaluate hardware-friendly algorithms and generate test vectors for verifying the Simulink HDL implementation. These related examples show the workflow for designing and deploying a 5G cell search algorithm to hardware.

  • NR Synchronization Procedures (5G Toolbox): MATLAB golden reference of the floating-point algorithm using 5G Toolbox functions.

  • NR HDL Cell Search MATLAB Reference: MATLAB hardware reference that models hardware-friendly algorithms and generates test waveforms. This MATLAB code operates on vectors and matrices of floating-point data samples and does not support HDL code generation.

  • NR HDL Cell Search: Simulink model of the 5G cell search subsystem that uses the same algorithm as the MATLAB reference. This model operates on scalar fixed-point data and is optimized for HDL code generation.

  • 5G NR Cell Search Using Analog Devices AD9361/AD9364 (Communications Toolbox Support Package for Xilinx Zynq-Based Radio): Simulink model that is configured for deployment to an SoC by using the Communications Toolbox™ Support Package for Xilinx® Zynq®-Based Radio.

For a general description of how MATLAB and Simulink can be used together to develop deployable models, see Wireless Communications Design for FPGAs and ASICs (Communications Toolbox).

Cell Search Algorithm Overview

The cell search algorithm detects and demodulates 5G NR synchronization signal blocks (SSBs) and is a hardware-friendly version of the PSS search, OFDM demodulation and SSS search steps shown in the NR Synchronization Procedures (5G Toolbox) example. This figure shows the algorithm. The receiver is divided into an SS Block Detector and a Search Controller. The SS Block Detector performs all of the high-speed signal processing tasks, making it well suited for FPGA or ASIC implementation. The Search Controller coordinates the search and operates at a low rate, making it well suited for software implementation on an embedded processor.

The algorithm starts by using the PSS to search for SSBs with subcarrier spacings of 15 kHz and 30 kHz across a range of coarse frequency offsets. The subcarrier spacings and coarse frequency offset range to search are configurable. If the detector finds SSBs, the receiver OFDM demodulates the resource grid of the SSB with the strongest PSS and determines its cell ID using the SSS. The algorithm includes coarse and fine carrier frequency offset recovery.

  • SS Block Detector: Searches for and OFDM-demodulates SSBs at a given carrier frequency offset and subcarrier spacing and measures the residual fine carrier frequency offset.

  • Digital Down Converter (DDC): Performs frequency translation to correct frequency offsets in the received waveform and then decimates the signal from 61.44 Msps to 7.68 Msps.

  • PSS search: Searches for PSS symbols within the waveform.

  • OFDM demodulation: OFDM-demodulates an SSB resource grid.

  • SSS search: Searches for SSS and determines the overall cell ID.

  • Search Controller: Coordinates the cell search by directing the SS Block Detector to search for PSS symbols at different coarse frequency offsets and subcarrier spacings and to demodulate the SSB with the strongest PSS.

In the MATLAB reference, the nrhdlexamples.cellSearch function implements the cell search algorithm. This function implements the Search Controller shown in the diagram, and calls the nrhdlexamples.ssBlockDetect function, which implements the SS Block Detector. This example describes these two functions, which together are used to explore algorithms for hardware implementation and to verify the streaming fixed-point Simulink model.

The NR HDL Cell Search example shows the streaming fixed-point Simulink HDL implementation of the SS Block Detector. The 5G NR Cell Search Using Analog Devices AD9361/AD9364 (Communications Toolbox Support Package for Xilinx Zynq-Based Radio) example shows how to deploy the cell search algorithm to an SoC by implementing the SS Block Detector in programmable logic and the Search Controller in software on the integrated processing system.

Search Controller

The Search Controller is responsible for coordinating the overall search. The algorithm follows these steps.

  1. For each subcarrier spacing, step through each coarse frequency offset and use the SS Block Detector to search for SSBs until one or more is detected. The coarse frequency offset step size is half the subcarrier spacing.

  2. Move to the next coarse frequency step and search for SSBs again. If the search detects SSBs, choose the coarse frequency offset that resulted in the smallest fine frequency offset measurement. Otherwise, pick the last coarse frequency offset.

  3. Compute the total frequency offset by adding the coarse and fine frequency offsets together.

  4. Use the SS Block Detector to correct the frequency offset and perform one more search for SSBs.

  5. Pick the SSB with the strongest PSS correlation. Use the SS Block Detector in demodulation mode to find and demodulate the SSB and determine its cell ID.

SS Block Detector

These diagrams show the SS Block Detector structure and the parameters and data passed to and from the Search Controller. The SS Block Detector is subdivided into two functions: SS Block DDC (nrhdlexamples.ssBlockDDC) and SS Block Core (nrhdlexamples.ssBlockCore). The DDC accepts samples at 61.44 Msps and performs a frequency shift followed by decimation by a factor of 8 using halfband filters. The frequency offset is provided by the search controller and is used by the algorithm to compensate for both coarse and fine frequency offsets.

SS Block Core accepts samples at 7.68 Msps. For 30 kHz subcarrier spacing, it uses the samples at this rate. For 15 kHz subcarrier spacing, it decimates the input by a factor of two, operating at 3.84 Msps. SS Block Core has two modes of operation: search and demodulation.

In search mode, the function searches for SSBs at the specified subcarrier spacing using the PSS, and returns a list of those detected. For each SSB that is found, the function returns these parameters:

  • NCellID2: Indicates which of the three possible PSS sequences (0,1, or 2) was detected.

  • timing offset: The timing offset from the start of the waveform to the start of the SSB.

  • fine frequency offset: The residual fine frequency offset measured by using the cyclic prefixes of all four OFDM symbols in the SSB.

  • correlation strength: The measured PSS correlation level.

  • signal energy: The total energy in the samples in which the PSS was detected.

In demodulation mode, the function attempts to find a specific SSB by using its timing offset and NCellID2. If the function finds the specified PSS, the receiver OFDM demodulates the SSB resource grid and attempts to detect its SSS. In demodulation mode, the function returns these results.

  • Updated parameters for only the specified SSB if the PSS is found.

  • The demodulated SSB resource grid if the PSS is found.

  • The cell ID if the SSS is found.

The OFDM demodulator uses a 256-point FFT to demodulate the SSB resource grid.

Timing Offsets

The cell search algorithm uses timing offsets to identify positions within the received waveform and intermediate signals. A timing offset is the number of samples from the start of the waveform to a given position, such as the start of an SSB. In 5G NR, UEs can assume that the SS burst periodicity is 20 ms or less for cell search purposes. Based on this value, the timing reference periodicity in this example is 20 ms. Timing offsets are given in samples at 61.44 Msps and are modulo 1228800.

The figure shows two 5G waveforms with different SS burst periodicities (5 ms and 20 ms) and the receiver timing reference. The MATLAB reference can detect SSBs at any position within the received waveform. However, if the waveform is longer than 20 ms, ambiguity in the returned timing offsets exists because the timing reference wraps around every 20 ms. Additionally, the receiver can demodulate only SSBs that begin within the first 20 ms of the waveform.

Generate a Test Waveform

This section shows how to use the MATLAB reference functions to search for SSBs in a waveform.

Use the nrhdlexamples.generateSSBurstWaveform function to generate an SS burst waveform. This function is based on the Synchronization Signal Blocks and Bursts (5G Toolbox) example. The burst has these parameters.

  • SSB pattern is case B

  • Subcarrier spacing is 30

  • NCellID is 249

  • Active SSBs within the burst is 8

rng('default');
[rxWaveform,txGrid,txMIB] = nrhdlexamples.generateSSBurstWaveform();

Plot the resource grid of the burst waveform. The amplitude of each resource element is indicated by its color. The plot shows eight SSBs. The SSBs are generated with different power levels to model what a UE typically receives.

figure(1); clf;
imagesc(abs(txGrid));
caxis([0 4]);
axis xy;
xlabel('OFDM symbol');
ylabel('Subcarrier');
title('SS burst, block pattern Case B');

Detect SS Blocks

Use the nrhdlexamples.ssBlockDetect function to find SSBs in the waveform by searching for PSS symbols. This example calls the function with a coarse carrier frequency offset estimate of zero and a subcarrier spacing of 30. The function corrects the coarse frequency offset and measures the residual fine frequency offset of each SSB. The function returns a list of detected PSS symbols as a structure array. Display the structure array contents by converting it to a table.

FoCoarse = 0;
scs = 30;
[pssList,diagnostics] = nrhdlexamples.ssBlockDetect(rxWaveform,FoCoarse,scs);

disp(struct2table(pssList));
    NCellID2    timingOffset    pssCorrelation    pssEnergy    frequencyOffset
    ________    ____________    ______________    _________    _______________

       0               6608         0.19853        0.19965             8      
       0              15376         0.39532        0.39729            98      
       0              32944         0.12552        0.12629            92      
       0              41712          1.9812         1.9901            71      
       0              68048         0.24951        0.25074           169      
       0              76816         0.63362        0.63808           -11      
       0              94384        0.078639        0.07933           -11      
       0         1.0315e+05         0.24873        0.24988            55      

The nrhdlexamples.ssBlockDetect function also returns a structure containing diagnostic signals. Use this output to plot the PSS correlation results. Each peak in the correlator output shown corresponds to an entry in the PSS list.

figure(2); clf;
nrhdlexamples.plotUtils.PSSCorrelation(diagnostics,'PSS Search Correlation');

Use the nrhdlexamples.ssBlockDetect function to OFDM-demodulate one of the SSBs and attempt SSS detection. For this operation, call the function with an optional 4th argument that specifies the timing offset and NCellID2 of the desired SSB. This example chooses the PSS with the highest correlation metric, however you can choose any of the detected SSBs. Correct the frequency offset by passing in the sum of the coarse and fine frequency offset estimates.

[~,maxCorrIdx] = max(vertcat(pssList.pssCorrelation));
chosenPSS = pssList(maxCorrIdx);
FoFine = chosenPSS.frequencyOffset;
FoEst = FoCoarse + FoFine;

[ssBlockInfo,ssGrid,diagnostics] = nrhdlexamples.ssBlockDetect(rxWaveform,FoEst,scs,chosenPSS);

In demodulation mode, the function returns three outputs instead of two. The ssBlockInfo structure contains further details of the SSB, such as the SSS correlation strength and the overall cell ID. The ssGrid output is a matrix containing the 2nd, 3rd, and 4th demodulated OFDM symbols. Display the SSB info to confirm that the cell ID is correctly decoded.

disp(ssBlockInfo);
           NCellID2: 0
       timingOffset: 41712
     pssCorrelation: 1.9811
          pssEnergy: 1.9901
           NCellID1: 83
     sssCorrelation: 2.0032
          sssEnergy: 2.0040
            NCellID: 249
    frequencyOffset: 0

Display the resulting resource grid.

figure(3); clf;
imagesc(abs(ssGrid));
axis xy;
xlabel('OFDM symbol #');
ylabel('subcarrier index');
title('Rx resource grid symbols 1,2 & 3');

The diagnostics output includes SSS correlation results for all 336 possible sequences. Plot the SSS correlation results.

figure(4); clf;
nrhdlexamples.plotUtils.SSSCorrelation(diagnostics,'SSS Correlation')

Search for Cells

This section shows how to use the nrhdlexamples.cellSearch function to search for and demodulate SSBs when the frequency offset and subcarrier spacing are not known. As described previously, the nrhdlexamples.cellSearch function builds on the nrhdlexamples.ssBlockDetect function by adding a search controller that looks for SSBs at different subcarrier spacings and frequency offsets.

Apply a frequency offset to test the coarse and fine frequency recovery functionality.

Fo           = 10000;
t            = (0:length(rxWaveform)-1).'/61.44e6;
rxWaveformFo = rxWaveform .* exp(1i*2*pi*Fo*t);

Define the frequency range endpoints and subcarrier spacing search space and call the nrhdlexamples.cellSearch function. The function displays information on the search progress as it runs. The frequency range endpoints must be multiples of half the maximum subcarrier spacing.

frequencyRange = [-30 30];
subcarrierSpacings = [15 30];

[ssBlockInfo,ssGrid] = nrhdlexamples.cellSearch(rxWaveformFo,frequencyRange,subcarrierSpacings,struct(...
    'DisplayPlots',false,...
    'DisplayCommandWindowOutput',true));
Searching for PSS (subcarrierSpacing: 15 kHz, frequencyOffset: -30 kHz)
Searching for PSS (subcarrierSpacing: 15 kHz, frequencyOffset: -22.5 kHz)
Searching for PSS (subcarrierSpacing: 15 kHz, frequencyOffset: -15 kHz)
Searching for PSS (subcarrierSpacing: 15 kHz, frequencyOffset: -7.5 kHz)
Searching for PSS (subcarrierSpacing: 15 kHz, frequencyOffset: 0 kHz)
Searching for PSS (subcarrierSpacing: 15 kHz, frequencyOffset: 7.5 kHz)
Searching for PSS (subcarrierSpacing: 15 kHz, frequencyOffset: 15 kHz)
Searching for PSS (subcarrierSpacing: 15 kHz, frequencyOffset: 22.5 kHz)
Searching for PSS (subcarrierSpacing: 15 kHz, frequencyOffset: 30 kHz)
Searching for PSS (subcarrierSpacing: 30 kHz, frequencyOffset: -30 kHz)
Searching for PSS (subcarrierSpacing: 30 kHz, frequencyOffset: -15 kHz)
Searching for PSS (subcarrierSpacing: 30 kHz, frequencyOffset: 0 kHz) ... PSS detected.
Searching for PSS (subcarrierSpacing: 30 kHz, frequencyOffset: 15 kHz) ... PSS detected.
Found PSS with (subcarrierSpacing: 30 kHz, frequencyOffsetEstimate: 10072 kHz)
Correcting frequency offset and searching for PSS again.
Found the following PSS symbols:

    NCellID2    timingOffset    pssCorrelation    pssEnergy    frequencyOffset
    ________    ____________    ______________    _________    _______________

       0               6608         0.19852        0.19964           -64      
       0              15376          0.3953        0.39728            26      
       0              32944         0.12552        0.12629            20      
       0              41712          1.9811         1.9901            -1      
       0              68048          0.2495        0.25074            97      
       0              76816         0.63361        0.63807           -83      
       0              94384        0.078631       0.079328           -83      
       0         1.0315e+05         0.24872        0.24987           -17      

Strongest PSS:
           NCellID2: 0
       timingOffset: 41712
     pssCorrelation: 1.9811
          pssEnergy: 1.9901
    frequencyOffset: -1

Attempting to reacquire strongest PSS and demodulate the corresponding SS block.
             NCellID2: 0
         timingOffset: 41712
       pssCorrelation: 1.9811
            pssEnergy: 1.9901
             NCellID1: 83
       sssCorrelation: 2.0032
            sssEnergy: 2.0040
              NCellID: 249
      frequencyOffset: 10072
    subcarrierSpacing: 30

Summary:
  Subcarrier spacing: 30 kHz
    Frequency offset: 10072 Hz
       Timing offset: 41712
             NCellID: 249

Verification

As shown in the summary, the receiver returned the correct subcarrier spacing of 30 kHz, a cell ID of 249, and the measured frequency offset is close to the expected value of 5 kHz. Use the nrhdlexamples.decodeBCH function to check the quality of the resource grid (ssGrid). The nrhdlexamples.decodeBCH function is based on the BCH decoding stages of the NR Synchronization Procedures (5G Toolbox) example. ssGrid contains only symbols 1, 2, and 3 of the SSB. An extra OFDM symbol must be prepended to the resource grid.

rxGrid = [zeros(240,1) ssGrid];
rxBCH = nrhdlexamples.decodeBCH(rxGrid,ssBlockInfo.NCellID,8);

disp(['RMS PBCH EVM: ' num2str(rxBCH.evm_rms,'%0.3f') '%' newline]);

disp(['BCH CRC: ' num2str(rxBCH.err) newline]);

disp('Decoded (Rx) MIB');
disp(rxBCH.mib);

disp('Expected (Tx) MIB');
disp(txMIB);
RMS PBCH EVM: 42.168%

BCH CRC: 0

Decoded (Rx) MIB
                     NFrame: 105
    SubcarrierSpacingCommon: 30
                      k_SSB: 0
          DMRSTypeAPosition: 2
            PDCCHConfigSIB1: 0
                 CellBarred: 0
       IntraFreqReselection: 0

Expected (Tx) MIB
                     NFrame: 105
    SubcarrierSpacingCommon: 30
                      k_SSB: 0
          DMRSTypeAPosition: 2
            PDCCHConfigSIB1: 0
                 CellBarred: 0
       IntraFreqReselection: 0

This result shows that the BCH is successfully decoded from the resource grid, and the transmitted and received MIB contents match.

Related Topics