Main Content

Bluetooth Full Duplex Data and Voice Transmission in MATLAB

This example shows how to model a full duplex communication in a Bluetooth® piconet having WLAN interference and supporting the adaptive frequency hopping (AFH) functionality using the Communications Toolbox™ Library for the Bluetooth Protocol. The Bluetooth nodes operating with basic rate (BR) physical layer (PHY) communicate with each other simultaneously by transmitting data packets (over an asynchronous connection-oriented (ACL) logical transport) and voice packets (over a synchronous connection-oriented (SCO) logical transport) as random bits. The supported data and voice packets are:

  • Data packet types: DM1, DH1, DM3, DH3, DM5, and DH5

  • Voice packet types: HV1, HV2, and HV3

This example enables AFH by classifying channels as good or bad based on the packet error rate (PER) of each channel. You can add your own classification algorithm to analyze the simulation results. The simulation results show a plot of the packet error rate (PER) for each Bluetooth node. The power spectral density of Bluetooth waveforms with WLAN interference is visualized using the spectrum analyzer.

Bluetooth Specifications

Bluetooth technology operates in 2.4 GHz industrial, scientific, and medical (ISM) band and shares it with other wireless technologies like ZigBee and WLAN. The Bluetooth Core Specification [1] defined by the Special Interest Group (SIG) specifies two PHY modes: the mandatory BR and the optional enhanced data rate (EDR). The Bluetooth BR/EDR radio implements a 1600 hops/s frequency hopping spread spectrum (FHSS) technique. The radio hops in a pseudo-random way on 79 designated Bluetooth channels. Each Bluetooth channel has a bandwidth of 1 MHz. Each channel is centered at (2402 + k) MHz, where k = 0, 1, ... 78. The modulation technique on the payload for BR and EDR mode is Gaussian frequency shift-keying (GFSK) and differential phase shift-keying (DPSK), respectively. The baud rate is 1 MSymbols/s. The Bluetooth BR/EDR radio uses a time-division duplex (TDD) scheme in which data transmission occurs in one direction at one time. The transmission alternates in two directions, one after the other.

Bluetooth and WLAN radios often operate in the same physical scenario and in the same device. Therefore, Bluetooth and WLAN transmissions can interfere with each other, thus impacting the performance and reliability of both the networks. To mitigate this interference, the IEEE 802.15.2 Task Group [2] recommends using the AFH technique. To study AFH and the coexistence of Bluetooth with WLAN, see Bluetooth-WLAN Coexistence.

For more information about the Bluetooth BR/EDR radio and the protocol stack, see Bluetooth Protocol Stack. For more information about Bluetooth BR/EDR packet structures, see Bluetooth Packet Structure.

Logical Transports

The Bluetooth system supports point-to-point or point-to-multipoint connections called as piconets. Each piconet consists of a node in the role of Master, with other nodes in the Slave role. The Master and Slave exchange data over multiple logical transports. These logical transports are:

  • SCO: The Master and Slave exchange SCO packets at regular intervals in the reserved slots. The Bluetooth nodes use SCO logical transport to exchange periodic data such as audio streaming. This logical transport does not support retransmissions.

  • Extended synchronous connection-oriented (eSCO): The Bluetooth nodes use eSCO to exchange periodic data such as audio streaming. This logical transport supports retransmissions.

  • ACL: The Bluetooth nodes use ACL to exchange asynchronous data such as a file transfer protocol (FTP). During each poll interval, the Master polls the ACL logical transport of a Slave at least once.

  • Active slave broadcast (ASB): The Bluetooth nodes use ASB logical transport to send messages from the Master to all of the Slaves in a piconet. This logical transport supports unidirectional traffic with no acknowledgments.

  • Connectionless slave broadcast (CSB): The Master node uses a CSB logical transport to send profile broadcast data to multiple Slaves. This logical transport supports unidirectional traffic with no acknowledgments.

This example supports ACL and SCO logical transports between a Master and Slaves by considering data as random bits of 0s and 1s. This figure shows the communication between a Master and three Slaves in a piconet over ACL and SCO logical transports.

