Main Content

NR HDL Cell Search

This example shows the design of a 5G NR cell search subsystem optimized for HDL code generation and hardware implementation.

Introduction

The Simulink® model described in this example is an HDL-optimized implementation of a synchronization signal block (SSB) detector for 5G NR frequency range 1 (FR1). This example is one of a related set which show the workflow for designing and deploying a 5G NR cell search and MIB recovery algorithm to hardware. The complete workflow is shown.

Each step in this workflow is demonstrated by one or more related examples.

  1. MATLAB Golden Reference Algorithm: The NR Cell Search and MIB and SIB1 Recovery (5G Toolbox) example shows the floating-point golden reference algorithm.

  2. MATLAB Hardware Reference Algorithm: The NR HDL Cell Search and MIB Recovery MATLAB Reference 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.

  3. Simulink Fixed-Point Implementation Model: The NR HDL Cell Search example (this example) demonstrates a 5G cell search Simulink subsystem that uses the same algorithm as the MATLAB reference. The NR HDL MIB Recovery example adds a broadcast channel decoding and MIB recovery subsystem. The NR HDL MIB Recovery for FR2 example shows cell search and MIB recovery models which have been extended to support FR2. These models operate on fixed-point data and are optimized for HDL code generation.

  4. Simulink SoC Deployment Model: The Deploy NR HDL Reference Applications on SoCs examples build on the fixed-point implementation models and use hardware support packages to deploy the algorithms on hardware.

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.

A block diagram of the SSB detector is shown in the figure. The detector performs all of the high-speed signal processing tasks associated with the cell search algorithm therefore is well suited for FPGA or ASIC implementation. The SSB detector searches for SSBs in time at a given frequency offset and subcarrier spacing. It is designed to be used as part of a larger system that implements carrier frequency offset recovery and subcarrier spacing detection. A controller must be used co-ordinate the overall cell search as shown in the 5G NR MIB Recovery Using Analog Devices AD9361/AD9364 (Communications Toolbox Support Package for Xilinx Zynq-Based Radio) example.

The SSB detector performs primary synchronization sequence (PSS) search, orthogonal frequency division multiplexing (OFDM) demodulation, and secondary synchronization sequence (SSS) search. It also includes a digital down converter (DDC) for correcting frequency offsets in the received signal. The SSB detector has two modes of operation, search and demodulation, which are demonstrated in this example. In search mode, the detector searches for SSBs and returns their parameters. In demodulation mode, the detector recovers a specified SSB OFDM-demodulates its resource grid and searches for SSS within the appropriate resource elements.

File Structure

The example uses these files.

Simulink models

  • nrhdlSSBDetection.slx: This Simulink model uses the nrhdlSSBDetectionFR1Core model reference to simulate the behaviour of the SSB decoding part of the MIB recovery process.

  • nrhdlSSBDetectionFR1Core.slx: This model reference implements the SSB detection algorithm.

Simulink data dictionary

  • nrhdlReceiverData.sldd: This Simulink data dictionary contains bus objects that define the buses contained in the example models.

MATLAB code

  • runSSBDetectionModelSearch.m: Script for running and verifying the nrhdlSSBDetection model in search mode.

  • runSSBDetectionModelDemod.m: Script for running and verifying the nrhdlSSBDetection model in demodulation mode.

  • nrhdlexamples: Package containing the MATLAB reference code and utility functions for verifying the implementation models.

NR HDL Cell Search Model

This figure shows the nrhdlSSBDetection model. The top level of the model reads signals from the MATLAB base workspace, passes them to the SSB Detection subsystem, and writes the outputs back to the workspace. Use the runSSBDetectionModelSearch and runSSBDetectionModelDemod scripts to run the model and post-process the outputs.

SSB Detection Interface

The SSB Detection subsystem contains a Model block that references the nrhdlSSBDetectionFR1Core model. This section describes the inputs and outputs of that model.

Inputs

  • dataIn: 14-bit signed complex-valued signal, sampled at 61.44 Msps.

  • validIn: 1-bit control signal to validate dataIn.

  • frequencyOffset: 32-bit signed value specifying the frequency offset to be corrected. This signal is connected to an NCO with a 32-bit accumulator. Use this equation to convert the value to Hz: frequencyOffset_Hz = frequencyOffset * 61.44e6 / 2^32.

  • subcarrierSpacing: 2-bit unsigned value specifying the subcarrier spacing. Set this signal to 0 to select 15kHz, or 1 to select 30kHz.

  • mode: 1-bit unsigned value specifying the operation mode. Set this signal to 0 for search mode, or 1 for demod mode.

  • timingOffset: 21-bit unsigned value specifying the timing offset of the start of the SSB to be demodulated. Specify the timing offset in samples at 61.44 Msps, from 0 to 1228799. This parameter applies only for demod mode.

  • NCellID2: 2-bit unsigned value specifying the PSS (0, 1, or 2) of the SSB to be demodulated. This parameter applies only for demod mode.

  • start: 1-bit control signal used to start a search or demodulation operation. To start an operation, set frequencyOffset, subcarrierSpacing, mode, timingOffset, and NCellID2 to the desired values and set start to 1 (true) for one or more cycles. If an operation is already in progress, that operation is canceled when start is set to 1 (true). The new operation begins when start is returned to 0 (false).

