0% found this document useful (0 votes)
42 views20 pages

5G NR Waveform & Simulation Guide

The document outlines the configuration and simulation of 5G NR waveforms, including downlink carrier setup, SCS carrier configurations, and link-level simulations for various SNR values. It details transmitter, channel, and receiver operations, as well as performance analysis through metrics like Bit Error Rate (BER) and throughput. The document also discusses waveform generation with flexible NR subcarrier spacing and includes code snippets for implementation.

Uploaded by

cit.dms1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views20 pages

5G NR Waveform & Simulation Guide

The document outlines the configuration and simulation of 5G NR waveforms, including downlink carrier setup, SCS carrier configurations, and link-level simulations for various SNR values. It details transmitter, channel, and receiver operations, as well as performance analysis through metrics like Bit Error Rate (BER) and throughput. The document also discusses waveform generation with flexible NR subcarrier spacing and includes code snippets for implementation.

Uploaded by

cit.dms1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

5G NR Waveform Generation for 3GPP 5G NR

% Create a downlink carrier configuration object


waveconfig = nrDLCarrierConfig;
waveconfig.Label = 'DL carrier 1'; % Label for this downlink waveform configuration
waveconfig.NCellID = 0; % Cell identity
waveconfig.ChannelBandwidth = 40; % Channel bandwidth (MHz)
waveconfig.FrequencyRange = 'FR1'; % 'FR1' or 'FR2'
waveconfig.NumSubframes = 10; % Number of 1 ms subframes in generated waveform
waveconfig.WindowingPercent = 0; % Windowing percentage
waveconfig.SampleRate = []; % Sample rate of the OFDM modulated waveform
waveconfig.CarrierFrequency = 0; % Carrier frequency in Hz

% Configure SCS carriers


scscarriers = {nrSCSCarrierConfig, nrSCSCarrierConfig};
scscarriers{1}.SubcarrierSpacing = 15;
scscarriers{1}.NSizeGrid = 216;
scscarriers{1}.NStartGrid = 0;
scscarriers{2}.SubcarrierSpacing = 30;
scscarriers{2}.NSizeGrid = 106;
scscarriers{2}.NStartGrid = 1;
waveconfig.SCSCarriers = scscarriers;

% 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

% Combine SS burst configuration with waveform configuration


waveconfig.SSBurst = ssburst;

% Generate waveform
[waveform,info] = nrWaveformGenerator(waveconfig);

% Display waveform info


disp('Waveform Information:');
disp(info);

% Plot the waveform if desired


figure;
plot(real(waveform));
title('5G NR Downlink Waveform');
xlabel('Sample');
ylabel('Amplitude');
Link-Level Simulation for 5G NR Release 15

% Step 1: Set up parameters


subcarrierSpacing = 30; % Subcarrier spacing in kHz (15, 30, or 60)
modulationScheme = '16QAM'; % Modulation scheme (QPSK, 16QAM, 64QAM)
channelModel = 'TDL-A'; % Channel model ('AWGN', 'TDL-A', 'CDL-B', etc.)
carrierFreq = 3.5e9; % Carrier frequency (Hz)
numFrames = 10; % Number of frames to simulate
SNRdB = 0:5:30; % Range of SNR values in dB

% Step 2: Configure the waveform


waveconfig = nrDLCarrierConfig;
waveconfig.NCellID = 1; % Cell ID
waveconfig.ChannelBandwidth = 100; % Channel bandwidth in MHz
waveconfig.FrequencyRange = 'FR1'; % 'FR1' or 'FR2'
waveconfig.NumSubframes = 10; % Number of subframes in generated waveform

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';

% Step 3: Set up channel model


tdlChannel = nrTDLChannel;
tdlChannel.DelayProfile = channelModel;
tdlChannel.DelaySpread = 30e-9; % Delay spread in seconds
tdlChannel.MaximumDopplerShift = 0; % Doppler shift in Hz
tdlChannel.SampleRate = waveconfig.SampleRate;

