Main Content

PHY Simulation of Bluetooth BR/EDR, LE, and WLAN Coexistence

This example shows you how to model homogenous and heterogeneous coexistence between Bluetooth® basic rate/enhanced data rate (BR/EDR), low energy (LE) , and wireless local area waveforms (WLAN) by using Bluetooth® Toolbox.

Using this example, you can:

  • Perform Bluetooth BR/EDR and LE end-to-end simulation in the presence of Bluetooth BR/EDR, LE, or WLAN interference.

  • Perform adaptive frequency hopping (AFH) by classifying the channels as "good" or "bad" based on the packet error rate (PER).

  • Compute the bit error rate (BER) and signal-to-interference-plus noise ratio (SINR).

  • Visualize the spectrum and spectrogram of the Bluetooth BR/EDR or LE waveform in the presence of interference.

Bluetooth and WLAN Coexistence

Bluetooth operates in the unlicensed 2.4 GHz industrial, scientific, and medical (ISM) band from 2.4 to 2.4835 GHz, which is also used by other technologies such as Zigbee and WLAN. Multiple homogenous and heterogeneous networks operating in this band are likely to coexist in a physical scenario. To mitigate interference, Bluetooth and WLAN implement AFH and carrier-sense multiple access with collision avoidance (CSMA/CA), respectively. AFH enables Bluetooth devices to improve their robustness to interference and avoid interfering with other devices in the 2.4 GHz ISM band. The basic principle is to classify interference channels as bad channels and discard them from the list of available channels. This classification mechanism of AFH enables a Bluetooth device to use 79 channels or fewer in BR/EDR mode and 40 channels or fewer in LE mode. The Bluetooth Core Specification [2] allows a minimum of 20 channels in BR/EDR mode and 2 channels in LE mode. For more information about coexistence between Bluetooth and WLAN, see Bluetooth-WLAN Coexistence (Bluetooth Toolbox).

Coexistence mechanisms can be classified into two categories: collaborative or noncollaborative, depending on whether the involved networks operate independently of one another or coordinate their use of the spectrum. In noncollaborative coexistence, each network treats other networks as interference and performs interference mitigation techniques. In collaborative coexistence, all the networks collaborate and coordinate their use of the spectrum. This example illustrates a noncollaborative coexistence mechanism between homogenous and heterogeneous networks.

This example uses these terminologies:

  • AWN - Affected wireless node, can be one of these:

- Bluetooth: BR, EDR 2Mbps, EDR 3Mbps, LE 1Mbps, LE 2Mbps, LE 500Kbps, and LE 125Kbps

  • IWN - Interfering wireless node, can be one of these:

- Bluetooth:

BR, EDR 2Mbps, EDR 3Mbps, LE 1Mbps, LE 2Mbps, LE 500Kbps, and LE 125Kbps

- WLAN:

802.11b with 22 MHz bandwidth

802.11g with 20 MHz bandwidth

802.11n with 20 MHz and 40 MHz bandwidths

802.11ax with 20 MHz and 40 MHz bandwidths

Impact of Interference in Space, Time, and Frequency Domains

Space: As the distance between AWN and IWN nodes increases, the impact of interference in space domain decreases. In this figure, if d1 and d2 increase, the impact of the IWN transmitter interference on the AWN receiver decreases.

Time: Depending on the packet transmission timings, three possible collision probabilities arise in the time domain: full collision, partial collision, or no collision.

  • Full - IWN packet completely interferes with the AWN packet.

  • Partial - IWN packet partially interferes with the AWN packet with the given probability.

  • No - IWN packet does not interfere with the AWN packet.

Frequency: As the channel separation between the AWN and IWN nodes increases, the impact of interference in frequency domain decreases. In this figure, if difference between fIWN and fAWN increase, the impact of the IWN transmitter interference on the AWN receiver decreases.

Simulation Parameters

Specify the AWN parameters such as the signal type, transmitter position, receiver position, transmitter power, and packet type.

Specify frequency hopping as one of these values.

  • Off (default) - To run simulation at a fixed frequency, use this value. If you use this value, the example configures awnFrequency.

  • On - To run simulation with AFH, use this value. If you use this value, the example does not configure awnFrequency.

