# 5G NR PRACH Configuration

This example shows how to configure the 5G New Radio (NR) physical random access channel (PRACH), as defined in TS 38.211 Sections 5.3.2 and 6.3.3 [ 1 ]. You can learn about PRACH time resources, their relation to PRACH preambles, and learn how to generate PRACH preambles without the need to look up configuration tables. This example also shows how to map PRACH symbols to the resource grid, and how to generate a time-domain waveform for a single PRACH preamble.

### Configure Carrier and PRACH

#### Supported Combinations of Subcarrier Spacing

Table 6.3.3.2-1 in TS 38.211 lists the supported combinations of subcarrier spacing for the PRACH and the physical uplink shared channel (PUSCH) during initial access. You can access this table directly from the PRACH configuration object.

`disp(nrPRACHConfig.Tables.SupportedSCSCombinations)`
``` LRA PRACHSubcarrierSpacing PUSCHSubcarrierSpacing NRBAllocation kbar ____ ______________________ ______________________ _____________ ____ 839 1.25 15 6 7 839 1.25 30 3 1 839 1.25 60 2 133 839 5 15 24 12 839 5 30 12 10 839 5 60 6 7 139 15 15 12 2 139 15 30 6 2 139 15 60 3 2 139 30 15 24 2 139 30 30 12 2 139 30 60 6 2 139 60 60 12 2 139 60 120 6 2 139 120 60 24 2 139 120 120 12 2 571 30 15 96 2 571 30 30 48 2 571 30 60 24 2 1151 15 15 96 1 1151 15 30 48 1 1151 15 60 24 1 ```

The system information block 1 (SIB1) contains the radio resource control (RRC) information element UplinkConfigCommonSIB (TS 38.331 Section 6.3.2 [ 2 ]) that defines the subcarrier spacing for the PUSCH. The user equipment (UE) needs this information to transmit the PRACH preamble during the random-access procedure.

#### Carrier Configuration

Because the PUSCH is not defined at the PRACH preamble transmission, to configure the PUSCH subcarrier spacing and the frequency-domain dimensions of the resource grid, use the `nrCarrierConfig` object.

```carrier = nrCarrierConfig; carrier.SubcarrierSpacing = 15; % Subcarrier spacing in kHz (15, 30, 60, 120)```

Because the PRACH preamble is modulated with respect to the carrier, changing the carrier subcarrier spacing leads to a different PRACH waveform. To see how a different carrier affects the generated waveform, check the `Information associated with PRACH OFDM modulation` output for several carriers in the Generate Waveform for Single PRACH Preamble section, .

#### PRACH Configuration

You can configure PRACH parameters by setting property values of the `nrPRACHConfig` object. According to TS 38.211, not all PRACH parameter combinations are valid. For more information on how the properties of `nrPRACHConfig` reflect these limitations, see `nrPRACHConfig`.

```prach = nrPRACHConfig; prach.FrequencyRange = 'FR1'; % Frequency range ('FR1', 'FR2') prach.DuplexMode = 'FDD'; % Duplex mode ('FDD', 'TDD', 'SUL') prach.ConfigurationIndex = 27; % Configuration index (0...255). This value is automatically updated in the next section. prach.SubcarrierSpacing = 15; % Subcarrier spacing in kHz (1.25, 5, 15, 30, 60, 120) prach.SequenceIndex = 0; % Logical root sequence index (0...837) prach.PreambleIndex = 0; % Scalar preamble index within the cell (0...63) prach.RestrictedSet = 'UnrestrictedSet'; % Type of restricted set ('UnrestrictedSet','RestrictedSetTypeA','RestrictedSetTypeB') prach.ZeroCorrelationZone = 0; % Cyclic shift configuration index (0...15) prach.RBOffset = 0; % Starting resource block index of the initial uplink bandwidth part (BWP) relative to carrier resource grid (0...274) prach.FrequencyStart = 0; % Frequency offset of lowest PRACH transmission occasion in frequency domain with respect to physical resource block 0 of the initial uplink BWP (0...274) prach.FrequencyIndex = 0; % Index of the PRACH transmission occasions in frequency domain (0...7) prach.TimeIndex = 0; % Index of the PRACH transmission occasions in time domain (0...6) % For formats B2 and B3, this value is automatically updated in the next section. prach.ActivePRACHSlot = 0; % Active PRACH slot number within a subframe or a 60 kHz slot (0,1) prach.NPRACHSlot = 0; % PRACH slot number```