% Step 4: Configure receiver


rxConfig = nrRxConfig;
rxConfig.SNRdB = SNRdB;
rxConfig.EqualizerType = 'ZF'; % Zero-forcing equalizer

% Step 5: Run simulation across SNR values


berResults = zeros(size(SNRdB));
throughputResults = zeros(size(SNRdB));

for snrIdx = 1:length(SNRdB)


% Generate waveform
[waveform, info] = nrWaveformGenerator(waveconfig);

% Pass through the channel


tdlChannel.SNR = SNRdB(snrIdx);
receivedWaveform = tdlChannel(waveform);

% Demodulate and decode


rxBits = nrOFDMDemodulate(receivedWaveform, modConfig, rxConfig);

% Calculate BER and throughput


berResults(snrIdx) = biterr(info.GeneratedBits, rxBits) / numel(info.GeneratedBits);
throughputResults(snrIdx) = sum(rxBits) / numel(rxBits) * waveconfig.SampleRate;
end

% Step 6: Plot results


figure;
plot(SNRdB, berResults, '-o');
title('BER vs. SNR for 5G NR Link-Level Simulation');
xlabel('SNR (dB)'); xlabel('SNR (dB)');
ylabel('Bit Error Rate (BER)'); ylabel('Throughput (bps)');

figure;
plot(SNRdB, throughputResults, '-x');
title('Throughput vs. SNR for 5G NR Link-Level Simulation’);
Wave Generation with Feasible NR Subcarrier Spacing

% Carrier Con guration


carrier = nrCarrierCon g;
carrier.NSizeGrid = 100; % Number of Resource Blocks
carrier.SubcarrierSpacing = 15; % Subcarrier Spacing (15, 30, 60, 120, or 240 kHz)
carrier.CyclicPre x = 'Normal'; % Normal or Extended CP
carrier.NCellID = 1; % Physical cell ID

% Generate SCS-speci c con gurations


scsCon gurations = [15, 30, 60, 120, 240]; % Feasible NR Subcarrier Spacings

% Loop through SCS con gurations to generate and analyze waveforms


for scsIdx = 1:length(scsCon gurations)
% Update Subcarrier Spacing
carrier.SubcarrierSpacing = scsCon gurations(scsIdx);

% Generate Random Data


data = randi([0 1], 1000, 1); % Random binary data

% PDSCH Con guration


pdsch = nrPDSCHCon g;
pdsch.PRBSet = 0:carrier.NSizeGrid-1; % Full bandwidth allocation
pdsch.Modulation = '16QAM'; % QPSK, 16QAM, 64QAM, 256QAM
pdsch.NumLayers = 1; % Single-layer MIMO

% Generate Modulated Symbols


modulatedSymbols = nrPDSCH(carrier, pdsch, nrDLSCH(data, pdsch.Modulation,
pdsch.NumLayers, 0.5));

% OFDM Modulation
waveform = nrOFDMModulate(carrier, modulatedSymbols);

% Plot Time-Domain Waveform


gure;
plot(real(waveform));
title(['Time-Domain Waveform with ', num2str(carrier.SubcarrierSpacing), ' kHz SCS']);
xlabel('Sample Index');
ylabel('Amplitude');

% 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);

% Pause to view plots before proceeding to next con guration


pause(2);
end
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
Transmitter, Channel, and Receiver :-

% Transmitter Con guration


carrier = nrCarrierCon g; % 5G NR Carrier Con guration
carrier.NSizeGrid = 52; % Number of Resource Blocks
carrier.SubcarrierSpacing = 30; % Subcarrier Spacing (kHz)
carrier.CyclicPre x = 'Normal'; % Cyclic Pre x
carrier.NCellID = 1; % Cell ID

% PDSCH Con guration


