Main Content

End-to-End Bluetooth LE PHY Simulation with AWGN, RF Impairments and Corrections

This example shows an end-to-end simulation to measure the bit error rate (BER) and packet error rate (PER) for different Bluetooth® low energy (LE) physical layer (PHY) packet types by using Bluetooth® Toolbox. The PHY packet types are distorted by adding the radio frequency (RF) impairments, and additive white Gaussian noise (AWGN). The simulation results show the BER and PER values for each PHY mode.

RF Impairments

Bluetooth Special Interest Group (SIG) [1] introduced Bluetooth LE for low-power short-range communications. Bluetooth LE devices operate in the globally unlicensed industrial, scientific, and medical (ISM) band in the frequency range of 2.4 GHz to 2.485 GHz. Bluetooth LE specifies a channel spacing of 2 MHz, which results in 40 RF channels. The Bluetooth LE standard specifies the link layer which includes both PHY and MAC layers. Bluetooth LE applications include image and video file transfers between mobile phones, home automation, and the Internet of Things (IoT). Bluetooth LE supports these PHY transmission modes.

  • Uncoded PHY with a data rate of 1 Mbps (LE1M)

  • Uncoded PHY with a data rate of 2 Mbps (LE2M)

  • Coded PHY with a data rate of 500 Kbps (LE500K)

  • Coded PHY with a data rate of 125 Kbps (LE125K)

In this example, each Bluetooth LE packet is distorted with these RF impairments.

  • DC offset

  • Carrier frequency offset

  • Carrier phase offset

  • Timing drift

  • Phase noise

End-to-End Simulation Workflow

This figure shows the workflow of this end-to-end simulation. After you add the RF impairments, the Bluetooth LE waveforms are distorted with the AWGN. The noisy waveform is then received at the practical receiver.

Bluetooth LE Block Diagram with RF impairments.

This figure shows the operational workflow of the practical receiver.

Bluetooth LE Practical Receiver Block Diagram

The practical receiver receives the noisy waveforms as input and performs these operations.

  1. Automatic gain control (AGC)

  2. DC removal

  3. Carrier frequency offset correction

  4. Matched filtering

  5. Packet detection

  6. Timing error correction

  7. Demodulation and decoding

  8. De-whitening

Simulations

Configuration

Specify the noise power spectral density (Eb/No), samples per symbol, data length, and PHY transmission modes.

EbNo = 2:4:10;                                  % Eb/No in dB
sps = 4;                                        % Samples per symbol, must be greater than 1
dataLength = 42;         % Data length in bytes, includes a header, a payload and a cycle redundancy check (CRC)
simMode = ["LE1M","LE2M","LE500K","LE125K"];    % PHY transmission modes

These parameters control the number of packets tested at each Eb/No point.

  • maxNumErrors: This parameter specifies the maximum number of bit errors simulated at each Eb/No point. When the number of bit errors reaches this value, the simulation at this Eb/No is complete.

  • maxNumPackets: This parameter specifies the maximum number of packets simulated at each Eb/No point. When the number of packets reaches this value, the simulation at this Eb/No is complete.

Specify the maxNumErrors and maxNumPackets values. For the purpose of this example, specify small values for maxNumErrors and maxNumPackets. For statistically meaningful results, you can simulate the example with higher maxNumErrors and maxNumPackets values.

maxNumErrors = 100;
maxNumPackets = 10;

Get the number of PHY modes for simulation.

numMode = numel(simMode);

Calculate the number of Eb/No points of simulation.

snrLength = length(EbNo);

Preallocate the space to store the BER and PER results.

[ber,per] = deal(zeros(numMode,snrLength));

Specify the number of bits per byte.

bitsPerByte = 8;

Simulate for Each PHY mode

This example demonstrates how to speed up the simulation by using a parfor loop, instead of a for loop simulate each Eb/No point. The parfor loop reduces the total simulation time by executing the processing for each PHY mode simultaneously. To utilize the parfor loop, you need the Parallel Computing Toolbox™ license. By commenting out the for statement, you can enable the use of parallel computing and enhance simulation speed. If you do not install the Parallel Computing Toolbox , by default, the example uses the for loop causing the simulation to run on a single core.

% parfor countMode = 1:numMode
for countMode = 1:numMode

For each PHY mode, set the signal-to-noise ratio (SNR). For coded PHYs (LE500K and LE125K), the SNR calculation includes the 1/2 and 1/8 code rate respectively.

    phyMode = simMode(countMode);

    if any(phyMode==["LE1M","LE2M"])
        snrVec = EbNo - 10*log10(sps);
    else
        if phyMode == "LE500K"
            codeRate = 1/2;
        else
            codeRate = 1/8;
        end
        snrVec = EbNo + 10*log10(codeRate) - 10*log10(sps);
    end

Calculate the sampling frequency of the generated waveform.

    sampleRate = sps*(1+(phyMode=="LE2M"))*1e6;

Simulate for Each Eb/No Point

    for countSnr = 1:snrLength

