Main Content

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

This example shows how to measure the bit error rate (BER) and packet error rate (PER) for different modes of Bluetooth® low energy (LE) physical layer (PHY) packet transmissions that have radio front-end (RF) impairments and additive white Gaussian noise (AWGN) added to them by using the Bluetooth® Toolbox.

Introduction

Bluetooth Special Interest Group (SIG) 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 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).

This end-to-end Bluetooth LE PHY simulation determines BER and PER performance of the four Bluetooth LE PHY transmission modes with RF impairments and AWGN added to the transmission packets. Nested for loops are used to compute error rates for each transmission mode at several bit energy to noise density ratio (Eb/No) settings. Inside the Eb/No loop, multiple transmission packets are generated using the bleWaveformGenerator function and altered with RF impairments and AWGN to accumulate the error rate statistics. Each packet is distorted by these RF impairments:

  • DC offset

  • Carrier frequency offset

  • Carrier phase offset

  • Timing drift

  • Phase noise

White gaussian noise is added to the transmitted Bluetooth LE waveforms. The noisy packets are processed through a practical Bluetooth LE receiver that performs the following operations:

  • Automatic gain control (AGC)

  • DC removal

  • Carrier frequency offset correction

  • Matched filtering

  • Packet detection

  • Timing error correction

  • Demodulation and decoding

  • Dewhitening

The processing steps for each packet are summarized in the following diagram:

The synchronized packets are then demodulated and decoded to recover the data bits. These recovered data bits are compared with the transmitted data bits to determine the BER and PER. BER and PER curves are generated for the following four PHY transmission throughput modes supported in Bluetooth LE:

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

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

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

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

Initialize the Simulation Parameters

EbNo = 2:4:10;                               % Eb/No in dB
sps = 4;                                     % Samples per symbol, must be greater than 1
dataLen = 42;                                % Data length in bytes, includes header, payload and CRC
simMode = {'LE1M','LE2M','LE500K','LE125K'}; % PHY modes considered for the simulation

The number of packets tested at each Eb/No point is controlled by two parameters:

  1. maxNumErrors is the maximum number of bit errors simulated at each Eb/No point. When the number of bit errors reaches this limit, the simulation at this Eb/No point is complete.

  2. maxNumPackets is the maximum number of packets simulated at each Eb/No point and limits the length of the simulation if the bit error limit is not reached.

The numbers chosen for maxNumErrors and maxNumPackets in this example will lead to a very short simulation. For meaningful results we recommend increasing these numbers.

maxNumErrors = 100; % Maximum number of bit errors at an Eb/No point
maxNumPackets = 10; % Maximum number of packets at an Eb/No point

Simulating for Each Eb/No Point

This example also demonstrates how a parfor loop can be used instead of the for loop when simulating each Eb/No point to speed up a simulation. parfor, as part of the Parallel Computing Toolbox, executes processing for each Eb/No point in parallel to reduce the total simulation time. To enable the use of parallel computing for increased speed, comment out the 'for' statement and uncomment the 'parfor' statement below. If Parallel Computing Toolbox (TM) is not installed, 'parfor' will default to the normal 'for' statement.

numMode = numel(simMode);          % Number of modes
ber = zeros(numMode,length(EbNo)); % Pre-allocate to store BER results
per = zeros(numMode,length(EbNo)); % Pre-allocate to store PER results
bitsPerByte = 8;                   % Number of bits per byte