awnSignalType = "LE1M";
awnTxPosition =  [0,0,0];    % In meters
awnRxPosition =  [10,0,0];    % In meters
awnTxPower = 30;       % In dBm
awnPacket = "Disabled";
awnFrequencyHopping = "Off";
awnFrequency = 2440*1e6; % In Hz

Configure a single or multiple IWNs and their respective parameters such as the signal type, transmitter position, fixed frequency of operation, and transmitter power. Create and configure multiple IWN nodes by using the IWN structure with different indices.

Specify the collision probability in the range [0,1]. Any value between 0 and 1 simulates partial collision. To simulate full collision, set this value to 1. To disable interference and simulate with no collisions, set this value to 0.

Add different types of WLAN signals as interference using WLAN Toolbox™. If you do not have WLAN Toolbox™, use WLANBasebandFile to add 802.11ax signal.

iwn(1).SignalType = "WLANHESUBandwidth20.bb";
iwn(1).TxPosition = [20,0,0];      % In meters
iwn(1).Frequency = 2437e6;         % In Hz
iwn(1).TxPower = 30;               % In dBm
iwn(1).CollisionProbability = 1;   % Probability of collision in time, must be between [0,1]

iwn(2).SignalType = "LE1M";
iwn(2).TxPosition = [25,0,0];      % In meters
iwn(2).Frequency = 2420e6;         % In Hz
iwn(2).TxPower = 30;               % In dBm
iwn(2).CollisionProbability = 0.2; % Probability of collision in time, must be between [0,1]

Specify the environment, bit energy to noise density ratio (Eb/No), sample rate, and number of packets.

environment = "Outdoor";
EbNo = 10;         % In dB
sampleRate = 80e6; % In Hz
numPackets = 500;

Set the seed for the random number generator.

rng default;

Configure the waveform transmission and reception parameters of the AWN.

phyFactor = 1+strcmp(awnSignalType,"LE2M");
sps = sampleRate/(1e6*phyFactor);                       % Samples per symbol
if sps > 8                                              % Decimation factor for the receiver filter
    decimationFactor = gcd(sps,8);
else
    decimationFactor = 1;
end

if any(strcmp(awnSignalType,["LE1M","LE2M","LE500K","LE125K"]))
    payloadLength = 100;                                % Length of the payload in bytes
    accessAddress = "01234567";                         % Access address
    accessAddBits = int2bit(hex2dec(accessAddress),32,false);

    % Derive channel index based on the AWN frequency
    channelIndexArray = [37 0:10 38 11:36 39];
    awnBandwidth = 2e6;
    channelIndex = channelIndexArray((awnFrequency-2402e6)/awnBandwidth+1);
    
    % Configure the receiver parameters in a structure
    rxCfg = struct(Mode=awnSignalType,SamplesPerSymbol=sps/decimationFactor,ChannelIndex=channelIndex, ...
        DFPacketType=awnPacket,AccessAddress=accessAddBits);
    rxCfg.CoarseFreqCompensator = comm.CoarseFrequencyCompensator(Modulation="OQPSK", ...
                                             SampleRate=sampleRate/decimationFactor, ...
                                             SamplesPerSymbol=2*rxCfg.SamplesPerSymbol, ...
                                             FrequencyResolution=100);
    rxCfg.PreambleDetector = comm.PreambleDetector(Detections="First");
else
    % Create and configure Bluetooth waveform generation parameters
    awnWaveformConfig = bluetoothWaveformConfig(Mode=awnSignalType,PacketType=awnPacket, ...
                            SamplesPerSymbol=sps);
    if strcmp(awnPacket,"DM1")
        awnWaveformConfig.PayloadLength = 17;            % Maximum length of DM1 packets in bytes
    end
    payloadLength = getPayloadLength(awnWaveformConfig); % Length of the payload

    % Get the receiver configuration parameters
    rxCfg = getPhyConfigProperties(awnWaveformConfig);
    rxCfg.SamplesPerSymbol = sps/decimationFactor;
end

Estimate the AWN path loss.