pdsch = nrPDSCHCon g; % Physical Downlink Shared Channel
pdsch.PRBSet = 0:carrier.NSizeGrid-1; % Full Bandwidth Allocation
pdsch.Modulation = '16QAM'; % Modulation Scheme
pdsch.NumLayers = 1; % Single-layer MIMO
pdsch.RNTI = 1; % Radio Network Temporary Identi er

% Generate Random Data


data = randi([0 1], 1000, 1); % Random Binary Data

% 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;

% Add Channel Impairments


channel.reset();
rxWaveform = channel(txWaveform); % Apply Channel E ects
rxWaveform = awgn(rxWaveform, 20, 'measured'); % Add AWGN with SNR of 20 dB

% 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)

% Channel Estimator Con guration


simParameters.PerfectChannelEstimator = true;

% Simulation Diagnostics
simParameters.DisplaySimulationInformation = true;
simParameters.DisplayDiagnostics = false;

% Carrier and PDSCH Con guration


simParameters.Carrier = nrCarrierCon g;
simParameters.Carrier.NSizeGrid = 51; % Bandwidth in resource blocks
simParameters.Carrier.SubcarrierSpacing = 30; % 15, 30, 60, 120 (kHz)
simParameters.Carrier.CyclicPre x = 'Normal'; % 'Normal' or 'Extended'
simParameters.Carrier.NCellID = 1; % Cell identity

% 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;

% Modulation and Layers


simParameters.PDSCH.Modulation = '16QAM';
simParameters.PDSCH.NumLayers = 2;

% 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);

% Redundancy Version Sequence


rvSeq = [0 2 3 1];

% DL-SCH Encoder/Decoder
encodeDLSCH = nrDLSCH;
encodeDLSCH.MultipleHARQProcesses = true;
decodeDLSCH = nrDLSCHDecoder;
decodeDLSCH.MultipleHARQProcesses = true;

% Loop Over SNR Points


for snrIdx = 1:numel(simParameters.SNRIn)
fprintf('Simulating for SNR=%gdB\n', simParameters.SNRIn(snrIdx));

% Initialize HARQ Processes


harqEntity = HARQEntity(0:15, rvSeq, simParameters.PDSCH.NumCodewords);

% Total Slots
NSlots = simParameters.NFrames * simParameters.Carrier.SlotsPerFrame;

% Loop Over Slots


for nslot = 0:NSlots-1
% Generate Transport Blocks
trBlk = randi([0 1], nrTBS(simParameters.PDSCH.Modulation, simParameters.PDSCH.NumLayers, ...
numel(simParameters.PDSCH.PRBSet), 12, 0.4785), 1);
encodeDLSCH(trBlk);

% Modulate and Transmit


txWaveform = nrOFDMModulate(simParameters.Carrier, nrPDSCH(simParameters.Carrier, ...
simParameters.PDSCH, encodeDLSCH));

% Add Channel Effects


rxWaveform = awgn(txWaveform, simParameters.SNRIn(snrIdx), 'measured');

% Demodulate and Decode


rxGrid = nrOFDMDemodulate(simParameters.Carrier, rxWaveform);
[rxSymbols, rxCsi] = nrPDSCHDecode(simParameters.Carrier, simParameters.PDSCH, rxGrid);
decodeDLSCH(rxSymbols);
end

% 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

% Con gure Downlink Carrier


wavecon g = nrDLCarrierCon g; % Create a downlink carrier con guration object
wavecon g.Label = 'DL carrier 1'; % Label for this downlink waveform con guration
wavecon g.NCellID = 0; % Cell identity
wavecon g.ChannelBandwidth = 40; % Channel bandwidth (MHz)
wavecon g.FrequencyRange = 'FR1'; % 'FR1' or 'FR2'
wavecon g.NumSubframes = 10; % Number of 1 ms subframes in generated
waveform
wavecon g.WindowingPercent = 0; % Percentage of windowing relative to FFT length
wavecon g.SampleRate = []; % Sample rate of the OFDM modulated waveform
wavecon g.CarrierFrequency = 0; % Carrier frequency in Hz