Bluetooth uses reserved time slots for communication between the nodes. The duration of each slot is 625 microseconds. The Master node initiates the transmission in even slots and extends the transmission to odd slots when transmitting a multislot packet. The Slave node initiates the transmission in odd slots and extends the transmission to even slots when transmitting a multislot packet.

Check for Support Package Installation

% Check if the 'Communications Toolbox Library for the Bluetooth Protocol'
% support package is installed

Configure Simulation Parameters

This section shows how to configure the simulation parameters for the Bluetooth piconet, the wireless channel, and WLAN interference.

Bluetooth Piconet

The NumSlaves parameter specifies the number of Slaves in the Bluetooth piconet. The LinkTraffic parameter specifies the type of traffic over Bluetooth logical transports between a Master and the respective Slave. This table maps LinkTraffic to different logical transports.

If the Master communicates with multiple Slaves, LinkTraffic must be a vector.

The SequenceType parameter specifies the type of frequency hopping algorithm that the Bluetooth node uses. When you set SequenceType to 'Connection adaptive', the Bluetooth channels are classified as good or bad periodically based on the PER of each Bluetooth channel. To classify the Bluetooth channels, you can use the classifyChannels object function.

% Set the simulation time in microseconds
simulationTime = 3*1e6;

% Enable or disable the visualization in the example
enableVisualization = true;

simulationParameters = struct;
% Configure the number of Slaves in the piconet
simulationParameters.NumSlaves = 1;

% Specify the positions of Bluetooth nodes in the form of n-by-3 array.
% where n represents the number of nodes in the piconet. Each row specifies
% the cartesian coordinates of a nodes starting from Master and followed by
% Slaves.
simulationParameters.NodePositions = [10 0 0; 20 0 0];

% Configure the logical links between the Master and Slaves

% Each element represents the logical link between the Master and the
% respective Slave. If the Master is connected to multiple Slaves, this
% value must be a row vector.
simulationParameters.LinkTraffic = 1;

% Configure the frequency hopping sequence as 'Connection basic' or
% 'Connection adaptive'
simulationParameters.SequenceType = 'Connection adaptive';

% To enable an ACL logical transport, set linkTraffic to 1 or 3. Specify
% the ACL packet type as 'DM1', 'DH1', 'DM3', 'DH3', 'DM5', or 'DH5'.
simulationParameters.ACLPacketType = 'DM1';

% To enable a SCO logical transport, set linkTraffic to 2 or 3. Specify the
% SCO packet type as 'HV1', 'HV2', or 'HV3' for the respective Slave that
% has SCO link traffic. Here, 1 represents the Slave number, and 'HV3'
% represents the corresponding SCO packet type used by Slave 1.
simulationParameters.SCOPacketType = {1, 'HV3'};

Wireless Channel and WLAN Interference

Configure the wireless channel by using the helperBluetoothChannel helper object. You can set the EbNo value for the AWGN channel. To generate the WLAN signal interference, use the helperBluetoothGenerateWLANWaveform helper function. Specify the sources of WLAN interference by using the WLANInterference parameter. Use one of these options to specify the source of the WLAN interference.

  • 'Generated': To add a WLAN Toolbox™ signal, select this option. Perform the steps shown in further exploration to add the signal from the WLAN Toolbox™.

  • 'BasebandFile': To add a WLAN signal from a baseband file (.bb), select this option. You can specify the file name using the WLANBBFilename input argument. If you do not specify the .bb file, the example uses the default .bb file, '', to add the WLAN signal.

The 'None' option implies that no WLAN signal is added. AWGN is present throughout the simulation.

% Configure wireless channel parameters
simulationParameters.EbNo = 22; % Ratio of energy per bit (Eb) to spectral noise density (No) in dB

% Configure the WLAN interference

% Specify the WLAN interference as 'Generated', 'BasebandFile', or 'None'.
% To use the 'wlanBBFilename' option, set wlanInterference to
% 'BasebandFile'.
simulationParameters.WLANInterference = 'BasebandFile';
simulationParameters.WLANBBFilename =  '';