% Estimate distance between AWN transmitter and AWN receiver
distanceAWNTxRx = sqrt(sum((awnTxPosition-awnRxPosition).^2));
[awnPathloss,pathlossdB] = helperBluetoothEstimatePathLoss(environment,distanceAWNTxRx);

Create and configure the IWN by using the helperIWNConfig object. Generate IWN waveforms by using the generateIWNWaveform method. Add the path loss based on the environment and node positions by using the applyPathloss method.

iwnConfig = helperIWNConfig(IWN=iwn,SampleRate=sampleRate,Environment=environment);
iwnWaveform = generateIWNWaveform(iwnConfig);
[iwnWaveformPL,iwnPathloss] = applyPathloss(iwnConfig,iwnWaveform,awnRxPosition);

Use the bluetoothFrequencyHop and bleChannelSelection objects to select a channel index for the transmission and reception of Bluetooth BR/EDR and LE waveforms, respectively.

if strcmp(awnFrequencyHopping,"On")
    if any(strcmp(awnSignalType,["LE1M","LE2M","LE500K","LE125K"]))
        frequencyHop = bleChannelSelection;   % Bluetooth LE channel index System object™
        numBTChannels = 37;                   % Number of Bluetooth LE channels
        minChannels = 2;                      % Minimum number of channels to classify
    else
        frequencyHop = bluetoothFrequencyHop; % Bluetooth BR/EDR channel index object
        frequencyHop.SequenceType = "Connection Adaptive";
        numBTChannels = 79;                   % Number of Bluetooth BR/EDR channels
        minChannels = 20;                     % Minimum number of channels to classify
        inputClock = 0;
        numSlots = 1*(any(strcmp(awnPacket,["ID","NULL","POLL","FHS","HV1","HV2", ...
                    "HV3","DV","EV3","DM1","DH1","AUX1","2-DH1","3-DH1","2-EV3","3-EV3"])))...
                    +(3*any(strcmp(awnPacket,["EV4","EV5","DM3","DH3","2-EV5","3-EV5","2-DH3", ...
                    "3-DH3"])))+ (5*any(strcmp(awnPacket,["DM5","DH5","2-DH5","3-DH5"])));
        slotValue = numSlots*2;
        clockTicks = slotValue*2;             % Clock ticks (one slot is two clock ticks)
    end
end

Design a receiver filter to capture the AWN waveform.

if any(strcmp(awnSignalType,["EDR2M","EDR3M"]))
    rolloff = 0.4;
    span = 8;
    filterCoeff = rcosdesign(rolloff,span,sps,"sqrt");
else
    N = 200;                                   % Order
    Fc = 1.5e6/(1+strcmp(awnSignalType,"BR")); % Cutoff frequency
    flag = "scale";                            % Sampling flag
    alpha = 3;                                 % Window parameter
    
    % Create the window vector for the design algorithm
    win = gausswin(N+1,alpha);
    
    % Calculate the coefficients using the FIR1 function
    filterCoeff = fir1(N,Fc/(sampleRate/2),"low",win,flag);
end
firdec = dsp.FIRDecimator(decimationFactor,filterCoeff);

Compute the signal-to-noise ratio (SNR).

codeRate = 1*any(strcmp(awnSignalType,["LE1M","LE2M"]))+1/2*strcmp(awnSignalType,"LE500K")+1/8*strcmp(awnSignalType,"LE125K")+...
           any(strcmp(awnSignalType,["BR","EDR2M","EDR3M"]))*(1-2/3*strcmp(awnPacket,"HV1")-...
           1/3*any(strcmp(awnPacket,["FHS","DM1","DM3","DM5","HV2","DV","EV4"]))); % Code rate
bitsPerSymbol = 1+ strcmp(awnSignalType,"EDR2M") + 2*(strcmp(awnSignalType,"EDR3M")); % Number of bits per symbol
snr = EbNo + 10*log10(codeRate) + 10*log10(bitsPerSymbol) - 10*log10(sps);

Create and configure the spectrum analyzer to visualize the spectrum and spectrogram of the Bluetooth BR/EDR or LE waveform in the presence of interference.