% De ne SCS Speci c Carriers


scscarriers = {nrSCSCarrierCon g, nrSCSCarrierCon g};
scscarriers{1}.SubcarrierSpacing = 15;
scscarriers{1}.NSizeGrid = 216;
scscarriers{1}.NStartGrid = 0;

scscarriers{2}.SubcarrierSpacing = 30;
scscarriers{2}.NSizeGrid = 106;
scscarriers{2}.NStartGrid = 1;

% Assign SCS Carriers to the Waveform Con guration


wavecon g.SCSCarriers = scscarriers;

% Generate Waveform
[waveform, info] = nrWaveformGenerator(wavecon g);

% Plot the Magnitude of the Waveform


gure;
plot(abs(waveform));
title('Magnitude of 5G Downlink Baseband Waveform');
xlabel('Sample Index');
ylabel('Magnitude');

% Plot the Spectrogram of the Waveform


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
fl
fi
fi
ff
ff
fi
ff
fi
fi
fi
fi
5G NR uplink and downlink waveform generation with exible subcarrier spacing
and CBP (Bandwidth Parts)

% Waveform Con guration


wavecon g = nrDLCarrierCon g; % Downlink carrier con guration object
wavecon g.Label = '5G NR DL'; % Label for the waveform con guration
wavecon g.NCellID = 0; % Cell identity
wavecon g.ChannelBandwidth = 40; % Channel bandwidth (MHz)
wavecon g.FrequencyRange = 'FR1'; % Frequency range: 'FR1' or 'FR2'
wavecon g.NumSubframes = 10; % Number of 1 ms subframes
wavecon g.WindowingPercent = 0; % Percentage of windowing
wavecon g.SampleRate = []; % Auto-sampled waveform

% SCS Speci c Carriers


scscarriers = {nrSCSCarrierCon g, nrSCSCarrierCon g};
scscarriers{1}.SubcarrierSpacing = 15; % SCS for carrier 1
scscarriers{1}.NSizeGrid = 216; % Bandwidth in RBs
scscarriers{1}.NStartGrid = 0; % Start of the grid

scscarriers{2}.SubcarrierSpacing = 30; % SCS for carrier 2


scscarriers{2}.NSizeGrid = 106; % Bandwidth in RBs
scscarriers{2}.NStartGrid = 1; % Start of the grid

% Assign SCS Carriers


wavecon g.SCSCarriers = scscarriers;

% SS Burst Con guration


ssburst = nrWavegenSSBurstCon g;
ssburst.Enable = 1;
ssburst.Power = 0; % Power scaling in dB
ssburst.BlockPattern = 'Case B'; % Subcarrier spacing: 30kHz
ssburst.TransmittedBlocks = [1 1 1 1]; % Bitmap for blocks transmitted
ssburst.Period = 20; % Periodicity (ms)

% 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 Magnitude of the Waveform


gure;
plot(abs(waveform));
title('Magnitude of 5G Downlink Baseband Waveform');
xlabel('Sample Index');
ylabel('Magnitude');

% 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

% Initialize Simulation Parameters


simParameters = struct();
simParameters.NFrames = 2; % Number of 10 ms frames
simParameters.SNRIn = [-5 0 5]; % SNR range (dB)
simParameters.PerfectChannelEstimator = true;
simParameters.DisplaySimulationInformation = true;

% Carrier Con guration


simParameters.Carrier = nrCarrierCon g;
simParameters.Carrier.NSizeGrid = 51; % Bandwidth in resource blocks
simParameters.Carrier.SubcarrierSpacing = 30; % Subcarrier spacing (kHz)
simParameters.Carrier.CyclicPre x = 'Normal';
simParameters.Carrier.NCellID = 1;

% PDSCH Con guration


