Get started !
online LTE test
online C test

Updated or New
5G NR Data Rate calculator New
5G NR TBS calculator New
5G NR UE Registration New
Python programming
C++ programming
MIMO for 3GPP Developer - 2
Uplink power control
MIMO for 3GPP Developer
NR ARFCN and GSCN
5GS Interfaces



About
Feedback
Information Theory
Modulation
Multiple Access
DSP
OSI Model
Data Link layer
SS7
Word about ATM
GSM
GPRS
UMTS
WiMAX
LTE
CV2X
5G
Standard Reference
Reference books
Resources on Web
Miscellaneous
Mind Map
Magic MSC tool
Bar graph tool
C programming
C++ programming
Perl resources
Python programming
Javascript/HTML
MATLAB
ASCII table
Project Management

another knowledge site

3GPP Modem
Simulator


Sparkle At Office comic strip

Communication model with Simulink

Communication model with Simulink [Under MATLAB]

In article Small peek into LTE PHY chain (with MATLAB), we mentioned a simple communication model as below:



It basically has a Transmitter, a Channel, and a Receiver. How about we simulate the model and look at its Performance, say BER (Bit Error Rate)? Below MATLAB program does exactly this with one block of 2048 bits:

% DGSpark™ Copyright 2021 Samir Amberkar
% MATLAB Release 2021a

clear;clc;

% TX: Data generation and transmission
blockSize = 2048;
txBitStream = DGSpark_traffic_generator(blockSize);
txSignal = DGSpark_transmitter(txBitStream);

% Channel: Noise and impairments
[rxSignal, SNR] = DGSpark_noise_channel(txSignal);

% RX
rxBitStream = DGSpark_receiver(rxSignal);

% Performance measurement
[berValue, numErrors, blockSize] = DGSpark_BER_performance(txBitStream, rxBitStream);

SNR
berValue
numErrors
blockSize


Below is sample output:



Above program has five distinct modules, Traffic Generator, Transmitter, Channel, Receiver, and Performance measurement. In practice, we would have many more !

Telecom engineering team would implement these modules independently (in parallel by different teams/experts). System engineering team would then experiment with different configurations of individual modules by various possible combinations of PHY chain modules (say Turbo coding/decoding with Noise channel, LDPC coding/decoding + 16 QAM modulation/demodulation with Noise channel, and so on). This would require seamless additions/deletions of modules.

Also, it would be expected to run the simulation for certain number of iterations to reach to conclusion or to compare between various configurations.

Simulink brings these "design" and "iterative" views in MATLAB simulation !!

Below is design and implementation of above communication model using Simulink.

First picture below shows Simulink model and second picture shows the model after one sample run. This model did the same as our above MATLAB program, however perspective is now design, performance, and so on.





Below are the steps we followed to create the Simulink model.

Step 1: Create three blocks using "MATLAB function" block from Simulink Library Browser (Simulink tab) and name them TRANSMITTER, CHANNEL, and RECEIVER.



Step 2: Double click on each block - this would open editor, add appropriate input arguments, output arguments, and code. Example is shown below for TRANSMITTER. The code from above communication model MATLAB program is taken as reference.



% DGSpark™ Copyright 2021 Samir Amberkar
% MATLAB Release 2021a

function [txSignal, txBitStream] = DGSpark_TX()

   % Initialization
   blockSize = 2048;

   % Data generation and transmission
   txBitStream = DGSpark_traffic_generator(blockSize);
   txSignal = DGSpark_transmitter(txBitStream);

end


% DGSpark™ Copyright 2021 Samir Amberkar
% MATLAB Release 2021a

function [rxSignal, SNR] = DGSpark_Noisy(txSignal)

   [rxSignal, SNR] = DGSpark_noise_channel(txSignal);

end


% DGSpark™ Copyright 2021 Samir Amberkar
% MATLAB Release 2021a

function rxBitStream = DGSpark_RX(rxSignal)

   rxBitStream = DGSpark_receiver(rxSignal);

end


Step 3: Now update "Update method" of each block. Also ensure input and output arguments have correct properties as below:





















Step 4: To add "Error Rate Calculation" and "Moving Average" blocks, simply double click on open space, search, and add the block as shown below.





Step 5: Update properties of these blocks (right click > properties).





Step 6: Add "Display" blocks, connect all "ports" as below, click on "Run".



Below is code of all the functions called in above models:

% DGSpark™ Copyright 2021 Samir Amberkar
% MATLAB Release 2021a

function [bitStream] = DGSpark_traffic_generator(blockSize)

   bitStream = randi([0 1], blockSize, 1);

end


% DGSpark™ Copyright 2021 Samir Amberkar
% MATLAB Release 2021a

function [txSignal] = DGSpark_transmitter(bitStream)

   persistent qpskModulator;
   
   if(isempty(qpskModulator))
      qpskModulator = comm.QPSKModulator('BitInput',true);
   end
   
   txSignal = qpskModulator.step(bitStream);
   
end


% DGSpark Copyright 2021 Samir Amberkar
% MATLAB Release 2021a

function [rxSignal, SNR] = DGSpark_noise_channel(txSignal)

   persistent awgnChannel;
   
   if(isempty(awgnChannel))
      awgnChannel = comm.AWGNChannel('NoiseMethod','Signal to noise ratio (SNR)');
   end
   
   awgnChannel.SNR = randi([-5 5]);
   
   SNR = awgnChannel.SNR;
   rxSignal = awgnChannel.step(txSignal);

end


% DGSpark™ Copyright 2021 Samir Amberkar
% MATLAB Release 2021a

function [bitStream] = DGSpark_receiver(rxSignal)

   persistent qpskDemodulator;
   
   if(isempty(qpskDemodulator))
      qpskDemodulator = comm.QPSKDemodulator('BitOutput',true);
   end
   
   bitStream = qpskDemodulator.step(rxSignal);

end


% DGSpark™ Copyright 2021 Samir Amberkar
% MATLAB Release 2021a

function [berValue, numErrors, blockSize] = DGSpark_BER_performance(txBitStream, rxBitStream)

   persistent berCalculator;
   
   if(isempty(berCalculator))
      berCalculator = comm.ErrorRate;
   end
   
   performanceResults = berCalculator.step(txBitStream, rxBitStream);
   
   berValue = performanceResults(1);
   numErrors = performanceResults(2);
   blockSize = performanceResults(3);

end