Outputs

  • status: 4-bit unsigned value that indicates the progress of the current operation. See the next section for the possible values of this signal.

  • pssNCellID2: 2-bit unsigned value that is the PSS (0, 1 or 2) of the detected SSB.

  • pssTimingOffset: 21-bit unsigned value that is the timing offset of the detected SSB. The timing offset is in samples at 61.44 Msp from 0 to 1228799.

  • pssFrequencyOffset: 32-bit signed value that is the frequency offset of the detected SSB. This signal has the same units as the frequencyOffset input.

  • pssCorrelation: 32-bit unsigned value that is the strength of the PSS correlation.

  • pssThreshold: 32-bit unsigned value that is the threshold value when PSS was detected.

  • NCellID: 10-bit unsigned value that is the cell ID of the demodulated SSB. This value is returned only in demod mode.

  • sssCorrelation: 32-bit unsigned value that is the SSS correlation strength. This signal is returned only in demod mode.

  • sssThreshold: 32-bit unsigned value that is the SSS threshold. This value is returned only in demod mode.

  • reportValid: 1-bit control signal. In search mode, this signal validates pssNCellID2, pssTimingOffset, pssFrequencyOffset, pssCorrelation, and pssThreshold for each PSS that is detected. In demod mode, this signal also validates NCellID, sssCorrelation, and sssThreshold. In demod mode, sssCorrelation and sssThreshold are only valid if the specified SSB was found using its PSS, and NCellID is only valid if the SSS was detected.

  • gridData: 16-bit signed complex-values that are the resource grid data. The receiver returns all four symbols of the SSB resource grid. Values are returned one resource element at a time. The resource grid is only returned in demod mode.

  • gridValid: 1-bit control signal that validates the gridData output. Data is only returned if the specified SSB was found using its PSS. This signal is returned only in demod mode.

  • diagnostics: Bus containing diagnostic signals.

Status Signal States

  • 0 Idle -- Initial state. Waiting for first start pulse.

  • 1 Search mode -- Searching for PSS.

  • 2 Search mode -- Operation complete, no PSS found.

  • 3 Search mode -- Operation complete, found one or more PSSs.

  • 4 Demod mode -- Waiting for specified PSS timing offset.

  • 5 Demod mode -- Operation complete, PSS not found.

  • 6 Demod mode -- Found specified PSS. Demodulating the resource grid and looking for SSS.

  • 7 Demod mode -- Operation complete, no SSS found. Returned demodulated resource grid.

  • 8 Demod mode -- Operation complete, found SSS. Returned demodulated resource grid.

SSB Detection Model Reference Structure

This diagram shows the top level of the nrhdlSSBDetectionFR1Core model. The input signal (dataIn) is 14-bit signed complex-valued data sampled at 61.44 Msps. The Input Scaling subsystem increases the word length to 16 bits by sign-extending the values by one bit and adding one LSB. This increase provides headroom and extra accuracy for subsequent processing stages. The DDC corrects the frequency offset and decimates the samples by eight (to 7.68 Msps) by using halfband filters. The output of the DDC is the input to the SSB Search and Demod subsystem. The Detection Status block keeps track of progress and generates the status output.

SSB Search and Demod Subsystem Structure

The SSB Search and Demod subsystem performs SSB detection and demodulation. Its internal sampling rate varies depending on the subcarrier spacing (SCS). The subsystem uses 7.68 Msps for 30kHz SCS and 3.84 Msps for 15kHz SCS. The subcarrier spacing selection logic on the left is responsible for changing the sampling rate. The rate can change only when a new operation is triggered by the start input.

The receiver has an internal timing reference system that keeps track of time by using counters at key points in the datapath. The timing reference counts 20ms periods - the assumed SSB periodicity for cell search as defined by the 5G NR standard. Time is measured in samples at 61.44 Msps modulo 1228800 to create the 20ms period. Since the actual sampling rate is either 7.84 Msps or 3.84 Msps, the timing reference counters increment by either 8 or 16, respectively, for each sample. When a new operation is triggered by the start input, the Start Controller records the start time and passes the time to the other timing references in the model. This signal tells the other timing references when a new subcarrier spacing and corresponding sampling rate applies. The other timing references wait until the start time before changing their increment. This design is possible only because hardware latency means the other timing references lag behind the Start Controller. This architecture enables the receiver to keep track of time consistently, even when a sampling rate change occurs.