spectrumAnalyzer = dsp.SpectrumAnalyzer(...
    Name="Bluetooth Coexistence Modeling", ...
    ViewType="Spectrum and spectrogram", ...
    TimeResolutionSource="Property", ...
    TimeResolution=0.0005, ...
    SampleRate=sampleRate, ...
    TimeSpanSource="Property", ...
    TimeSpan=0.05, ...
    FrequencyResolutionMethod="WindowLength", ...
    WindowLength=512, ...
    AxesLayout="Horizontal", ...
    YLimits=[-100 20], ...
    ColorLimits=[-100 20]);

Coexistence Simulation

This diagram summarizes the example workflow.

Perform these steps to simulate the coexistence scenario.

  1. Generate AWN (Bluetooth BR/EDR or LE) waveforms.

  2. Distort each AWN waveform with these RF impairments: timing offset, carrier frequency offset, and DC offset.

  3. Hop the waveform (frequency shift based on a center frequency of 2440 MHz) using the channel index derived from AFH.

  4. Scale the hopped waveform with the transmitter power and path loss.

  5. Generate and add IWN waveforms (Bluetooth BR/EDR, LE, or WLAN) based on the collision probabilities.

  6. Add additive white Gaussian noise (AWGN).

  7. Filter the noisy waveform.

  8. Recover the bits from the filtered waveform by performing timing synchronization, carrier frequency offset correction, and DC offset correction.

  9. Compute the PER, BER, and SINR.

  10. If frequency hopping is on, classify the channels.

% Classify the channels for every |numPacketsToClassify| packets. If the PER of the
% channel is greater than |thresholdPER|, then map the corresponding channel
% as bad.
numPacketsToClassify = 50;
thresholdPER = 0.2; 

% Create an instance of the error rate
errorRate = comm.ErrorRate;

% Initialize variables to perform the simulation
numErrors = 0;
numPktLost = 0;
countPER = 0;
countPreviousPER = 0;
midFrequency = 2440e6;
if strcmp(awnFrequencyHopping,"On")
    errorsBasic = deal(zeros(numBTChannels,3));
    errorsBasic(:,1) = (0:numBTChannels-1);
end

% Number of interfering nodes that collide with AWN
collisionCount = 0;
for index = 1:iwnConfig.NumIWNNodes
    collisionCount = collisionCount + (iwn(index).CollisionProbability > 0);
end

if strcmp(awnFrequencyHopping,"On") && collisionCount ~= 0
    sinr = zeros(numPackets,1);
end