% Signal to interference ratio in dB
simulationParameters.SIR = [-15 -16];

Channel Classification Parameters

Classify the Bluetooth channels as good or bad by using the helperBluetoothChannelClassification object only when the SequenceType is 'Connection adaptive'. The example classifies the Bluetooth channels by using these parameters.

  • PERThreshold: PER threshold

  • ClassificationInterval: Periodicity (in slots) of channel classification

  • RxStatusCount: Maximum number of received packets status maintained for each channel

  • MinRxCountToClassify: Minimum number of received packets status for each channel to classify a channel as good or bad

  • PreferredMinimumGoodChannels: Preferred number of good channels required to communicate between the Master and Slaves

You can add your own classification algorithm by customizing the classifyChannels method of the helperBluetoothChannelClassification object.

simulationParameters.PERThreshold = 50;                 % Packet error rate
simulationParameters.ClassificationInterval = 3000;   % In slots
simulationParameters.RxStatusCount = 10;                % Maximum Rx packets status
simulationParameters.MinRxCountToClassify = 4;          % Minimum packets received
simulationParameters.PreferredMinimumGoodChannels = 20;  % Preferred number of good channels

Create Bluetooth Piconet

Specify the total number of Bluetooth nodes in the piconet. Set the role of the nodes as Master or Slave. To create a Bluetooth piconet from the configured parameters, use the helperBluetoothCreatePiconet helper function.

% Reset the random number generator

% Specify Tx power, in dBm
simulationParameters.TxPower = 20;

% Specify the Bluetooth node receiver range (in meters)
simulationParameters.ReceiverRange = 40;

% Set the total number of nodes in the piconet (one Master and multiple
% Slaves)
numNodes = simulationParameters.NumSlaves + 1;

% Create a Bluetooth piconet
btNodes = helperBluetoothCreatePiconet(simulationParameters);

To visualize the Bluetooth waveforms, create the dsp.SpectrumAnalyzer System™ object.

% View the Bluetooth waveforms using the spectrum analyzer
spectrumAnalyzer = dsp.SpectrumAnalyzer(...
    'Name','Bluetooth Full Duplex Communication', ...
    'ViewType','Spectrum and spectrogram', ...
    'TimeResolutionSource','Property', ...
    'TimeResolution',0.0005, ...
    'SampleRate',btNodes{1}.PHY.SamplesPerSymbol*1e6, ...
    'TimeSpanSource','Property', ...
    'TimeSpan',0.05, ...
    'FrequencyResolutionMethod','WindowLength', ...
    'WindowLength',512, ...
    'AxesLayout','Horizontal', ...
    'FrequencyOffset',2441*1e6, ...
    'ColorLimits',[-20 15]);


Simulate the Bluetooth piconet using the configured parameters. Visualize the plot of the PER of each Bluetooth node in the piconet. Visualize the power spectral density of the Bluetooth waveforms by using the dsp.SpectrumAnalyzer System object. You can also calculate the baseband layer statistics (total transmitted packets, total received packets, and total dropped packets) and channel classification statistics at each Bluetooth node. When the sequence type is set to 'Connection adaptive', the Bluetooth node updates the channel classification statistics.

% Current simulation time in microseconds
curTime = 0;

% Elapsed time in microseconds
elapsedTime = 0;

% Next invoke times of all of the nodes in microseconds
nextInvokeTimes = zeros(1, numNodes);