simParameters.PDSCH = nrPDSCHCon g;
simParameters.PDSCH.PRBSet = 0:simParameters.Carrier.NSizeGrid-1;
simParameters.PDSCH.SymbolAllocation = [0, simParameters.Carrier.SymbolsPerSlot];
simParameters.PDSCH.Modulation = '16QAM';
simParameters.PDSCH.NumLayers = 2;

% Channel Con guration


simParameters.DelayPro le = 'CDL-C';
simParameters.DelaySpread = 300e-9;
simParameters.MaximumDopplerShift = 5;

% 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;

for snrIdx = 1:numel(simParameters.SNRIn)


fprintf('Simulating for SNR=%gdB\n', simParameters.SNRIn(snrIdx));
NSlots = simParameters.NFrames * simParameters.Carrier.SlotsPerFrame;
for nslot = 0:NSlots-1
trBlk = randi([0 1], 1000, 1);
[codedBits, harqInfo] = encodeDLSCH(trBlk);
txGrid = nrPDSCH(simParameters.Carrier, simParameters.PDSCH, codedBits);
txWaveform = nrOFDMModulate(simParameters.Carrier, txGrid);
rxWaveform = awgn(txWaveform, simParameters.SNRIn(snrIdx), 'measured');
rxGrid = nrOFDMDemodulate(simParameters.Carrier, rxWaveform);
[rxSymbols, rxCsi] = nrPDSCHDecode(simParameters.Carrier, simParameters.PDSCH, rxGrid);
decodeDLSCH(rxSymbols, harqInfo);
end
simThroughput(snrIdx) = calculateThroughput(harqInfo);
end

% 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;

% PDSCH Con guration


simParams.PDSCH = nrPDSCHCon g;
simParams.PDSCH.PRBSet = 0:simParams.Carrier.NSizeGrid-1;
simParams.PDSCH.SymbolAllocation = [0, simParams.Carrier.SymbolsPerSlot];
simParams.PDSCH.Modulation = '16QAM';
simParams.PDSCH.NumLayers = 2;

% 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);

% CDL Channel Object


channel = nrCDLChannel;
channel.DelayPro le = simParams.DelayPro le;
channel.DelaySpread = simParams.DelaySpread;
channel.MaximumDopplerShift = simParams.MaximumDopplerShift;
channel.SampleRate = waveformInfo.SampleRate;

% Processing Loop for Each SNR


for snrIdx = 1:length(simParams.SNRRange)
fprintf('Simulating for SNR=%ddB\n', simParams.SNRRange(snrIdx));

% Generate Random Data


trBlk = randi([0 1], 1000, 1);
codedBits = nrDLSCH(trBlk);

% 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);

% Error Vector Magnitude (EVM)


evm = comm.EVM;
evmVal = evm(pdschSymbols, rxSymbols);
fprintf('EVM at SNR %d dB: %.2f%%\n', simParams.SNRRange(snrIdx), evmVal);
end

% Plot Throughput Results


gure;
plot(simParams.SNRRange, evmVal, '-o');
xlabel('SNR (dB)');
ylabel('EVM (%)');
title('EVM Performance for 5G NR');
grid on;
fi
fi
ff
fi
fi
fi
fi
fi
fi
Link Performance Analysis for 5G NR: BLER and Throughput
% Simulation Parameters
simParams = struct();
simParams.Carrier = nrCarrierCon g;
simParams.Carrier.NSizeGrid = 52; % Number of resource blocks
simParams.Carrier.SubcarrierSpacing = 30; % Subcarrier spacing (kHz)
simParams.Carrier.CyclicPre x = 'Normal';
simParams.Carrier.NCellID = 1;

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

% CDL Channel Model


channel = nrCDLChannel;
channel.DelayPro le = 'CDL-A';
channel.DelaySpread = 300e-9;
channel.MaximumDopplerShift = 5;
channel.SampleRate = nrOFDMInfo(simParams.Carrier).SampleRate;