% Fixed access address Ideally, this access address value should meet the
% requirements specified in Section 2.1.2 of the Bluetooth specification.
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]';
for iMode = 1:numMode

    phyMode = simMode{iMode};

    % Set signal to noise ratio (SNR) points based on mode.
    % For Coded PHYs (LE500K and LE125K), the code rate factor is included
    % in SNR calculation as 1/2 and 1/8 respectively.
    if any(strcmp(phyMode,{'LE1M','LE2M'}))
        snrVec = EbNo - 10*log10(sps);
    else
        if strcmp(phyMode,'LE500K')
             codeRate = 1/2;
        else
             codeRate = 1/8;
        end
        snrVec = EbNo + 10*log10(codeRate) - 10*log10(sps);
    end

    % parfor iSnr = 1:length(snrVec)  % Use 'parfor' to speed up the simulation
    for iSnr = 1:length(snrVec)   % Use 'for' to debug the simulation

        % Set random substream index per iteration to ensure that each
        % iteration uses a repeatable set of random numbers
        stream = RandStream('combRecursive','Seed',0);
        stream.Substream = iSnr;
        RandStream.setGlobalStream(stream);

        % Create an instance of error rate
        errorRate = comm.ErrorRate('Samples','Custom',...
                        'CustomSamples',1:(dataLen*bitsPerByte-1));

        % Create and configure the System objects for impairments
        initImp = helperBLEImpairmentsInit(phyMode,sps);

        % Configure the receiver parameters in a structure
        rxCfg = struct(Mode=phyMode,SamplesPerSymbol=sps,ChannelIndex=37,...
            DFPacketType='Disabled',AccessAddress=accessAddress);
        rxCfg.CoarseFreqCompensator = comm.CoarseFrequencyCompensator(Modulation="OQPSK",...
                                                 SampleRate=sps*(1+strcmp(phyMode,'LE2M'))*1e6,...
                                                 SamplesPerSymbol=2*sps,...
                                                 FrequencyResolution=30);
        rxCfg.PreambleDetector = comm.PreambleDetector(Detections="First");

        % Initialize error computation parameters
        [numErrs,perCnt] = deal(0);
        numPkt = 1;

        % Loop to simulate multiple packets
        while numErrs <= maxNumErrors && numPkt <= maxNumPackets

            % Generate Bluetooth LE waveform
            txBits = randi([0 1],dataLen*bitsPerByte,1,'int8'); % Data bits generation
            channelIndex = randi([0 39],1,1); % Random channel index value for each packet
            txWaveform = bleWaveformGenerator(txBits,'Mode',phyMode,...
                                            'SamplesPerSymbol',sps,...
                                            'ChannelIndex',channelIndex,...
                                            'accessAddress',accessAddress);

            % Define the RF impairment parameters
            initImp.pfo.FrequencyOffset = randsrc(1,1,-50e3:10:50e3); % In Hz, Max range is +/- 150 KHz
            initImp.pfo.PhaseOffset = randsrc(1,1,-10:5:10);          % 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 with respect to maximum amplitude value

            % Pass the generated waveform through RF impairments
            txImpairedWfm = helperBLEImpairmentsAddition(txWaveform,initImp);

            % Pass the transmitted waveform through AWGN channel
            rxWaveform = awgn(txImpairedWfm,snrVec(iSnr));

            % Recover data bits using practical receiver
            rxCfg.ChannelIndex = channelIndex;
            [rxBits,recAccessAddress] = helperBLEPracticalReceiver(rxWaveform,rxCfg);

            % Determine the BER and PER
            if(length(txBits) == length(rxBits))
                errors = errorRate(txBits,rxBits); % Outputs the accumulated errors
                ber(iMode,iSnr) = errors(1);       % Accumulated BER
                currentErrors = errors(2)-numErrs; % Number of errors in current packet
                if(currentErrors) % Check if current packet is in error or not
                    perCnt  = perCnt + 1;          % Increment the PER count
                end
                numErrs = errors(2);               % Accumulated errors
                numPkt = numPkt + 1;
            end
        end
        per(iMode,iSnr) = perCnt/(numPkt-1);

    disp(['Mode ' phyMode ', '...
        'Simulating for Eb/No = ', num2str(EbNo(iSnr)), ' dB' ', '...
        'BER:',num2str(ber(iMode,iSnr)), ', '...
        'PER:',num2str(per(iMode,iSnr))])
    end
end
Mode LE1M, Simulating for Eb/No = 2 dB, BER:0.15, PER:1
Mode LE1M, Simulating for Eb/No = 6 dB, BER:0.0077612, PER:0.7
Mode LE1M, Simulating for Eb/No = 10 dB, BER:0, PER:0
Mode LE2M, Simulating for Eb/No = 2 dB, BER:0.089552, PER:1
Mode LE2M, Simulating for Eb/No = 6 dB, BER:0.0080597, PER:0.7
Mode LE2M, Simulating for Eb/No = 10 dB, BER:0, PER:0
Mode LE500K, Simulating for Eb/No = 2 dB, BER:0.15522, PER:1
Mode LE500K, Simulating for Eb/No = 6 dB, BER:0.0047761, PER:0.5
Mode LE500K, Simulating for Eb/No = 10 dB, BER:0, PER:0
Mode LE125K, Simulating for Eb/No = 2 dB, BER:0.4597, PER:1
Mode LE125K, Simulating for Eb/No = 6 dB, BER:0.16567, PER:1
Mode LE125K, Simulating for Eb/No = 10 dB, BER:0, PER:0