% Loop to simulate multiple packets
for inum = 1:numPackets

    % Generate AWN waveform
    if any(strcmp(awnSignalType,["LE1M","LE2M","LE500K","LE125K"]))
        if strcmp(awnFrequencyHopping,"On")
            channelIndex = frequencyHop();
            channelFrequencies = [2404:2:2424 2428:2:2478 2402 2426 2480]*1e6;
            awnFrequency = channelFrequencies(channelIndex+1);
        end
        txBits = randi([0 1],payloadLength*8,1,"int8");
        awnWaveform = bleWaveformGenerator(int8(txBits),Mode=awnSignalType,ChannelIndex=channelIndex, ...
            SamplesPerSymbol=sps,AccessAddress=accessAddBits,DFPacketType=awnPacket);
    else
        if strcmp(awnFrequencyHopping,"On")
            inputClock = inputClock + clockTicks;

            % Frequency hopping
            channelIndex = nextHop(frequencyHop,inputClock)
            awnFrequency = (2402+channelIndex)*1e6;

            % Generate whiten initialization vector from clock
            clockBinary = int2bit(inputClock,28,false).';
            awnWaveformConfig.WhitenInitialization = [clockBinary(2:7)'; 1];
        end
        txBits = randi([0 1],payloadLength*8,1);
        awnWaveform = bluetoothWaveformGenerator(txBits,awnWaveformConfig);
    end
    
    % Add timing offset
    timingOffset = randsrc(1,1,1:0.1:100);
    timingOffsetWaveform = helperBLEDelaySignal(awnWaveform,timingOffset);

    % Add frequency offset
    freqOffsetImp = randsrc(1,1,-10e3:100:10e3);
    freqOffsetWaveform = helperBLEFrequencyOffset(timingOffsetWaveform,sampleRate,freqOffsetImp);
    
    % Add DC offset
    dcValue = (5/100)*max(freqOffsetWaveform);
    dcWaveform = freqOffsetWaveform + dcValue;

    % Shift the waveform by making 2440 MHz as the mid frequency
    freqOffset = awnFrequency-midFrequency;
    hopWaveform = helperBLEFrequencyOffset(dcWaveform,sampleRate,freqOffset);

    % Scale the waveform as per the transmitter power and path loss
    soiAmplitudeLinear = 10^((awnTxPower-30)/20)/awnPathloss;
    attenAWNWaveform = soiAmplitudeLinear*hopWaveform;
    
    % Add IWN waveforms to AWN waveform
    addIWN2AWN = addInterference(iwnConfig,attenAWNWaveform,iwnWaveformPL,timingOffset);

    % Frequency shift the waveform by |-freqOffset|
    freqShiftWaveform = helperBLEFrequencyOffset(addIWN2AWN,sampleRate,-freqOffset);

    % Add AWGN
    soiPower = 20*log10(soiAmplitudeLinear);
    noisePower = soiPower - snr;
    splusibyn = 10*log10(var(freqShiftWaveform))-noisePower;
    noisyWaveform = awgn(freqShiftWaveform,splusibyn,"measured");

    % Apply filter
    if rem(length(noisyWaveform),sps)
        remainder = sps-rem(length(noisyWaveform),sps);
        noisyWaveform = [noisyWaveform;zeros(remainder,1)]; %#ok<AGROW> 
    end
    delay = floor(length(firdec.Numerator)/(2*decimationFactor));
    noisyWaveformPadded = [noisyWaveform;zeros(delay*decimationFactor,1)];
    filteredWaveform = firdec(noisyWaveformPadded);
    release(firdec)
    filteredWaveform = filteredWaveform(1+delay:end)*sqrt(decimationFactor);

    % Recover the data bits
    if any(strcmp(awnSignalType,["LE1M","LE2M","LE500K","LE125K"]))
        rxCfg.ChannelIndex = channelIndex;
        [rxBits,accAddress] = helperBLEPracticalReceiver(filteredWaveform,rxCfg);
        if isempty(rxBits) || ~isequal(accessAddBits,accAddress)
            pktStatus = [];
        end
    else
        % Get PHY properties
        rxCfg.WhitenInitialization = awnWaveformConfig.WhitenInitialization;
        [rxBits,~,pktStatus]...
                            = helperBluetoothPracticalReceiver(filteredWaveform,rxCfg);
    end   

Simulation Results

Compute the BER and PER for each packet. If frequency hopping is on,

  • Perform channel classification for every numPacketsToClassify based on the PER.

  • Compute the SINR for each packet.

  • Visualize the Bluetooth BR/EDR or LE waveform with the interference.

    % Compute BER and PER
    lengthTx = length(txBits);
    lengthRx = length(rxBits);
    lengthMinimum = min(lengthTx,lengthRx)-1;
    countPreviousPER = countPER;
    if lengthTx && lengthRx
        vectorBER = errorRate(txBits(1:lengthMinimum),rxBits(1:lengthMinimum));
        currentErrors = vectorBER(2)-numErrors;    % Number of errors in current packet
        if currentErrors || (lengthTx ~= lengthRx) % Check if current packet is in error or not
            countPER  = countPER+1;                % Increment the PER count
        end
        numErrors = vectorBER(2);
    elseif ~isempty(pktStatus)
        countPER  = countPER+~pktStatus;           % Increment the PER count
    else
        numPktLost = numPktLost+1;
    end

    % Perform frequency hopping
    if strcmp(awnFrequencyHopping,"On")
        chIdx = channelIndex+1;
        if countPreviousPER ~= countPER
            errorsBasic(chIdx,3) = errorsBasic(chIdx,3)+1;
        end

        % Classify the channels
        if any(inum == (1:floor(numPackets/numPacketsToClassify))*numPacketsToClassify)
            channelMap = errorsBasic(:,3)/numPacketsToClassify > thresholdPER;
            if nnz(channelMap) == 0
                continue;
            end
            badChannels = find(channelMap)-1;
            if length(frequencyHop.UsedChannels)-length(badChannels) < minChannels
                errorsBasic(badChannels+1,3) = 0;
                usedChannels = 0:36;
            else
                errorsBasic(badChannels+1,3) = 0;
                usedChannels = setdiff(frequencyHop.UsedChannels,badChannels);
            end
            frequencyHop.UsedChannels = usedChannels;
        end
    end
    
    % Visualize the spectrum and spectrogram. Compute SINR.
    if strcmp(awnFrequencyHopping,"On") && collisionCount ~= 0
        sinr(inum) = helperBluetoothSINREstimate(snr,awnTxPower,awnFrequency,pathlossdB,iwnConfig,iwnPathloss);
        spectrumAnalyzer(addIWN2AWN)
    elseif (strcmp(awnFrequencyHopping,"Off") && inum < 70) || (strcmp(awnFrequencyHopping,"On") && collisionCount == 0)
        if inum == 1
            sinr = helperBluetoothSINREstimate(snr,awnTxPower,awnFrequency,pathlossdB,iwnConfig,iwnPathloss);
        end
        spectrumAnalyzer(addIWN2AWN)
    end
end

% Compute BER and PER
if ~any(strcmp(awnPacket,["ID","NULL","POLL"]))
    if numPackets ~= numPktLost
        per = countPER/(numPackets-numPktLost);
        ber = vectorBER(1);
        fprintf('Mode %s, Simulated for Eb/No = %d dB, Obtained BER: %d, Obtained PER: %d\n',awnSignalType,EbNo,ber,per);
    else
        fprintf('No Bluetooth packets were detected.\n');
    end
else
    if numPackets ~= numPktLost
        per = countPER/(numPackets-numPktLost);
        fprintf('Mode %s, Simulated for Eb/No = %d dB, Obtained PER: %d\n',awnSignalType,EbNo,per);
    else
        fprintf('No Bluetooth packets were detected.\n');
    end
end
Mode LE1M, Simulated for Eb/No = 10 dB, Obtained BER: 4.205257e-04, Obtained PER: 8.980000e-01

This example simulates an end-to-end link for Bluetooth BR/EDR and LE with Bluetooth BR/EDR, LE, or WLAN waveforms as interference. You can implement AFH to mitigate interference by classifying channels as good or bad based on the PER value.

Further Exploration

To observe the PER performance with interferer distance, you can run the simulation for different IWN transmitter positions. This plot shows the impact of interferer distance on PER given:

  • Bluetooth LE1M AWN, 10 meters distance between the AWN transmitter and receiver, an AWN frequency of 2440 MHz, and an Eb/No value of 10 dB.

  • 802.11 g with 20 MHz bandwidth IWN, an IWN frequency of 2437 MHz (co-channel interference), and a collision probability of 1.

To observe the PER performance with interferer channel separation, you can run the simulation for different IWN frequencies (when frequency hopping is off). This plot shows the impact of interferer channel separation on PER given:

  • Bluetooth LE1M AWN, 10 m distance between the AWN transmitter and receiver, and an Eb/No value of 10 dB.

  • 802.11g with 20 MHz bandwidth IWN, an IWN frequency of 2437 MHz, a collision probability of 1, and 10 m distance between the AWN and IWN transmitters.

To observe the PER performance with collision probability, you can run the simulation for different collision probabilities. This plot shows the impact of collision probability on PER by considering:

  • Bluetooth LE1M AWN, an AWN frequency of 2440 MHz, 10 m between the AWN transmitter and receiver, and an Eb/No value of 10 dB.

  • 802.11g with 20 MHz bandwidth IWN, an IWN frequency of 2437 MHz, and 10 m between the AWN and IWN transmitters.

Appendix

The example uses these helper functions:

Selected Bibliography

  1. Bluetooth Technology Website. “Bluetooth Technology Website | The Official Website of Bluetooth Technology.” Accessed November 15, 2021. https://www.bluetooth.com.

  2. Bluetooth Special Interest Group (SIG). "Core System Package [Low Energy Controller Volume]". Bluetooth Core Specification. Version 5.3, Volume https://www.bluetooth.com.

Related Topics