% 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));

% Reset HARQ Processes


harqProcesses = HARQEntity(0:simParams.NHARQProcesses-1, [0 2 3 1], simParams.PDSCH.NumLayers);

% 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);

% Encode Data Block


[codedBits, harqInfo] = nrDLSCH(trBlk);

% Modulate PDSCH
txGrid = nrPDSCH(simParams.Carrier, simParams.PDSCH, codedBits);
txWaveform = nrOFDMModulate(simParams.Carrier, txGrid);

% Add Channel E ects


rxWaveform = awgn(channel(txWaveform), simParams.SNRRange(snrIdx), 'measured');

% Receiver Processing
rxGrid = nrOFDMDemodulate(simParams.Carrier, rxWaveform);
[rxSymbols, ~] = nrPDSCHDecode(simParams.Carrier, simParams.PDSCH, rxGrid);

% Decode Data Block


[decBlk, crcError] = nrDLSCHDecode(rxSymbols, harqInfo);

% Update Counters
totalBlocks = totalBlocks + 1;
errorBlocks = errorBlocks + crcError;
totalThroughput = totalThroughput + (1 - crcError) * length(trBlk);
end

% Calculate BLER and Throughput


BLER(snrIdx) = errorBlocks / totalBlocks;
Throughput(snrIdx) = totalThroughput / (totalBlocks * 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;

% PDSCH Con guration


simParams.PDSCH = nrPDSCHCon g;
simParams.PDSCH.PRBSet = 0:simParams.Carrier.NSizeGrid-1;
simParams.PDSCH.SymbolAllocation = [0, simParams.Carrier.SymbolsPerSlot];
simParams.PDSCH.Modulation = '16QAM';
simParams.PDSCH.NumLayers = 2;

% Channel Model Parameters (TR 38.901 CDL-C)


channel = nrCDLChannel;
channel.DelayPro le = 'CDL-C'; % TR 38.901 standard model
channel.DelaySpread = 300e-9; % Delay spread (s)
channel.MaximumDopplerShift = 5; % Doppler shift (Hz)
channel.SampleRate = nrOFDMInfo(simParams.Carrier).SampleRate;

% Simulation Range and HARQ Con guration


simParams.SNRRange = -10:5:20; % SNR points (dB)
simParams.HARQProcesses = 16;
simParams.TargetCodeRate = 0.5;

% 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);

% Encode Transport Block


[codedBits, harqInfo] = nrDLSCH(trBlk);

% PDSCH Modulation
pdschSymbols = nrPDSCH(simParams.Carrier, simParams.PDSCH, codedBits);
txWaveform = nrOFDMModulate(simParams.Carrier, pdschSymbols);

% Channel Model E ects


channel.reset();
rxWaveform = channel(txWaveform);

% 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);

% Decode Transport Block


[decBlk, crcError] = nrDLSCHDecode(rxSymbols, harqInfo);

% Update Counters
totalBlocks = totalBlocks + 1;
errorBlocks = errorBlocks + crcError;
end

% Calculate BLER
BLER(snrIdx) = errorBlocks / totalBlocks;
end

% Plot BLER vs SNR


gure;
semilogy(simParams.SNRRange, BLER, '-o');
grid on;
xlabel('SNR (dB)');
ylabel('BLER');
title('BLER vs SNR (TR 38.901 CDL-C)');
fi
fi
fi
ff
fi
fi
fi
fi
5G NR Link Level Performance Analysis, focusing on the Physical Downlink Shared Channel
(PDSCH):

% Initialize Simulation Parameters


simParams = struct();
simParams.Carrier = nrCarrierCon g; % Carrier con guration
simParams.Carrier.NSizeGrid = 52; % Number of resource blocks
simParams.Carrier.SubcarrierSpacing = 30; % Subcarrier spacing (kHz)
simParams.Carrier.CyclicPre x = 'Normal';
simParams.Carrier.NCellID = 1;