if enableVisualization
    % Plot the PER
    perFigure = figure("Name","PER of Each Bluetooth Node",'Tag','BluetoothPERPlot');
    perAxes = axes(perFigure);
    % Add annotations to the figure
    ylim(perAxes, [0 1]);
    xlabel(perAxes, 'Simulation Time (in Microseconds)');
    ylabel(perAxes, 'PER');
    title(perAxes, 'PER of Each Bluetooth Node');
    % Plot the PER line for each Bluetooth node
    [perPlots, legendStr] = deal(cell(1, numNodes));
    for plotIdx = 1:numNodes
        hold on
        perPlots{plotIdx} = plot(perAxes, curTime, 0);
        if plotIdx == 1
            legendStr{1} = ['\color[rgb]{' num2str(perPlots{plotIdx}.Color) '} Master'];
            legendStr{plotIdx} = ['\color[rgb]{' num2str(perPlots{plotIdx}.Color) '} Slave-' num2str(plotIdx-1)];
    % Add a legend to the figure
    legend(perAxes, legendStr,'Location','northeastoutside','Box','on');
    if ~strcmpi(simulationParameters.WLANInterference, 'None')
        % Generate the WLAN waveform for visualization
        wlanWaveform = helperBluetoothGenerateWLANWaveform(...
            simulationParameters.WLANInterference, simulationParameters.WLANBBFilename);

% Run the simulation
while(curTime < simulationTime)
    % Simulate the Bluetooth nodes
    for nodeIdx = 1:numNodes
        % Push the data into the node
        pushData(btNodes{nodeIdx}, ...
            simulationParameters.ACLPacketType, simulationParameters.SCOPacketType);
        % Run the Bluetooth node instance
        nextInvokeTimes(nodeIdx) = runNode(btNodes{nodeIdx}, elapsedTime);
        if enableVisualization
            if ~isempty(findobj('Tag', 'BluetoothPERPlot'))
                % Update and plot the PER
                perPlots{nodeIdx}.XData = [perPlots{nodeIdx}.XData curTime];
                if isempty(btNodes{nodeIdx}.PHY.PER)
                    per = 0;
                    per = btNodes{nodeIdx}.PHY.PER;
                perPlots{nodeIdx}.YData = [perPlots{nodeIdx}.YData per];

    % Update the current simulation time
    curTime = curTime + elapsedTime;

    % Distribute any transmitted packets from each node into the receiving
    % buffers of the other nodes
    [isPacketDistributed, txBuffer] = helperBluetoothDistributePackets(btNodes);
    % Update visualization
    if enableVisualization
        for txIdx = 1:numel(txBuffer)
            channelWaveform = txBuffer{txIdx}.Waveform(1:txBuffer{txIdx}.NumSamples);
            if ~strcmpi(simulationParameters.WLANInterference, 'None')
                % Add WLAN interference to the channel waveform
                channelWaveform = channelWaveform + wlanWaveform(1:txBuffer{txIdx}.NumSamples);
            % Plot the Bluetooth waveform

    % If packets are distributed to the receiver nodes, run the nodes to
    % check the packet reception buffer.
    if isPacketDistributed
        elapsedTime = 0;
    % Advance the simulation time to the next event at a node
        elapsedTime = min(nextInvokeTimes(nextInvokeTimes ~= -1));
ans = 1x79 logical array

   0   1   1   0   0   1   0   1   1   0   0   0   0   0   0   0   0   0   0   1   0   0   0   0   0   0   0   0   1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0

Figure PER of Each Bluetooth Node contains an axes. The axes with title PER of Each Bluetooth Node contains 2 objects of type line. These objects represent \color[rgb]{0 0.447 0.741} Master, \color[rgb]{0.85 0.325 0.098} Slave-1.


Figure Bluetooth Full Duplex Communication contains 2 axes and other objects of type uiflowcontainer, uimenu, uitoolbar. Axes 1 contains an object of type line. This object represents Channel 1. Axes 2 contains an object of type image.

The preceding spectrum analyzer plot shows the spectrum of the Bluetooth waveform distorted with WLAN interference (in the frequency domain) and passed through the AWGN channel. The right-side plot shows the overlapping of Bluetooth packets with the interfering WLAN signal.

The plot "PER of Each Bluetooth Node" shows the PER of each node in the Bluetooth piconet with respect to the simulation time.