You can also modify the value of `prach.LRA` to use a value of the PRACH preamble sequence length introduced in Release 16 of the 3GPP specifications.

The `ConfigurationIndex` and `TimeIndex` properties depend on the PRACH format. The `SubcarrierSpacing`, `ActivePRACHSlot`, and `NPRACHSlot` properties determine whether the PRACH preamble is active. The next two sections discuss how to set these properties.

#### How to Set `ConfigurationIndex` Based on Preferred Format

Tables 6.3.3.2-2 to 6.3.3.2-4 in TS 38.211 define all possible PRACH configurations in the time domain. The combination of frequency range and duplex mode specifies which configuration table to use. Valid combinations are:

• FR1 and FDD (paired spectrum): Table 6.3.3.2-2

• FR1 and SUL (supplementary uplink): Table 6.3.3.2-2

• FR1 and TDD (unpaired spectrum): Table 6.3.3.2-3

• FR2 and TDD (unpaired spectrum): Table 6.3.3.2-4

For more information on how paired and unpaired spectrums relate to duplex mode, see the field FDD-OrSUL of the RRC information element FrequencyInfoUL in TS 38.331 Section 6.3.2.

You can access these configuration tables through the `Tables` property of the `nrPRACHConfig` object. For example:

```nrPRACHConfig.Tables.ConfigurationsFR1PairedSUL % TS 38.211 Table 6.3.3.2-2 nrPRACHConfig.Tables.ConfigurationsFR1Unpaired % TS 38.211 Table 6.3.3.2-3 nrPRACHConfig.Tables.ConfigurationsFR2 % TS 38.211 Table 6.3.3.2-4 ```

TS 38.211 defines 13 PRACH formats and categorizes them as long or short preambles. Long preambles have a sequence of length ${L}_{RA}=839$, whereas short preambles have a sequence of length ${L}_{RA}=139$. The formats associated with long preambles are: 0, 1, 2, 3. The formats associated with short preambles are: A1, A2, A3, B1, B2, B3, B4, C0, C2, including mixed formats A1/B1, A2/B2, and A3/B3.

The configuration indices in Tables 6.3.3.2-2 to 6.3.3.2-4 define the time resources in which each preamble format can be transmitted. Each preamble format is associated with several configuration indices. You can choose a PRACH format without the need to look up the configuration tables by setting the value of `ConfigurationIndex` based on the preferred format. This value corresponds to the largest range of time resources in which you can transmit the preferred preamble format.

`format = 'B2'; % PRACH preamble format ('0','1','2','3','A1','A2','A3','B1','B2','B3','B4','C0','C2')`

Select the configuration table based on `FrequencyRange` and `DuplexMode`.

```if strcmpi(prach.FrequencyRange,'FR1') if strcmpi(prach.DuplexMode,'TDD') % TS 38.211 Table 6.3.3.2-3 configTable = nrPRACHConfig.Tables.ConfigurationsFR1Unpaired; else % TS 38.211 Table 6.3.3.2-2 configTable = nrPRACHConfig.Tables.ConfigurationsFR1PairedSUL; end else % TS 38.211 Table 6.3.3.2-4 configTable = nrPRACHConfig.Tables.ConfigurationsFR2; end```

Among all configurations corresponding to the same short preamble format in Table 6.3.3.2-2, the second to last configuration has the largest number of time resources for transmitting the PRACH preamble. In all the other cases, including mixed formats in Table 6.3.3.2-2, the last configuration has the largest number of time resources for transmitting the PRACH preamble. This example uses this information to set the value of the `ConfigurationIndex` property. If you select format B2 or B3, this example sets the maximum value of `TimeIndex`.