% PDSCH Con guration


simParams.PDSCH = nrPDSCHCon g;
simParams.PDSCH.PRBSet = 0:simParams.Carrier.NSizeGrid-1; % Full grid allocation
simParams.PDSCH.SymbolAllocation = [0, simParams.Carrier.SymbolsPerSlot]; % Full slot
simParams.PDSCH.Modulation = '16QAM'; % QPSK, 16QAM, 64QAM, 256QAM
simParams.PDSCH.NumLayers = 2; % Number of transmission layers
simParams.PDSCH.RNTI = 100; % Radio network temporary identi er

% HARQ and Simulation Range


simParams.NHARQProcesses = 16; % Number of HARQ processes
simParams.TargetCodeRate = 0.5; % Target coding rate
simParams.SNRRange = -5:5:20; % SNR range (dB)

% CDL Channel Model Con guration


channel = nrCDLChannel;
channel.DelayPro le = 'CDL-C'; % CDL propagation model
channel.DelaySpread = 300e-9; % Delay spread (s)
channel.MaximumDopplerShift = 5; % Doppler shift (Hz)
channel.SampleRate = nrOFDMInfo(simParams.Carrier).SampleRate;

% 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);

% Encode Transport Block


[codedBits, harqInfo] = nrDLSCH(trBlk);

% PDSCH Modulation and Grid Mapping


pdschSymbols = nrPDSCH(simParams.Carrier, simParams.PDSCH, codedBits);
txWaveform = nrOFDMModulate(simParams.Carrier, pdschSymbols);

% 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);

% Decode Transport Block


[decBlk, crcError] = nrDLSCHDecode(rxSymbols, harqInfo);

% Update Counters
totalBlocks = totalBlocks + 1;
errorBlocks = errorBlocks + crcError;
totalBits = totalBits + length(trBlk);
successfulBits = successfulBits + (~crcError) * length(trBlk);
end

% Calculate BLER and Throughput


BLER(snrIdx) = errorBlocks / totalBlocks;
Throughput(snrIdx) = successfulBits / totalBits;
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

% Transmitter Con guration


txCon g = nrCarrierCon g; % Carrier con guration
txCon g.NSizeGrid = 100; % Resource blocks
txCon g.SubcarrierSpacing = 30; % Subcarrier spacing (kHz)
txCon g.CyclicPre x = 'Normal';
txCon g.NCellID = 1; % Cell identity

% PDSCH Con guration


pdschCon g = nrPDSCHCon g;
pdschCon g.PRBSet = 0:txCon g.NSizeGrid-1; % Full bandwidth allocation
pdschCon g.Modulation = '16QAM'; % Modulation scheme
pdschCon g.NumLayers = 1; % Single antenna
pdschCon g.RNTI = 1;

% Generate Data and Modulate


data = randi([0 1], 1000, 1); % Random binary data
codedData = nrDLSCH(data, pdschCon g.Modulation, pdschCon g.NumLayers, pdschCon g.TargetCodeRate);
pdschSymbols = nrPDSCH(txCon g, pdschCon g, codedData);

% 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 Phase Noise


phaseNoise = comm.PhaseNoise('Level', -80, 'FrequencyO set', 1e6);
txWaveform = phaseNoise(txWaveform);

% 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);

% Time-Domain Waveform Plot


gure;
plot(real(txWaveform));
title('Time-Domain Waveform of RF Transmitted Signal');
xlabel('Sample Index');
ylabel('Amplitude');
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
ff
fi
fi
fi
5G NR RF Receiver Modeling and Testing with Interference

% Receiver Con guration


rxCon g = nrCarrierCon g; % Carrier con guration
rxCon g.NSizeGrid = 100; % Resource blocks
rxCon g.SubcarrierSpacing = 30; % Subcarrier spacing (kHz)
rxCon g.CyclicPre x = 'Normal';
rxCon g.NCellID = 1; % Cell identity