To see the baseband layer statistics for each Bluetooth node, inspect the statisticsAtEachNode variable. To see the channel classification statistics for each Master-Slave pair, inspect the classificationStats variable. The channel classification statistics are valid when sequenceType is set to 'Connection adaptive'. Get the baseband layer and channel classification statistics of each Bluetooth node in the piconet.

% Get the baseband layer and channel classification statistics of each Bluetooth node in the piconet
[statisticsAtEachNode, classificationStats] = helperBluetoothFullDuplexStatistics(btNodes)
statisticsAtEachNode=2×19 table
              TotalRxPackets    TotalTxPackets    TxACLPackets    TxACLOneSlotPackets    TxACLThreeSlotPackets    TxACLFiveSlotPackets    RetransmittedACLPackets    RxSlotsWithNoPacket    TxSCOPackets    RxACLPackets    RxACLOneSlotPackets    RxACLThreeSlotPackets    RxACLFiveSlotPackets    RxSCOPackets    TotalRxFailedPackets    ACKedACLPackets    ACKedSCOPackets    DroppedPackets    DroppedLMPMessages
              ______________    ______________    ____________    ___________________    _____________________    ____________________    _______________________    ___________________    ____________    ____________    ___________________    _____________________    ____________________    ____________    ____________________    _______________    _______________    ______________    __________________

    Master         1435              2401         {7x2 double}       {7x2 double}            {7x2 double}             {7x2 double}             {7x2 double}                  965            {7x2 double}    {7x2 double}       {7x2 double}            {7x2 double}             {7x2 double}        {7x2 double}            157              {7x2 double}       {7x2 double}           254                  0         
    Slave1         2379              1444         {7x2 double}       {7x2 double}            {7x2 double}             {7x2 double}             {7x2 double}                    0            {7x2 double}    {7x2 double}       {7x2 double}            {7x2 double}             {7x2 double}        {7x2 double}            384              {7x2 double}       {7x2 double}           551                  0         

classificationStats=1×3 table
    LTAddress    ClassificationCount     ChannelMap  
    _________    ___________________    _____________

        1                 1             {1x79 double}

This example enables you to configure and simulate a full duplex data and voice communication in a Bluetooth piconet with WLAN interference. The example uses AFH to mitigate WLAN interference by classifying channels as good or bad based on the PER value. The performance of full duplex communication is analyzed by visualizing the impact of WLAN interference on each Bluetooth node.

Further Exploration

To add the WLAN signal using the features of the WLAN Toolbox™, set the value of wlanInterference to 'Generated'. Use this code to add the WLAN signal.

Add the WLAN signal generated using the features of the WLAN Toolbox™ as static signal interference to Bluetooth. To enable this, set wlanInterference value as 'Generated', add your custom signal generation code in function. Use this sample code snippet in WLAN signal generation using features of WLAN Toolbox™.

% % WLAN waveform to interfere with Bluetooth waveforms can be
% % modified by using the features of the WLAN Toolbox(TM).
% psduLength = 1000;
% % Create configuration object for WLAN waveform (802.11b)
% cfgNHT = wlanNonHTConfig('Modulation','DSSS', ...
%     'PSDULength', psduLength);
% % Create random PSDU
% psdu = randi([0 1], cfgNHT.PSDULength*8, 1);
% % Generate WLAN waveform
% wlanWaveform = wlanWaveformGenerator(psdu, cfgNHT);

You can add your custom signal generation code in the helperBluetoothGenerateWLANWaveform function. You can also write the respective signal WLAN spectrum masks and register to the WLANSpectrum property of the helperBluetoothChannel as a function pointer.


The example uses this object:

The example uses these helpers:

Selected Bibliography

  1. Bluetooth Special Interest Group (SIG). "Bluetooth Core Specification." Version 5.2.

  2. IEEE® Standard 802.15.2™. "Coexistence of Wireless Personal Area Networks with Other Wireless Devices Operating in Unlicensed Frequency Bands." IEEE Recommended Practice for Information technology - Telecommunications and information exchange between systems - Local and metropolitan area networks - Specific requirements; IEEE Computer Society.

Related Topics