Simulation Results

This section presents the BER and PER results related to the input Eb/No range for the considered PHY modes

markers = 'ox*s';
color = 'bmcr';
dataStr = {zeros(numMode,1)};
for iMode = 1:numMode
    subplot(2,1,1),semilogy(EbNo,ber(iMode,:).',['-' markers(iMode) color(iMode)]);
    hold on;
    dataStr(iMode) = simMode(iMode);

    subplot(2,1,2),semilogy(EbNo,per(iMode,:).',['-' markers(iMode) color(iMode)]);
    hold on;
    dataStr(iMode) = simMode(iMode);
end
subplot(2,1,1),
grid on;
xlabel('Eb/No (dB)');
ylabel('BER');
legend(dataStr);
title('BER of Bluetooth LE under RF impairments');

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

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 = dataLen-headerLen-crcLen; % Payload length in bytes
for iMode = 1:numMode
    [refBER(iMode),refPER(iMode),refEbNo(iMode)] = ...
                        helperBLEReferenceResults(simMode(iMode),payloadLen);
    disp(['Mode ' simMode{iMode} ', '...
        'Reference Eb/No = ', num2str(refEbNo(iMode)), ' dB' ', '...
        'BER = ',num2str(refBER(iMode)), ', '...
        'PER = ',num2str(refPER(iMode)), ', '...
        '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 = 31.9087 dB, BER = 0.001, PER = 0.30801, for payload length of 37 bytes

Further Exploration

The number of packets tested at each Eb/No value is controlled by maxNumErrors and maxNumPackets parameters. For statistically meaningful results these values should be larger than those presented in this example. To generate the figure below, the simulation ran using a data length of 128 bytes, maxNumErrors = 1e3, and maxNumPackets = 1e4 for all the four transmission modes.

The figure shows that the reference BER and PER can be obtained at lower Eb/No points compared to the reference Eb/No value given in the Bluetooth specification. In this example, only the following impairments are added and passed through AWGN channel.

  • DC offset

  • Carrier frequency offset

  • Carrier phase offset

  • Timing drift

The reference Eb/No values generated based on the Bluetooth LE specification include margin for RF impairments and fading channel conditions that are not modeled in this simulation. As a result, the simulation results here outperform the standard reference results. If you modify this example to include additional impairments such as frequency drift, fading, and interference in the simulation the BER and PER curves will move right towards the reference Eb/No values generated based on the Bluetooth LE standard receiver characteristics in [ 2 ].

Appendix

The example uses these helpers:

  • <matlab:openExample('bluetooth/BLEPracticalReceiverExample','supportingFile','helperBLEImpairmentsAddition.m') helperBLEImpairmentsAddition >: Add RF impairments to the Bluetooth LE waveform

  • <matlab:openExample('bluetooth/BLEPracticalReceiverExample','supportingFile','helperBLEPracticalReceiver.m') helperBLEPracticalReceiver >: Demodulate and decodes the received signal

  • <matlab:openExample('bluetooth/BLEPracticalReceiverExample','supportingFile','helperBLEImpairmentsInit.m') helperBLEImpairmentsInit >: Initialize RF impairment parameters

  • <matlab:openExample('bluetooth/BLEPracticalReceiverExample','supportingFile','helperBLEReferenceResults.m') helperBLEReferenceResults >: Generate reference BER, PER and Eb/No values

Summary

This example simulates a Bluetooth LE PHY packet transmissions that have RF impairments and AWGN added to them. It shows how to generate Bluetooth LE waveforms, demodulate and decode data bits using practical receiver and compute the BER and PER.

Selected Bibliography

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

  2. Volume 6 of the Bluetooth Core Specification, Version 5.3 Core System Package [Low Energy Controller Volume].

See Also

Functions

Objects

Related Topics