% PDSCH Con guration


pdschCon g = nrPDSCHCon g;
pdschCon g.PRBSet = 0:rxCon g.NSizeGrid-1; % Full bandwidth allocation
pdschCon g.Modulation = '16QAM'; % Modulation scheme
pdschCon g.NumLayers = 1; % Single antenna
pdschCon g.RNTI = 1;

% Interference Signal Con guration


interferenceFreqO set = 2e6; % Frequency o set of interference (Hz)
interferencePower = -20; % Interference power relative to signal (dB)

% RF Receiver Parameters
snr = 30; % Signal-to-noise ratio (dB)

% Generate Received Signal


data = randi([0 1], 1000, 1); % Random binary data
codedData = nrDLSCH(data, pdschCon g.Modulation, pdschCon g.NumLayers, pdschCon g.TargetCodeRate);
txSymbols = nrPDSCH(rxCon g, pdschCon g, codedData);
txWaveform = nrOFDMModulate(rxCon g, txSymbols);

% 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);

% Channel Estimation (Ideal for simplicity)


[channelEstimate, noiseEstimate] = nrChannelEstimate(rxGrid, pdschCon g);

% PDSCH Decoding
[rxSymbols, rxCsi] = nrPDSCHDecode(rxCon g, pdschCon g, rxGrid, channelEstimate, noiseEstimate);

% Error Vector Magnitude (EVM)


evmAnalyzer = comm.EVM;
evmValue = evmAnalyzer(txSymbols, rxSymbols);
disp(['EVM: ', num2str(evmValue), '%']);

% 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);

% Plot Time-Domain Received Signal


gure;
plot(real(rxWaveform));
title('Time-Domain Waveform of Received Signal with Interference');
xlabel('Sample Index');
ylabel('Amplitude');
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
ff
fi
fi
fi
fi
fi
ff
fi
fi
fi
fi
fi
fi
fi
fi
ff
fi
fi
fi
fi
5G Network Simulation

% 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);

for ueIdx = 1:numUEs


% Generate Random Data
data = randi([0 1], 1000, 1);

% Transmitter: Modulate Data


txSymbols = nrModulate(data, '16QAM');
txWaveform = nrOFDMModulate(txSymbols, numRBs, subcarrierSpacing);

% Channel E ects
channel.reset();
rxWaveform = channel(txWaveform);

% Add Noise
rxWaveform = awgn(rxWaveform, snr, 'measured');

% Receiver: Demodulate Data


rxSymbols = nrOFDMDemodulate(rxWaveform, numRBs, subcarrierSpacing);
rxData = nrDemodulate(rxSymbols, '16QAM');

% Calculate Throughput and BLER


errors = sum(rxData ~= data);
bler = errors / length(data);
throughput = (1 - bler) * length(data) / numSubframes;

% 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)

% Data Collection Initialization


results = struct();
results.SNR = snrRange;
results.Throughput = zeros(numUEs, length(snrRange));
results.BLER = zeros(numUEs, length(snrRange));

% 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);

for ueIdx = 1:numUEs


% Initialize Counters
totalBlocks = 0;
errorBlocks = 0;
successfulBits = 0;
totalBits = 0;

% 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);

% Apply Channel E ects


channel.reset();
rxWaveform = channel(txWaveform);

% 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

% Aggregate Data for Analysis


avgThroughput = mean(results.Throughput, 1);
avgBLER = mean(results.BLER, 1);

% 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');

% Save Results to CSV


lename = '5G_Simulation_Results.csv';
dataTable = array2table([snrRange', avgThroughput', avgBLER'], ...
'VariableNames', {'SNR_dB', 'Throughput_bps', 'BLER'});
writetable(dataTable, lename);

disp('Simulation complete. Results saved to 5G_Simulation_Results.csv');


fi
fi
fi
6 7

9
9
10

10

You might also like