The SSB Search and Demod subsystem contains these main subsystems.

  • Subcarrier Spacing Selection: Converts the input to two synchronized sample streams, one at 7.68 Msps and one at 3.84 Msps, and selects which stream to pass to subsequent processing stages according to the subcarrier spacing.

  • PSS Detection: Searches for PSS symbols in the received signal. The next section describes this subsystem in more detail.

  • Cyclic Prefix Correlation: Computes cyclic prefix (CP) correlation values. Each result is averaged across the last four OFDM symbols.

  • CP Correlation to Frequency: Converts CP correlation values to fine frequency offset estimates.

  • PSS and CP Alignment: Matches a CP-based frequency estimate with each PSS symbol detection instance. This alignment is necessary because the frequency estimate for a given PSS detection instance is available only at the end of the corresponding SSB.

  • PSS Info Serialization: If PSS is detected on more than one PSS correlator output at the same timing offset, this block serializes the results so that they are returned from the detector one at a time.

  • OFDM Data Synchronization: Synchronizes the OFDM demodulator input with the output of the PSS detector. This synchronization enables the PSS detector to trigger the OFDM demodulation process at the correct time. The synchronized data is one OFDM symbol behind the PSS correlator as the peak detection occurs at the end of the first OFDM symbol to be demodulated.

  • OFDM Demodulation: OFDM-demodulates `the four symbols of the specified SSB.

  • SSS Detection: Extracts the SSS resource elements from the OFDM demodulator output and correlates them with all 336 possible sequences to determine the cell ID.

  • Create report: Aligns all of the parameters corresponding to one SSB detection, so that they are all valid at the same time.

Simulation Setup

The block diagram shows the simulation setup of this example, which is implemented in the runSSBDetectionModelSearch and runSSBDetectionModelDemod scripts. 5G Toolbox™ functions are used to generate a test waveform which is applied to the MATLAB and Simulink implementations of the SSB detector in search mode and then in demodulation mode. Key diagnostic signals from each detector are compared in terms of their relative mean-squared error (MSE) and the final outputs are compared. Finally, the resource grid output of the Simulink model is decoded to show that the MIB contents are as expected.

Search Mode Simulation

Use the runSSBDetectionModelSearch script to run a search mode simulation and verify the results. In search mode, the SSB detector searches for SSBs and returns their parameters. The script displays its progress in the MATLAB command window. Tables show the parameters of each SSB detected by MATLAB and Simulink. The final table shows the relative MSE between MATLAB and Simulink for each correlator output and for the detection threshold. Plots are generated showing (i) the combined resource grid of all eight SSBs in the transmitted waveform and (ii) the PSS correlation outputs and threshold. The results show that the MATLAB and Simulink implementations match very closely. The small differences between the two implementations are due to quantization errors. These errors occur because the MATLAB reference uses floating-point data types, and the Simulink model uses fixed-point data types.

runSSBDetectionModelSearch;
Generating test waveform.
              SSB pattern: case B
       Subcarrier spacing: 30
                  NCellID: 249
    Number of active SSBs: 8
         Frequency offset: 10 kHz
Searching for SSBs using the MATLAB reference.
Searching for SSBs using the Simulink model.
Running nrhdlSSBDetection.slx
### Starting serial model reference simulation build
### Model reference simulation target for nrhdlSSBDetectionFR1Core is up to date.

Build Summary

0 of 1 models built (1 models already up to date)
Build duration: 0h 0m 1.8465s
..........

SSBs found by MATLAB reference:
    NCellID2    timingOffset    pssCorrelation    pssEnergy    frequencyOffset
    ________    ____________    ______________    _________    _______________

       0               6608        0.43616         0.77013           9837     
       0              15376        0.94287          1.4364           9941     
       0              32944        0.25739         0.50089           9627     
       0              41712         4.4661          6.8109           9885     
       0              68048        0.57172         0.92271          10292     
       0              76816         1.4557          2.2044          10075     
       0              94384         0.1859         0.41544          10318     
       0         1.0315e+05        0.58464         0.93384          10076     

SSBs found by Simulink model:
    NCellID2    timingOffset    pssCorrelation    pssEnergy    frequencyOffset
    ________    ____________    ______________    _________    _______________

       0               6608         0.4361         0.77034           9837     
       0              15376        0.94326          1.4367           9941     
       0              32944        0.25759         0.50106           9628     
       0              41712         4.4667           6.812           9885     
       0              68048        0.57174         0.92296          10292     
       0              76816         1.4563          2.2049          10075     
       0              94384          0.186          0.4156          10318     
       0         1.0315e+05        0.58468         0.93403          10076     


Relative mean-squared error between MATLAB and Simulink in search mode:

            name             relativeMSEdB
    _____________________    _____________

    {'PSS correlation 0'}       -66.863   
    {'PSS correlation 1'}        -61.77   
    {'PSS correlation 2'}       -61.542   
    {'PSS threshold'    }       -76.821   

Use the Simulink Logic Analyzer to view the inputs and outputs to the SSB Detection subsystem. The detector looks for PSS symbols within a 20 ms time window, which begins after a pulse on the start input triggers the search operation. If no PSS symbols are found after 20 ms, the detector sets the status output to 2 - indicating that the search has failed. In this example, the detector finds all eight SSBs. The status output is set to 1 during the search, and a report is returned for each SSB by asserting the reportValid signal. The simulation only runs for 5 ms however if it is extended to run for more than 20 ms, then the status output is eventually set to 3 - indicating that the search has succeeded.

Demodulation Mode Simulation

After running runSSBDetectionModelSearch, use the runSSBDetectionModelDemod script to run a demodulation mode simulation and verify the results. In demodulation mode, the detector recovers the specified SSB by searching for its PSS, OFDM-demodulating the resource grid, and searching for the SSS within the appropriate resource elements. The script displays its progress in the MATLAB command window. SS block reports from MATLAB and Simulink show that both detectors returned similar parameters and determined the cell ID correctly as 249. Relative MSE measurements indicate that the MATLAB and Simulink implementations match very closely. As a final verification step, the script decodes the broadcast channel (BCH) from the Simulink resource grid output. The CRC check passes and the master information block (MIB) contents match the transmission. Plots are generated which show the PSS and SSS correlation results, and the resource grid output. The PSS correlation levels are stronger in the demodulation mode simulation than in search mode simulation because the frequency offset is corrected.

runSSBDetectionModelDemod;
Choosing the strongest PSS from the previous search and computing its frequency offset.
       Strongest PSS index (1 based): 4
    Frequency offset (coarse + fine): 9.885 kHz
Demodulating the strongest SSBs using the MATLAB reference.
Demodulating the strongest SSBs using the Simulink model.
Running nrhdlSSBDetection.slx
### Starting serial model reference simulation build
### Model reference simulation target for nrhdlSSBDetectionFR1Core is up to date.

Build Summary

0 of 1 models built (1 models already up to date)
Build duration: 0h 0m 0.42526s
..........

SS block report from MATLAB
           NCellID2: 0
       timingOffset: 41712
     pssCorrelation: 6.5920
          pssEnergy: 6.7946
           NCellID1: 83
     sssCorrelation: 6.6760
          sssEnergy: 6.8410
            NCellID: 249
    frequencyOffset: -1

SS block report from Simulink
           NCellID2: 0
       timingOffset: 41712
     pssCorrelation: 6.5940
          pssEnergy: 6.7974
           NCellID1: 83
     sssCorrelation: 6.6766
          sssEnergy: 6.8432
            NCellID: 249
    frequencyOffset: -1


Relative mean-squared error between MATLAB and Simulink in demod mode:

            name             relativeMSEdB
    _____________________    _____________

    {'PSS correlation 0'}       -66.962   
    {'PSS threshold'    }       -69.199   
    {'SSS correlation'  }       -68.706   
    {'Rx resource grid' }       -69.822   

Decoding BCH from Simulink resource grid output:

 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

Use the Simulink Logic Analyzer to view the detector output as it progresses through these steps.

  1. The detector sets the status output to 4 while it waits for the specified timing offset and searches for the specified PSS.

  2. PSS is found. The detector sets the status output to 6 - the detector is now searching for the SSS within the resource grid. The four demodulated OFDM symbols are output, indicated by asserting gridValid.

  3. After the SSS is determined, the detector asserts reportValid to indicate that all of the PSS and SSS parameters, including NCellID, are valid. The status output changes to 8, to indicate that the operation is complete and SSS and cell ID are ready.

If the PSS is not found at the specified timing offset, the detector sets the status output to 5 and stops searching. If the detector is unable to determine the SSS, then it sets the status output to 7. In this example, the detector recovers the specified SSB - the SSB with the strongest PSS from the initial search.

HDL Code Generation and Implementation Results

To generate the HDL code for this example, you must have an HDL Coder™ license. Use the makehdl and makehdltb commands to generate HDL code and an HDL test bench for the nrhdlSSBDetection/SSB Detection subsystem. The resulting HDL code was synthesized for a Xilinx® Zynq®-7000 ZC706 evaluation board. The table shows the post place and route resource utilization results. The design meets timing with a clock frequency of 230 MHz.

       Resource        Usage
    _______________    _____

    Slice Registers    74934
    Slice LUTs         29104
    RAMB18                 9
    RAMB36                 1
    DSP48                208

Related Topics