5G NR Waveform & Simulation Guide
5G NR Waveform & Simulation Guide
% Configure SS burst
ssburst = nrWavegenSSBurstConfig;
ssburst.Enable = 1; % Enable SS Burst
ssburst.Power = 0; % Power scaling in dB
ssburst.BlockPattern = 'Case B'; % SS burst pattern with 30kHz SCS
ssburst.TransmittedBlocks = [1 1 1 1]; % Bitmap for blocks in a 5ms half-frame
ssburst.Period = 20; % SS burst periodicity in ms
ssburst.NCRBSSB = []; % Frequency offset for SS burst
% Generate waveform
[waveform,info] = nrWaveformGenerator(waveconfig);
scsCarrier = nrSCSCarrierConfig;
scsCarrier.SubcarrierSpacing = subcarrierSpacing;
scsCarrier.NSizeGrid = 273;
scsCarrier.NStartGrid = 0;
waveconfig.SCSCarriers = {scsCarrier};
modConfig = nrPDSCHConfig;
modConfig.Modulation = modulationScheme;
modConfig.NumLayers = 1;
modConfig.MappingType = 'A';
figure;
plot(SNRdB, throughputResults, '-x');
title('Throughput vs. SNR for 5G NR Link-Level Simulation’);
Wave Generation with Feasible NR Subcarrier Spacing
% OFDM Modulation
waveform = nrOFDMModulate(carrier, modulatedSymbols);
% Spectrum Analysis
fs = nrOFDMInfo(carrier).SampleRate; % Sampling rate based on carrier con g
spectrumAnalyzer = spectrumAnalyzer('SampleRate', fs, ...
'Title', ['Spectrum of Waveform with ', num2str(carrier.SubcarrierSpacing), ' kHz SCS']);
spectrumAnalyzer(waveform);
% Transmitter Operations
disp('Transmitter: Encoding and Modulating Data...');
codedBits = nrDLSCH(data, pdsch.Modulation, pdsch.NumLayers, 0.5); % LDPC Coding
pdschSymbols = nrPDSCH(carrier, pdsch, codedBits); % Modulation
txWaveform = nrOFDMModulate(carrier, pdschSymbols); % OFDM Modulation
% Channel Model
disp('Channel: Applying Propagation E ects...');
channel = nrCDLChannel;
channel.DelayPro le = 'CDL-A'; % Channel Delay Pro le (TR 38.901)
channel.DelaySpread = 300e-9; % Delay Spread
channel.MaximumDopplerShift = 5; % Doppler Shift
channel.SampleRate = nrOFDMInfo(carrier).SampleRate;
% Receiver Operations
disp('Receiver: Demodulating and Decoding...');
rxGrid = nrOFDMDemodulate(carrier, rxWaveform); % OFDM Demodulation
[rxSymbols, csi] = nrPDSCHDecode(carrier, pdsch, rxGrid); % PDSCH Decoding
[decodedData, crcError] = nrDLSCHDecode(rxSymbols, codedBits); % LDPC Decoding
% Display Results
disp('Simulation Results:');
if crcError
disp('Decoding Failed (CRC Error)');
else
disp('Decoding Successful');
end
% Constellation Diagram
constellation = comm.ConstellationDiagram('Title', 'Constellation at Receiver');
constellation(rxSymbols);
% Spectrum Analysis
spectrumAnalyzer = spectrumAnalyzer('SampleRate', channel.SampleRate, ...
'Title', 'Spectrum of Received Waveform');
spectrumAnalyzer(rxWaveform);
% Time-Domain Waveform
gure;
plot(real(rxWaveform));
title('Time-Domain Waveform of Received Signal');
xlabel('Sample Index');
ylabel('Amplitude');
fi
fi
fi
fi
fi
fi
fi
ff
fi
fi
fi
ff
fi
Link Performance Analysis (BLER and Throughput Calculation)
% Simulation Parameters
simParameters = struct();
simParameters.NFrames = 2; % Number of 10 ms frames
simParameters.SNRIn = [-5 0 5]; % SNR range (dB)
% Simulation Diagnostics
simParameters.DisplaySimulationInformation = true;
simParameters.DisplayDiagnostics = false;
% PDSCH/DL-SCH Parameters
simParameters.PDSCH = nrPDSCHCon g;
simParameters.PDSCH.PRBSet = 0:simParameters.Carrier.NSizeGrid-1;
simParameters.PDSCH.SymbolAllocation = [0, simParameters.Carrier.SymbolsPerSlot];
simParameters.PDSCH.MappingType = 'A';
simParameters.PDSCH.NID = simParameters.Carrier.NCellID;
simParameters.PDSCH.RNTI = 1;
% Propagation Channel
simParameters.DelayPro le = 'CDL-C';
simParameters.DelaySpread = 300e-9;
simParameters.MaximumDopplerShift = 5;
% Processing Loop
maxThroughput = zeros(length(simParameters.SNRIn), 1);
simThroughput = zeros(length(simParameters.SNRIn), 1);
% DL-SCH Encoder/Decoder
encodeDLSCH = nrDLSCH;
encodeDLSCH.MultipleHARQProcesses = true;
decodeDLSCH = nrDLSCHDecoder;
decodeDLSCH.MultipleHARQProcesses = true;
% Total Slots
NSlots = simParameters.NFrames * simParameters.Carrier.SlotsPerFrame;
% Throughput Calculation
simThroughput(snrIdx) = calculateThroughput(harqEntity);
end
% Results
disp('Simulation Throughput Results:');
disp(simThroughput);
fi
fi
fi
fi
fi
fi
wave generation for exible NR subcarrier spacing
scscarriers{2}.SubcarrierSpacing = 30;
scscarriers{2}.NSizeGrid = 106;
scscarriers{2}.NStartGrid = 1;
% Generate Waveform
[waveform, info] = nrWaveformGenerator(wavecon g);
% Bandwidth Parts
bwp = {nrWavegenBWPCon g, nrWavegenBWPCon g};
bwp{1}.Label = 'BWP1';
bwp{1}.SubcarrierSpacing = 15;
bwp{1}.CyclicPre x = 'Normal';
bwp{1}.NSizeBWP = 25; % Size in PRBs
bwp{1}.NStartBWP = 12; % Start of BWP relative to point A
bwp{2}.Label = 'BWP2';
bwp{2}.SubcarrierSpacing = 30;
bwp{2}.CyclicPre x = 'Normal';
bwp{2}.NSizeBWP = 50; % Size in PRBs
bwp{2}.NStartBWP = 51; % Start of BWP relative to point A
% Assign BWPs
wavecon g.BandwidthParts = bwp;
% Assign SS Burst
wavecon g.SSBurst = ssburst;
% Generate Waveform
[waveform, info] = nrWaveformGenerator(wavecon g);
% Plot Spectrogram
samplerate = info.ResourceGrids(1).Info.SampleRate;
n t = info.ResourceGrids(1).Info.N t;
gure;
spectrogram(waveform(:,1), ones(n t, 1), 0, n t, 'centered', samplerate, 'yaxis', 'MinThreshold', -130);
title('Spectrogram of 5G Downlink Baseband Waveform’);
fi
fi
ff
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
ff
ff
ff
fi
fi
fi
fi
fi
fl
Link-Level Simulation for 5G NR
% HARQ Parameters
simParameters.PDSCHExtension.EnableHARQ = true;
simParameters.PDSCHExtension.NHARQProcesses = 16;
simParameters.PDSCHExtension.TargetCodeRate = 0.4785;
% Waveform Information
waveformInfo = nrOFDMInfo(simParameters.Carrier);
% Channel Model
channel = nrCDLChannel;
channel.DelayPro le = simParameters.DelayPro le;
channel.DelaySpread = simParameters.DelaySpread;
channel.SampleRate = waveformInfo.SampleRate;
channel.NumTransmitAntennas = simParameters.PDSCH.NumLayers;
channel.NumReceiveAntennas = simParameters.PDSCH.NumLayers;
% Simulation Loops
maxThroughput = zeros(length(simParameters.SNRIn), 1);
simThroughput = zeros(length(simParameters.SNRIn), 1);
rvSeq = [0 2 3 1];
encodeDLSCH = nrDLSCH;
decodeDLSCH = nrDLSCHDecoder;
% Plot Results
gure;
plot(simParameters.SNRIn, simThroughput, '-o');
xlabel('SNR (dB)');
ylabel('Throughput');
title('5G NR Link-Level Simulation Results');
grid on;
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
Transenter, Chamel Modeling, and Raveler Censins for 5G NR
% Simulation Parameters
simParams = struct();
simParams.Carrier = nrCarrierCon g;
simParams.Carrier.NSizeGrid = 51; % Bandwidth in RBs
simParams.Carrier.SubcarrierSpacing = 30; % Subcarrier Spacing (kHz)
simParams.Carrier.CyclicPre x = 'Normal';
simParams.Carrier.NCellID = 1;
% Channel Parameters
simParams.DelayPro le = 'CDL-C'; % CDL-C Model
simParams.DelaySpread = 300e-9;
simParams.MaximumDopplerShift = 5;
simParams.SNRRange = [-5 0 5]; % SNR Range (dB)
% OFDM Information
waveformInfo = nrOFDMInfo(simParams.Carrier);
% PDSCH Modulation
pdschSymbols = nrPDSCH(simParams.Carrier, simParams.PDSCH, codedBits);
txWaveform = nrOFDMModulate(simParams.Carrier, pdschSymbols);
% Channel E ects
rxWaveform = awgn(channel(txWaveform), simParams.SNRRange(snrIdx), 'measured');
% Receiver Processing
rxGrid = nrOFDMDemodulate(simParams.Carrier, rxWaveform);
[rxSymbols, rxCsi] = nrPDSCHDecode(simParams.Carrier, simParams.PDSCH, rxGrid);
simParams.PDSCH = nrPDSCHCon g;
simParams.PDSCH.PRBSet = 0:simParams.Carrier.NSizeGrid-1; % Full bandwidth
simParams.PDSCH.SymbolAllocation = [0, simParams.Carrier.SymbolsPerSlot];
simParams.PDSCH.Modulation = '16QAM'; % Modulation scheme
simParams.PDSCH.NumLayers = 1; % Number of transmission layers
% HARQ Parameters
simParams.NHARQProcesses = 16;
simParams.TargetCodeRate = 0.5; % Coding rate
simParams.SNRRange = -5:5:20; % SNR points to simulate
% Initialize Results
numSNR = length(simParams.SNRRange);
BLER = zeros(numSNR, 1);
Throughput = zeros(numSNR, 1);
% Simulation Loop
for snrIdx = 1:numSNR
fprintf('Simulating for SNR = %d dB\n', simParams.SNRRange(snrIdx));
% Initialize Counters
totalBlocks = 0;
errorBlocks = 0;
totalThroughput = 0;
% Generate Frames
for frameIdx = 1:10
% Generate Random Data Block
trBlk = randi([0 1], nrTBS(simParams.PDSCH.Modulation, simParams.PDSCH.NumLayers, ...
numel(simParams.PDSCH.PRBSet), 12, simParams.TargetCodeRate), 1);
% Modulate PDSCH
txGrid = nrPDSCH(simParams.Carrier, simParams.PDSCH, codedBits);
txWaveform = nrOFDMModulate(simParams.Carrier, txGrid);
% Receiver Processing
rxGrid = nrOFDMDemodulate(simParams.Carrier, rxWaveform);
[rxSymbols, ~] = nrPDSCHDecode(simParams.Carrier, simParams.PDSCH, rxGrid);
% Update Counters
totalBlocks = totalBlocks + 1;
errorBlocks = errorBlocks + crcError;
totalThroughput = totalThroughput + (1 - crcError) * length(trBlk);
end
% Plot Results
gure;
subplot(2, 1, 1);
semilogy(simParams.SNRRange, BLER, '-o');
grid on;
xlabel('SNR (dB)');
ylabel('BLER');
title('Block Error Rate vs SNR');
subplot(2, 1, 2);
plot(simParams.SNRRange, Throughput, '-o');
grid on;
xlabel('SNR (dB)');
ylabel('Throughput (bps)');
title('Throughput vs SNR');
fi
fi
ff
fi
fi
fi
Block Error Rate (BLER) with the TR 38.901 propagation channel model
% Simulation Parameters
simParams = struct();
simParams.Carrier = nrCarrierCon g;
simParams.Carrier.NSizeGrid = 52; % Bandwidth in RBs
simParams.Carrier.SubcarrierSpacing = 30; % Subcarrier spacing (kHz)
simParams.Carrier.CyclicPre x = 'Normal';
simParams.Carrier.NCellID = 1;
% Results Initialization
numSNR = length(simParams.SNRRange);
BLER = zeros(numSNR, 1);
% Simulation Loop
for snrIdx = 1:numSNR
fprintf('Simulating for SNR = %d dB\n', simParams.SNRRange(snrIdx));
% Initialize Counters
totalBlocks = 0;
errorBlocks = 0;
% Generate Frames
for frameIdx = 1:10
% Generate Random Transport Block
trBlk = randi([0 1], nrTBS(simParams.PDSCH.Modulation, simParams.PDSCH.NumLayers, ...
numel(simParams.PDSCH.PRBSet), 12, simParams.TargetCodeRate), 1);
% PDSCH Modulation
pdschSymbols = nrPDSCH(simParams.Carrier, simParams.PDSCH, codedBits);
txWaveform = nrOFDMModulate(simParams.Carrier, pdschSymbols);
% Add AWGN
snr = simParams.SNRRange(snrIdx);
rxWaveform = awgn(rxWaveform, snr, 'measured');
% Receiver Processing
rxGrid = nrOFDMDemodulate(simParams.Carrier, rxWaveform);
[rxSymbols, ~] = nrPDSCHDecode(simParams.Carrier, simParams.PDSCH, rxGrid);
% Update Counters
totalBlocks = totalBlocks + 1;
errorBlocks = errorBlocks + crcError;
end
% Calculate BLER
BLER(snrIdx) = errorBlocks / totalBlocks;
end
% Initialize Results
numSNR = length(simParams.SNRRange);
BLER = zeros(numSNR, 1); % Block Error Rate
Throughput = zeros(numSNR, 1); % Throughput
% Simulation Loop
for snrIdx = 1:numSNR
fprintf('Simulating for SNR = %d dB\n', simParams.SNRRange(snrIdx));
% Initialize Counters
totalBlocks = 0;
errorBlocks = 0;
totalBits = 0;
successfulBits = 0;
% Frame Loop
for frameIdx = 1:10 % 10 frames
% Generate Random Transport Block
trBlk = randi([0 1], nrTBS(simParams.PDSCH.Modulation, simParams.PDSCH.NumLayers, ...
numel(simParams.PDSCH.PRBSet), 12, simParams.TargetCodeRate), 1);
% Channel E ects
channel.reset();
rxWaveform = channel(txWaveform);
% Add AWGN
rxWaveform = awgn(rxWaveform, simParams.SNRRange(snrIdx), 'measured');
% Receiver Processing
rxGrid = nrOFDMDemodulate(simParams.Carrier, rxWaveform);
[rxSymbols, ~] = nrPDSCHDecode(simParams.Carrier, simParams.PDSCH, rxGrid);
% Update Counters
totalBlocks = totalBlocks + 1;
errorBlocks = errorBlocks + crcError;
totalBits = totalBits + length(trBlk);
successfulBits = successfulBits + (~crcError) * length(trBlk);
end
% Plot Results
gure;
subplot(2, 1, 1);
semilogy(simParams.SNRRange, BLER, '-o');
grid on;
xlabel('SNR (dB)');
ylabel('BLER');
title('Block Error Rate vs SNR');
subplot(2, 1, 2);
plot(simParams.SNRRange, Throughput, '-o');
grid on;
xlabel('SNR (dB)');
ylabel('Throughput');
title('Throughput vs SNR');
fi
fi
fi
ff
fi
fi
fi
fi
fi
fi
5G NR RF Transmitter Modeling
% OFDM Modulation
txWaveform = nrOFDMModulate(txCon g, pdschSymbols);
% RF Impairments Modeling
% Add IQ Imbalance
txWaveform = iqimbalance(txWaveform, 0.01, 2); % 1% gain imbalance, 2° phase imbalance
% Add Nonlinearities
ampNonlinearity = comm.MemorylessNonlinearity('Method', 'Rapp model', ...
'InputScalingFactor', 0.5, 'SmoothingFactor', 2);
txWaveform = ampNonlinearity(txWaveform);
% Add Noise
txWaveform = awgn(txWaveform, 30, 'measured'); % Add AWGN with SNR of 30 dB
% Spectrum Analysis
spectrumAnalyzer = spectrumAnalyzer('SampleRate', nrOFDMInfo(txCon g).SampleRate, ...
'Title', '5G NR RF Transmitter Spectrum');
spectrumAnalyzer(txWaveform);
% EVM Analysis
evmAnalyzer = comm.EVM;
evmValue = evmAnalyzer(pdschSymbols, txWaveform);
disp(['EVM: ', num2str(evmValue), '%']);
% Constellation Analysis
constDiagram = comm.ConstellationDiagram('Title', 'Constellation of RF Transmitted Signal');
constDiagram(txWaveform);
% RF Receiver Parameters
snr = 30; % Signal-to-noise ratio (dB)
% Add AWGN
rxWaveform = awgn(txWaveform, snr, 'measured');
% Add Interference
fs = nrOFDMInfo(rxCon g).SampleRate;
interference = sqrt(10^(interferencePower/10)) * ...
cos(2*pi*interferenceFreqO set*(0:length(rxWaveform)-1)'/fs);
rxWaveform = rxWaveform + interference;
% Receiver Processing
% OFDM Demodulation
rxGrid = nrOFDMDemodulate(rxCon g, rxWaveform);
% PDSCH Decoding
[rxSymbols, rxCsi] = nrPDSCHDecode(rxCon g, pdschCon g, rxGrid, channelEstimate, noiseEstimate);
% Constellation Diagram
constDiagram = comm.ConstellationDiagram('Title', 'Constellation of RF Received Signal');
constDiagram(rxSymbols);
% Spectrum Analysis
spectrumAnalyzer = spectrumAnalyzer('SampleRate', fs, ...
'Title', 'Spectrum of Received Signal with Interference');
spectrumAnalyzer(rxWaveform);
% Simulation Parameters
numUEs = 10; % Number of User Equipment (UEs)
numRBs = 50; % Number of Resource Blocks
numSubframes = 100; % Simulation duration in subframes
subcarrierSpacing = 30; % Subcarrier spacing (kHz)
channelBandwidth = 20e6; % Channel bandwidth (Hz)
snrRange = [0, 5, 10, 15, 20]; % SNR values for UEs (dB)
% Initialize Results
throughputPerUE = zeros(numUEs, length(snrRange));
blerPerUE = zeros(numUEs, length(snrRange));
% Channel Model
channel = nrCDLChannel;
channel.DelayPro le = 'CDL-A';
channel.DelaySpread = 300e-9;
channel.MaximumDopplerShift = 5;
channel.SampleRate = channelBandwidth;
% Simulation Loop
for snrIdx = 1:length(snrRange)
snr = snrRange(snrIdx);
fprintf('Simulating for SNR = %d dB\n', snr);
% Channel E ects
channel.reset();
rxWaveform = channel(txWaveform);
% Add Noise
rxWaveform = awgn(rxWaveform, snr, 'measured');
% Store Results
throughputPerUE(ueIdx, snrIdx) = throughput;
blerPerUE(ueIdx, snrIdx) = bler;
end
end
% Plot Results
gure;
subplot(2, 1, 1);
plot(snrRange, mean(throughputPerUE, 1), '-o');
xlabel('SNR (dB)');
ylabel('Average Throughput (bps)');
title('Throughput vs SNR');
grid on;
subplot(2, 1, 2);
semilogy(snrRange, mean(blerPerUE, 1), '-o');
xlabel('SNR (dB)');
ylabel('Average BLER');
title('BLER vs SNR');
grid on;
fi
fi
ff
5G Network Simulation with Data Collection and Analysis
% Simulation Parameters
numUEs = 10; % Number of User Equipment (UEs)
numRBs = 50; % Number of Resource Blocks
numSubframes = 100; % Number of subframes for simulation
subcarrierSpacing = 30; % Subcarrier Spacing (kHz)
channelBandwidth = 20e6; % Channel Bandwidth (Hz)
snrRange = 0:5:20; % SNR range for analysis (dB)
% Channel Model
channel = nrCDLChannel;
channel.DelayPro le = 'CDL-C';
channel.DelaySpread = 300e-9;
channel.MaximumDopplerShift = 5;
channel.SampleRate = channelBandwidth;
% Simulation Loop
for snrIdx = 1:length(snrRange)
snr = snrRange(snrIdx);
fprintf('Simulating for SNR = %d dB\n', snr);
% Frame Loop
for frameIdx = 1:numSubframes
% Generate Random Data for UE
data = randi([0 1], 1000, 1);
% Modulate Data
txSymbols = nrModulate(data, '16QAM');
txWaveform = nrOFDMModulate(txSymbols, numRBs, subcarrierSpacing);
% Add AWGN
rxWaveform = awgn(rxWaveform, snr, 'measured');
% Receiver Processing
rxSymbols = nrOFDMDemodulate(rxWaveform, numRBs, subcarrierSpacing);
rxData = nrDemodulate(rxSymbols, '16QAM');
% Calculate Errors
errors = sum(rxData ~= data);
bler = errors / length(data);
% Update Counters
totalBlocks = totalBlocks + 1;
errorBlocks = errorBlocks + bler > 0;
totalBits = totalBits + length(data);
successfulBits = successfulBits + (1 - bler) * length(data);
end
fi
ff
% Calculate Performance Metrics
results.BLER(ueIdx, snrIdx) = errorBlocks / totalBlocks;
results.Throughput(ueIdx, snrIdx) = successfulBits / numSubframes;
end
end
% Visualization
gure;
% Throughput Analysis
subplot(2, 1, 1);
plot(snrRange, avgThroughput, '-o');
grid on;
xlabel('SNR (dB)');
ylabel('Average Throughput (bps)');
title('Average Throughput vs SNR');
% BLER Analysis
subplot(2, 1, 2);
semilogy(snrRange, avgBLER, '-o');
grid on;
xlabel('SNR (dB)');
ylabel('Average BLER');
title('Average BLER vs SNR');
9
9
10
10