To ensure that each iteration uses a repeatable set of random numbers, set a random substream index for each iteration.

        stream = RandStream("combRecursive",Seed=0);
        stream.Substream = countSnr;
        RandStream.setGlobalStream(stream);

Create an instance of error rate.

        errorRate = comm.ErrorRate(Samples="Custom", ...
            CustomSamples=1:(dataLength*bitsPerByte-1));

To configure the RF impairments, use the helperBLEImpairmentsInit helper object.

        initImp = helperBLEImpairmentsInit(phyMode,sps);

Configure the parameters of the practical receiver.

        rxCfg = struct(Mode=phyMode,SamplesPerSymbol=sps, ...
            DFPacketType="Disabled");
        rxCfg.CoarseFreqCompensator = comm.CoarseFrequencyCompensator(Modulation="OQPSK", ...
            SampleRate=sampleRate, ...
            SamplesPerSymbol=2*sps, ...
            FrequencyResolution=30);
        rxCfg.PreambleDetector = comm.PreambleDetector(Detections="First");

Initialize the parameters for error computation. The numErrors is used for accumulating errors while the perCount is used for the PER count. The numPacket is used for number of packets received successfully.

        [numErrors,perCount,numPacket] = deal(0,0,1);

Configure and generate the Bluetooth LE waveform by providing the data bits, the PHY transmission mode, the samples per symbol value, the channel index, and the access address.

        while numErrors <= maxNumErrors && numPacket <= maxNumPackets

            txBits = randi([0 1],dataLength*bitsPerByte,1,"int8");  % Data bits generation
            channelIndex = randi([0 39],1,1);                       % Random channel index value for each packet
            if channelIndex <= 36
                % Random access address for data channels. This access
                % address value meets the requirements specified in Section
                % 2.1.2, Part-B, Vol-6 of Bluetooth specification.
                accessAddress = [1 0 0 0 1 1 1 0 1 1 0 0 1  ...
                    0 0 1 1 0 1 1 1 1 1 0 1 1 0 1 0 1 1 0]';
            else
                % Default access address for periodic advertising channels
                accessAddress = [0 1 1 0 1 0 1 1 0 1 1 1 1 1 0 1 1 0 0  ...
                    1 0 0 0 1 0 1 1 1 0 0 0 1]';
            end
            txWaveform = bleWaveformGenerator(txBits,Mode=phyMode, ...
                SamplesPerSymbol=sps, ...
                ChannelIndex=channelIndex, ...
                AccessAddress=accessAddress);

Configure and add the RF impairment parameters to the generated Bluetooth LE waveform.

            initImp.pfo.FrequencyOffset = randsrc(1,1,-50e3:10:50e3);                       % Frequency offset in Hz, range is [-150000,+150000]
            initImp.pfo.PhaseOffset = randsrc(1,1,-10:5:10);                                % Phase offset in degrees
            initoff = 0.15*sps;                                                             % Static timing offset
            stepsize = 20*1e-6;                                                             % Timing drift in ppm, max range is +/- 50 ppm
            initImp.vdelay = (initoff:stepsize:initoff+stepsize*(length(txWaveform)-1))';   % Variable timing offset
            initImp.dc = 20;                                                                % Percentage related to maximum amplitude value

            txImpairedWfm = helperBLEImpairmentsAddition(txWaveform,initImp);

Add AWGN to the fadded waveform.

            rxWaveform = awgn(txImpairedWfm,snrVec(countSnr));

Recover data bits from the noisy waveform by using the practical receiver.

            rxCfg.ChannelIndex = channelIndex;
            rxCfg.AccessAddress = accessAddress;
            [rxBits,recAccessAddress] = helperBLEPracticalReceiver(rxWaveform,rxCfg);

Determine the BER and PER by comparing transmitted and received bits.

            if(length(txBits) == length(rxBits))
                errors = errorRate(txBits,rxBits);      % Accumulate the error
                ber(countMode,countSnr) = errors(1);    % Accumulated BER
                currentErrors = errors(2)-numErrors;    % Number of errors in current packet
                if(currentErrors)                       % Check if the current packet has error or not
                    perCount = perCount + 1;            % Increment the PER count
                end
                numErrors = errors(2);                  % Accumulated errors
            else
                perCount = perCount + 1;                % Increment the PER count
            end
            numPacket = numPacket + 1;                  % Increment the packet number
        end
        per(countMode,countSnr) = perCount/(numPacket-1);

Display message for the particular value of SNR

        disp("Mode "+phyMode+","+ ...
            "Simulating for Eb/No = "+num2str(EbNo(countSnr))+"dB,"+ ...
            " BER: "+num2str(ber(countMode,countSnr))+","+ ...
            " PER: "+num2str(per(countMode,countSnr)));
    end
