# Use Custom OFDM Sample Rate and Default FFT Size

This example explains how the OFDM functions (`nrOFDMModulate`, `nrOFDMInfo`, and `nrOFDMDemodulate`) set the default value for the fast Fourier transform (FFT) size input, `Nfft`, when you call an OFDM function and these conditions apply.

• You specify a custom value for the sample rate input, `SampleRate`.

• You do not specify a value for the `Nfft` input or you specify `'Nfft',[]`.

### Custom OFDM Sample Rate

The value that you set for the `SampleRate` input determines the sample rate of the waveform.

The nominal sample rate corresponding to the FFT size used in the OFDM modulation, ${\mathit{FFT}}_{\mathit{SR}}$, is equal to `Nfft * carrier.SubcarrierSpacing * 1000`, where `carrier` is the input argument of the function call, specifying the carrier configuration.

Because the resampling of the OFDM-modulated waveform is by a factor of `SampleRate/`${\mathit{FFT}}_{\mathit{SR}}$, the resampling is costly if `SampleRate` and ${\mathit{FFT}}_{\mathit{SR}}$ do not have large common factors.

### Default FFT Size

The default value set for the `Nfft` input satisfies these conditions.

• `Nfft` is a multiple of 128, that is, `Nfft = 128 * ``Y` (to ensure integer-valued cyclic prefix lengths).

• The lower bound of `Y` is equal to `ceil((carrier.NSizeGrid * 12 / 0.85) / 128)`, that is, the lower bound depends of the maximum FFT occupancy of 85%.

• The upper bound of `Y` is equal to `ceil((2 * SampleRate / (carrier.SubcarrierSpacing * 1000)) / 128)`, that is, the upper bound depends on the sample rate you specify.

• `Y` maximizes the common factors of the nominal and specified sample rates, that is, `gcd`(${\mathit{FFT}}_{\mathit{SR}}$,`SampleRate`).

### Plot Bandwidth Occupancy

Create a carrier configuration object.

`carrier = nrCarrierConfig;`

Set the `SampleRate` for each `NSizeGrid` value to give an occupancy of exactly 75%.

```nSizeGrids = 1:275; userSampleRateDefaultNfft = zeros(1,275); fftOccupancy = zeros(1,275); for nSizeGrid = 1:275 carrier.NSizeGrid = nSizeGrid; % Transmission bandwidth of OFDM waveform txBW = carrier.NSizeGrid * 12 * carrier.SubcarrierSpacing * 1000; sr = txBW / 0.75; ofdmInfo = nrOFDMInfo(carrier,'SampleRate',sr); userSampleRateDefaultNfft(nSizeGrid) = ofdmInfo.Nfft; fftOccupancy(nSizeGrid) = carrier.NSizeGrid * 12 / ofdmInfo.Nfft; end```

Plot the resulting `Nfft` values.

```figure; plot(nSizeGrids,userSampleRateDefaultNfft,'x'); title({'Nfft for Custom SampleRate' 'with Bandwidth Occupancy of 75%'}); axis([1 275 min(userSampleRateDefaultNfft) max(userSampleRateDefaultNfft)]); xlabel('NSizeGrid'); xticks([1 52 106 160 216 275]); ylabel('Nfft'); yticks([min(userSampleRateDefaultNfft) 1024:1024:8192 max(userSampleRateDefaultNfft)]);```

Plot the resulting FFT occupancy.

```figure; plot(nSizeGrids,fftOccupancy,'x'); title({'FFT Occupancy for Custom SampleRate' 'with Bandwidth Occupancy of 75%'}); axis([1 275 0 1]); xlabel('NSizeGrid'); xticks([1 52 106 160 216 275]); ylabel('FFT Occupancy');```