```if strcmpi(prach.FrequencyRange,'FR1') && strcmpi(prach.DuplexMode,'FDD') && ... any(strcmpi(format,{'A1','A2','A3','B1','B4','C0','C2'})) prach.ConfigurationIndex = find(strcmpi(configTable.PreambleFormat,format),1,'last') - 2; else if ~any(strcmpi(format,{'B2','B3'})) prach.ConfigurationIndex = find(strcmpi(configTable.PreambleFormat,format),1,'last') - 1; else % Format B2 and B3 only appear in mixed formats, so select an % appropriate mixed format and set the maximum value of TimeIndex prach.ConfigurationIndex = find(endsWith(configTable.PreambleFormat,format),1,'last') - 1; prach.TimeIndex = prach.NumTimeOccasions - 1; end end```

#### How to Select `SubcarrierSpacing`, `ActivePRACHSlot`, and `NPRACHSlot` to Generate Active PRACH Preamble

Tables 6.3.3.2-2 to 6.3.3.2-4 in TS 38.211 describe which PRACH slot corresponds to an active PRACH preamble. The third and fourth columns of these tables represent the system frame numbers that correspond to an active PRACH preamble. Depending on the selected frequency range, FR1 or FR2, the fifth column represents the slot numbers for 15 kHz or 60 kHz subcarrier spacing, respectively, corresponding to an active PRACH preamble. If a PRACH preamble is not active in the current time resources, no time transmission can take place.

For example, the selected PRACH configuration is active in any system frame and subframe if PRACH subcarrier spacing is set to 15 kHz, as shown in Table 6.3.3.2-2.

`disp(configTable(prach.ConfigurationIndex+1,:))`
``` ConfigurationIndex PreambleFormat x y SubframeNumber StartingSymbol PRACHSlotsPerSubframe NumTimeOccasions PRACHDuration __________________ ______________ _ _____ _______________________ ______________ _____________________ ________________ _____________ 146 {'A2/B2'} 1 {[0]} {[0 1 2 3 4 5 6 7 8 9]} 0 2 3 4 ```

To verify that the PRACH preamble is active in the current slot, check the `prachSymbols` output of the `nrPRACH` function. This output is empty if the PRACH preamble is not active in the current slot. To generate an active PRACH preamble, loop through the values of the `NPRACHSlot` property until `prachSymbols` becomes nonempty.

The cases presented in this section show how to check whether the current PRACH short preamble is active. Both cases consider a PRACH short preamble format B2. If you change the format, the PRACH preamble may be active for values of the `NPRACHSlot` and `ActivePRACHSlot` properties different from those shown in this example.

Case 1: Typical PRACH subcarrier spacing configuration

Set up a PRACH preamble for the selected format with a typical subcarrier spacing configuration. This example considers a 15 kHz subcarrier spacing, which is the typical value for short preambles in FR1. If you change the value of the subcarrier spacing or the format, you may need to change the values of `ActivePRACHSlot` and `NPRACHSlot` to get an active PRACH slot.

```% Store the user-defined configuration subcarrierSpacing = prach.SubcarrierSpacing; activePRACHSlot = prach.ActivePRACHSlot; nPRACHSlot = prach.NPRACHSlot; % Set values of SubcarrierSpacing, ActivePRACHSlot, and NPRACHSlot for this % case if any(strcmpi(format,{'0','1','2'})) prach.SubcarrierSpacing = 1.25; elseif strcmpi(format,'3') prach.SubcarrierSpacing = 5; else % Short preambles if strcmpi(prach.FrequencyRange,'FR1') prach.SubcarrierSpacing = 15; % Valid values are (15, 30) else % FR2 prach.SubcarrierSpacing = 60; % Valid values are (60, 120) end end prach.ActivePRACHSlot = 0; prach.NPRACHSlot = 0;```

According to Table 6.3.3.2-2 in TS 38.211, the UE can transmit PRACH in any slot.

```prachSymbols = nrPRACH(carrier,prach); active = ~isempty(prachSymbols); disp(['active: ' num2str(active)])```
```active: 1 ```

Case 2: Alternative PRACH subcarrier spacing configuration

