This example shows the design of a 5G NR cell search subsystem optimized for HDL code generation and hardware implementation.
The Simulink model described in this example is an HDL optimized implementation of a synchronization signal block (SSB) detector for 5G NR cell search. 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 figure shows the complete set of examples and the current example within the workflow. For more details on the overall algorithm and workflow, see the NR HDL Cell Search and MIB Recovery MATLAB Reference example. The 5G NR MIB Recovery Using Analog Devices AD9361/AD9364 (Communications Toolbox Support Package for Xilinx Zynq-Based Radio) example shows how to deploy the algorithm to an SoC. 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. This 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.
This example uses these files.
nrhdlexamples.runSSBDetectionModel: This script runs the
nrhdlSSBDetection model by calling the
nrhdlexamples.ssbDetectSimulink function and verifies the model by using 5G Toolbox functions and the NR HDL Cell Search and MIB Recovery MATLAB Reference.
nrhdlexamples.ssbDetectSimulink: This function runs the Simulink model and has the same input and output arguments as the
nrhdlexamples.ssbDetect function from the MATLAB reference.
nrhdlSSBDetection: This top-level Simulink model is a lightweight wrapper that instantiates the
nrhdlSSBDetectionCore model reference.
nrhdlSSBDetectionCore: This model reference implements the SSB detection algorithm.
This example also uses helper functions from the
nrhdlexamples package. The Simulink models and the
nrhdlexamples package are on the MATLAB path. To open one of the models, enter its name at the MATLAB command prompt.
To open a function or script from the
nrhdlexamples package, use the edit command.
This figure shows the
nrhdlSSBDetection model. The top level of the model reads signals from the MATLAB base workspace, passes them to the SS Block Detection subsystem, and writes the outputs back to the workspace. To run the model, call the
nrhdlexamples.runSSBDetectionModel script in MATLAB.
The SS Block Detection subsystem contains a Model block that references the
nrhdlSSBDetectionCore model. This section describes the inputs and outputs of that model.
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: 1-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 cancelled when start is set to 1 (true). The new operation begins when start is returned to 0 (false).
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
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.
This diagram shows the top level of the
nrhdlSSBDetectionCore 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 SS Block Core subsystem. The Detection Status block keeps track of progress and generates the status output.
The SS Block Core 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 SS Block Core 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 `all 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.
This block diagram shows the simulation setup implemented by the
nrhdlexamples.runSSBDetectionModel function. The function uses 5G Toolbox functions to generate a test waveform that has these parameters.
SSB pattern is case B
Subcarrier spacing is 30
NCellID is 249
Active SSBs within the burst is 8
Frequency offset is 10 kHz
Channel is modeled with AWGN
The function passes the test waveform 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. The function calls 5G Toolbox functions to decode the BCH, recover the MIB, and measure the EVM of the resource grid returned by the Simulink implementation.
To run the simulation, call the
nrhdlexamples.runSSBDetectionModel function. This diagram shows the actions performed by the script.
The simulation starts by generating a test waveform as previously described. The plot shows the combined resource grid of all eight SSBs in the transmitted waveform.
In search mode, 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 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. View these signals by opening the Simulink Logic Analyzer tool after the search mode simulation is complete. The simulation runs for 5 ms. If the simulation ran for more than 20 ms, then the status output is eventually set to
3 - indicating the search has succeeded.
The script generates a plot that shows the PSS correlation outputs and the PSS detection threshold. Tables are displayed at the command line showing the parameters of each SSB. The final table shows the MSE between the MATLAB and Simulink implementations for each correlator output and for the detection threshold. These 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.
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. If the PSS is not found at the specified timing offset, the detector sets the status output to
5 and stops searching.
In this example, the detector recovers the specified SSB. The test bench in the
nrhdlexamples.runSSBDetectionModel function chooses the SSB with the strongest PSS from the initial search. The frequency offset measurement from this SSB is used as a frequency offset estimate and passed back into the detector. The Simulink Logic Analyzer tool shows the detector output as it progresses through these steps.
The detector sets status output to
4 while it waits for the specified timing offset and searches for the specified PSS.
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.
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 detector is unable to determine the SSS, then it sets the status output to
These plots show the PSS and SSS correlation signals for both detector implementations. The PSS correlation levels are stronger in demod mode than in search mode because the frequency offset is corrected. The final reports are displayed at the command line, showing that both detectors returned similar parameters and determined the cell ID is 249. The table shows the relative MSE for the PSS and SSS correlation signals and the resource grid.
The plot shows the demodulated resource grids returned by MATLAB and Simulink.
As a final verification step, the script decodes the BCH from the Simulink output by calling
nrhdlexamples.ssbDecode. The command line output shows that the CRC check passed, and confirms that the MIB content matches that of the transmitted waveform.
To generate the HDL code for this example, you must have an HDL Coder™ license. Use the
makehdltb commands to generate HDL code and an HDL test bench for the
nrhdlSSBDetection/SS Block 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 79357 Slice LUTs 37659 RAMB18 7 RAMB36 1 DSP48 208