end
Mode LE1M,Simulating for Eb/No = 2dB, BER: 0.10448, PER: 1
Mode LE1M,Simulating for Eb/No = 6dB, BER: 0.0023881, PER: 0.3
Mode LE1M,Simulating for Eb/No = 10dB, BER: 0, PER: 0
Mode LE2M,Simulating for Eb/No = 2dB, BER: 0.083582, PER: 1
Mode LE2M,Simulating for Eb/No = 6dB, BER: 0.011045, PER: 0.9
Mode LE2M,Simulating for Eb/No = 10dB, BER: 0, PER: 0
Mode LE500K,Simulating for Eb/No = 2dB, BER: 0.16716, PER: 1
Mode LE500K,Simulating for Eb/No = 6dB, BER: 0.0047761, PER: 0.4
Mode LE500K,Simulating for Eb/No = 10dB, BER: 0, PER: 0
Mode LE125K,Simulating for Eb/No = 2dB, BER: 0.4209, PER: 1
Mode LE125K,Simulating for Eb/No = 6dB, BER: 0.0039801, PER: 0.5
Mode LE125K,Simulating for Eb/No = 10dB, BER: 0, PER: 0

Results and Visualizations

Specify the marker, color, and space for the legend variable.

marker = "ox*s";
color = "bmgr";
legendVar = strings(numMode,1);

Plot the BER and the PER curves for each PHY modes.

for countMode = 1:numMode
    subplot(2,1,1),semilogy(EbNo,ber(countMode,:).',"-"+marker{1}(countMode)+color{1}(countMode));
    hold on;
    legendVar(countMode) = simMode(countMode);

    subplot(2,1,2),semilogy(EbNo,per(countMode,:).',"-"+marker{1}(countMode)+color{1}(countMode));
    hold on;
    legendVar(countMode) = simMode(countMode);
end

subplot(2,1,1),
grid on;
xlabel("Eb/No (dB)");
ylabel("BER");
legend(legendVar);
title("BER of Bluetooth LE under RF impairments");

subplot(2,1,2),
grid on;
xlabel("Eb/No (dB)");
ylabel("PER");
legend(legendVar);
title("PER of Bluetooth LE under RF impairments");

Figure contains 2 axes objects. Axes object 1 with title BER of Bluetooth LE under RF impairments, xlabel Eb/No (dB), ylabel BER contains 4 objects of type line. These objects represent LE1M, LE2M, LE500K, LE125K. Axes object 2 with title PER of Bluetooth LE under RF impairments, xlabel Eb/No (dB), ylabel PER contains 4 objects of type line. These objects represent LE1M, LE2M, LE500K, LE125K.

Reference Results

This section generates the reference BER, PER and Eb/No values for each PHY mode based on the receiver sensitivity and corresponding BER as specified in [2].

[refBER,refPER,refEbNo] = deal(zeros(numMode,1));
headerLen = 2;                              % Header length in bytes
crcLen = 3;                                 % CRC length in bytes
payloadLen = dataLength-headerLen-crcLen;   % Payload length in bytes
for countMode = 1:numMode
    [refBER(countMode),refPER(countMode),refEbNo(countMode)] = ...
        helperBLEReferenceResults(simMode(countMode),payloadLen);
    disp("Mode "+simMode(countMode) + ", "+...
        "Reference Eb/No = "+ num2str(refEbNo(countMode))+ " dB, "+...
        "BER = "+num2str(refBER(countMode))+ ", "+...
        "PER = "+num2str(refPER(countMode))+ ", "+...
        "for payload length of "+num2str(payloadLen)+ " bytes.")
end
Mode LE1M, Reference Eb/No = 34.919 dB, BER = 0.001, PER = 0.30801, for payload length of 37 bytes.
Mode LE2M, Reference Eb/No = 34.919 dB, BER = 0.001, PER = 0.30801, for payload length of 37 bytes.
Mode LE500K, Reference Eb/No = 31.9087 dB, BER = 0.001, PER = 0.30801, for payload length of 37 bytes.
Mode LE125K, Reference Eb/No = 25.8881 dB, BER = 0.001, PER = 0.30801, for payload length of 37 bytes.

Further Exploration

You can further explore this example by increasing the maxNumErrors and maxNumPackets parameters for all the four transmission modes. These BER and PER results are obtained by using this configuration.

  • dataLength — 128 bytes

  • maxNumErrors — 1000

  • maxNumPackets — 10000

BER and PER plots for Bluetooth LE under RF Impairments.

The reference Eb/No values generated based on the Bluetooth LE specification include margin for RF impairments and fading channel conditions are not simulated in the example. As a result, these simulation results outperform the standard reference results. If you modify this example to include additional impairments such as frequency drift and interference, the BER and PER values increase with respect to the reference Eb/No values specified in [2].

Appendix

The example uses these helpers:

Selected Bibliography

[1] Bluetooth Technology Website. “Bluetooth Technology Website | The Official Website of Bluetooth Technology.” Accessed May 24, 2024. https://www.bluetooth.com/.

[2] Bluetooth Special Interest Group (SIG). "Bluetooth Core Specification". Version 5.3. Accessed May 24, 2024. https://www.bluetooth.com/specifications/specs/core-specification-5-3/.

See Also

Functions

Objects

Related Topics