The PRACH subcarrier spacing is set to 30 kHz, whereas the carrier subcarrier spacing is set to the default value of 15 kHz. This means that each carrier slot contains two PRACH slots. This case does not consider PRACH long preambles and frequency range FR2 because they are not compatible with 30 kHz subcarrier spacing.

In the case of 30 kHz PRACH subcarrier spacing, only one of the two PRACH slots within a 15 kHz subcarrier spacing can be active. According to Table 6.3.3.2-2 in TS 38.211, either the first or the second PRACH slots can be active for PRACH preamble format B2. The value of `prach.ActivePRACHSlot` property defines which PRACH slot is active within the current carrier subframe. This property is the ${n}_{slot}^{RA}$ parameter defined in TS 38.211 Section 5.3.2.

This case shows four combinations of the `NPRACHSlot` and `ActivePRACHSlot` property values and tests whether the PRACH preamble is active. This case displays the plot of the time-domain structure of the PRACH preamble for both combinations. The plot shows that the active PRACH preamble occupies the first half of the carrier slot when `ActivePRACHSlot` is `0` and occupies the second half of the carrier slot when `ActivePRACHSlot` is `1`. For more details on this plot, see the Plot Time-Domain Structure of Selected PRACH Preamble section.

```if ~any(strcmpi(format,{'0','1','2','3'})) && strcmpi(prach.FrequencyRange,'FR1') % Short preamble formats and FR1 only % Set subcarrier spacing to 30 kHz for this case prach.SubcarrierSpacing = 30; % Define all combinations of NPRACHSlot and ActivePRACHSlot to check nPRACHSlotCase2 = [0, 1, 2]; activePRACHSlotCase2 = [0, 1]; [NPRACHSlotCase2, ActivePRACHSlotCase2] = meshgrid(nPRACHSlotCase2,activePRACHSlotCase2); prachActivityTable = table(NPRACHSlotCase2(:),ActivePRACHSlotCase2(:),false*ones(numel(NPRACHSlotCase2),1), ... 'VariableNames',{'NPRACHSlot','ActivePRACHSlot','active'}); % Loop over all combinations for i = 1:numel(NPRACHSlotCase2) prach.NPRACHSlot = NPRACHSlotCase2(i); prach.ActivePRACHSlot = ActivePRACHSlotCase2(i); prachSymbols = nrPRACH(carrier,prach); active = ~isempty(prachSymbols); % Check if the PRACH preamble is active in the current slot prachActivityTable.active(i) = active; if active && prach.NPRACHSlot < 2 % Plot the time-domain structure of the PRACH preamble for % active PRACH preambles in the first two slots hPRACHPreamblePlot(carrier,prach); end end else % Display a message for the filtered cases if any(strcmpi(format,{'0','1','2','3'})) disp(['PRACH long preamble format ' format ' is not compatible with 30 kHz subcarrier spacing.']) else % FR2 disp('Frequency range FR2 is not compatible with 30 kHz subcarrier spacing.') end end```

For short preamble formats with a 30 kHz subcarrier spacing, this table shows whether the PRACH preamble is active for each combination of the chosen values of the `NPRACHSlot` and `ActivePRACHSlot` properties.

```if ~any(strcmpi(format,{'0','1','2','3'})) && strcmpi(prach.FrequencyRange,'FR1') % Short preamble formats and FR1 only disp(prachActivityTable) end```
``` NPRACHSlot ActivePRACHSlot active __________ _______________ ______ 0 0 1 0 1 0 1 0 0 1 1 1 2 0 1 2 1 0 ```

Set the PRACH configuration object back to the user-defined configuration

```prach.SubcarrierSpacing = subcarrierSpacing; prach.ActivePRACHSlot = activePRACHSlot; prach.NPRACHSlot = nPRACHSlot;```

#### Inspect PRACH Configuration

• Preamble format: `Format`

• Length of the Zadoff-Chu preamble sequence: `LRA`

• Maximum number of allowed PRACH time occasions: `NumTimeOccasions`

• Number of OFDM symbols in the PRACH slot grid corresponding to one transmission occasion: `PRACHDuration`

• Location of the first OFDM symbol of the current PRACH occasion: `SymbolLocation`

`disp(prach)`
``` nrPRACHConfig with properties: FrequencyRange: 'FR1' DuplexMode: 'FDD' ConfigurationIndex: 146 SubcarrierSpacing: 15 LRA: 139 SequenceIndex: 0 PreambleIndex: 0 RestrictedSet: 'UnrestrictedSet' ZeroCorrelationZone: 0 RBOffset: 0 FrequencyStart: 0 FrequencyIndex: 0 TimeIndex: 2 ActivePRACHSlot: 0 NPRACHSlot: 0 Read-only properties: Format: 'B2' NumTimeOccasions: 3 PRACHDuration: 4 SymbolLocation: 8 SubframesPerPRACHSlot: 1 PRACHSlotsPerPeriod: 10 Constant properties: Tables: [1x1 struct] ```

#### Plot Time-Domain Structure of Selected PRACH Preamble

This plot shows all the possible PRACH occasions (in the current carrier slot) in light colors and the current PRACH occasion (corresponding to the selected `TimeIndex`) in dark colors. This plot contains the cyclic prefix (CP), the PRACH active sequence periods, and a final guard period (GP) in red, blue, and green, respectively. If the PRACH preamble is not active in the current slot, the plot is empty. The plot shows time-related properties of the selected PRACH configuration and the PRACH position in the carrier slot. If the PRACH subcarrier spacing is smaller than the carrier subcarrier spacing, the plot shows the minimum number of carrier slots needed to transmit the PRACH preamble. The last PRACH occasion in time does not always correspond to the end of the carrier slot. The plot is empty for those time values in which no PRACH transmission is allowed for the current PRACH configuration.

`hPRACHPreamblePlot(carrier,prach);`

### Generate and Map PRACH Symbols to Resource Grid

The PRACH resource grid shows the location of the PRACH preamble in both time and frequency domain. Using this resource grid, you can:

• Inspect the PRACH preamble visually in both time and frequency domain

• Generate the PRACH waveform, which is obtained by modulating the resource grid

The PRACH resource grid generation consists of these steps:

1. Generate an empty grid

2. Generate the symbols to be transmitted in the PRACH waveform

3. Generate the frequency indices and time indices in which the PRACH symbols are located

4. Map the PRACH symbols to the PRACH resource grid

Generate an empty PRACH resource grid.

```prachGrid = nrPRACHGrid(carrier,prach); size(prachGrid)```
```ans = 1×2 624 14 ```

Generate the PRACH symbols. The number of symbols depends on the PRACH configuration. The `prachSymbols` output is empty if the PRACH preamble is not active in the current slot.

`prachSymbols = nrPRACH(carrier,prach);`

Generate the PRACH indices. The value in each element of `prachIndices` is the linear index of the location of each element of `prachSymbols` in the PRACH resource grid.

`prachIndices = nrPRACHIndices(carrier,prach);`

Map the PRACH symbols to the PRACH resource grid using the indices. To represent ${\beta }_{PRACH}$ in TS 38.211 Section 6.3.3.2, the mapping applies a scaling factor of 1 to the PRACH symbols.

`prachGrid(prachIndices) = 1 * prachSymbols;`

The `hPRACHResourceGridPlot` helper function plots the PRACH resource grid to show the location of the active PRACH. The plot shows all the time occasions in which the PRACH can be transmitted. The plot shows all the possible PRACH occasions in the current carrier slot in light blue and the current PRACH occasion (corresponding to the selected `TimeIndex`) in dark blue. The plot is empty for OFDM symbols not used by any PRACH occasion for the current configuration. If the PRACH preamble is not active in the current slot, the plot is empty.

`hPRACHResourceGridPlot(carrier,prach);`

The PRACH resource grid contains 14 OFDM symbols except for these cases:

• For long preamble format 0, each preamble has one active sequence period that spans one subframe. Therefore, the slot grid related to format 0 has one OFDM symbol.

• For long preamble format 1, each preamble has two active sequence periods that span two subframes. Therefore, the slot grid related to format 1 has two OFDM symbols.

• For long preamble format 2, each preamble has four active sequence periods that span four subframes. Therefore, the slot grid related to format 2 has four OFDM symbols.

• For long preamble format 3, each preamble has four active sequence periods that span one subframe. Therefore, the slot grid related to format 3 has four OFDM symbols.

• For short preamble format C0, each preamble has one active sequence period. However, because of the guard and the cyclic prefix, the preamble spans two OFDM symbols. Therefore, the slot grid related to format C0 has seven OFDM symbols.

You can retrieve the number of active sequence periods from the value of the `PRACHDuration` property of the PRACH configuration object.

### Generate Waveform for Single PRACH Preamble

Generate a time-domain waveform for a single PRACH preamble by modulating the PRACH resource grid. To set the number of time-domain samples over which to apply windowing and overlapping of OFDM symbols, use `windowing`. This example uses the default value for windowing. For more details about windowing, see `nrPRACHOFDMModulate`.

```windowing = []; [prachWaveform,prachInfo] = nrPRACHOFDMModulate(carrier,prach,prachGrid,'Windowing',windowing);```

The output `prachWaveform` is a column vector corresponding to the time-domain waveform. The output `prachInfo` is a structure that provides dimensional information related to the PRACH. This example displays this information by using the `hPRACHInfoDisplay` helper function. The function displays the information related to the number of samples corresponding to CP, PRACH active sequence period ${T}_{SEQ}$, and GP for each OFDM symbol in a tabular format. The table lists all the OFDM symbols that fit in the resource grid. For short preamble formats, the values marked with `*` correspond to all possible PRACH occasions except the current one (marked light blue in the resource grid plot). For short preamble formats, the values within angle brackets represent OFDM symbols not used by any PRACH occasion for the current configuration (corresponding to an empty space in time in the resource grid plot).

Check the information related to the OFDM symbols against the `PRACHDuration`, `SymbolLocation`, and `NumTimeOccasions` properties. These properties show that:

• Each PRACH occasion lasts 4 OFDM symbols

• The current PRACH occasion starts at OFDM symbol 8

• 3 PRACH occasions are possible in time

`hPRACHInfoDisplay(carrier,prach,windowing);`
```Information associated with PRACH: SubcarrierSpacing: 15 kHz Number of subcarriers: 624 Information associated with PRACH OFDM modulation: Nfft: 1024 Windowing: 72 Offset: 0 samples Symbol TCP TSEQ GP ------ ------ ------ ----- 0* 296* 1024* 0* 1* 0* 1024* 0* 2* 0* 1024* 0* 3* 0* 1024* 0* 4* 296* 1024* 0* 5* 0* 1024* 0* 6* 0* 1024* 0* 7* 0* 1024* 0* 8 180 1024 0 9 0 1024 0 10 0 1024 0 11 0 1024 108 <12> < 0> <1024> < 0> <13> < 0> <1024> < 0> * : OFDM symbols for unused PRACH time occasions <#> : OFDM symbols not used by any PRACH time occasion for the current configuration Total samples: 15360 Sample rate: 15.360 MHz Duration: 1.000 ms Total number of subframes: 1 ```

### Summary and Further Exploration

This example shows how to configure the PRACH, set the configuration index based on the selected format, and determine whether a PRACH preamble is active in the current time resources. This example guides you through PRACH resource grid and time-domain waveform generation. Plotting the time-domain structure of the PRACH preamble displays all the available PRACH occasions for the selected configuration within one subframe. Plotting the resource grid displays all the available PRACH occasions for the selected configuration in both the time and frequency domain.

This example shows how to generate a waveform for a single PRACH preamble. For an example that generates a waveform for multiple PRACH preambles, see 5G NR PRACH Waveform Generation.

### Appendix

This example uses these helper functions:

### Selected Bibliography

1. 3GPP TS 38.211. "NR; Physical channels and modulation." 3rd Generation Partnership Project; Technical Specification Group Radio Access Network.

2. 3GPP TS 38.331. "NR; Radio Resource Control (RRC); Protocol specification." 3rd Generation Partnership Project; Technical Specification Group Radio Access Network.