Main Content

Bluetooth LE Waveform Reception Using SDR

This example shows how to implement a Bluetooth® low energy (LE) receiver using the Bluetooth® Toolbox. You can either capture the Bluetooth LE waveform by using the ADALM-PLUTO radio or load in-phase and quadrature phase (IQ) samples corresponding to the Bluetooth LE waveform from a baseband file (*.bb). To generate and transmit the Bluetooth LE waveform, see Bluetooth LE Waveform Generation and Transmission Using SDR and configure your test environment with:

  • Two SDR platforms connected to the same host computer which runs two MATLAB sessions

  • Two SDR platforms connected to two computers which run separate MATLAB sessions.

To configure your host computer to work with the Support Package for ADALM-PLUTO Radio, see Guided Host-Radio Hardware Setup.

Required Hardware

To capture signals in real time, you need an ADALM-PLUTO radio and the corresponding support package add-On.

For a full list of communications toolbox supported SDR platforms, refer to Supported Hardware section of the SDR discovery page.

Bluetooth LE Radio Specifications

The Bluetooth Special Interest Group (SIG) [2] introduced LE for low power short range communication, operating 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 radio frequency (RF) channels. Bluetooth LE uses Gaussian Minimum Shift Keying (GMSK) modulation scheme. The Bluetooth standard [1] 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).

The Bluetooth LE standard specifies these physical layer (PHY) 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)

Bluetooth LE Packet Formats

The air interface packet formats for PHY modes include these fields:

  • Preamble — The preamble depends on PHY transmission mode. LE1M mode uses an 8-bit sequence of alternate zeros and ones, '01010101'. LE2M uses a 16-bit sequence of alternate zeros and ones, '0101...'. LE500K and LE125K modes use an 80-bit sequence of zeros and ones obtained by repeating '00111100' ten times.

  • Access Address — Specifies the connection address shared between two Bluetooth LE devices using a 32-bit sequence.

  • Coding Indicator — 2-bit sequence used for differentiating coded modes (LE125K and LE500K).

  • Payload — Input message bits including both protocol data unit (PDU) and cyclic redundancy check (CRC). The maximum message size is 2080 bits.

  • Termination Fields — Two 3-bit vectors of zeros, used in forward error correction encoding. The termination fields are present for coded modes (LE500K and LE125K) only.

This figure shows the packet format for uncoded PHY (LE1M and LE2M) modes.

BLEUncodedPhy.png

This figure shows the packet format for coded PHY (LE500K and LE125K) modes.

BLECodedPhy.png

Receiver and SDR Configuration

Specify the PHY transmission mode as "LE1M", "LE2M", "LE125K", or "LE500K". You can change phyMode parameter to decode the received Bluetooth LE waveform based on the PHY transmission mode.

phyMode = "LE1M";

Initialize the receiver parameters by using the helperBLEReceiverConfig helper function.

bleParam = helperBLEReceiverConfig(phyMode);

Specify the signal source as "File" or "ADALM-PLUTO".

  • File — Use the comm.BasebandFileReader System object™ to read a file that contains a previously captured over-the-air signal.

  • ADALM-PLUTO — Use the sdrrx System object™ to receive a live signal from the SDR hardware.

If you assign ADALM-PLUTO as the signal source, the example searches your computer for the ADALM-PLUTO radio at radio address 'usb:0' and uses it as the signal source.

signalSource = "File";
if signalSource == "File"

Specify the corresponding baseband file.

    switch bleParam.Mode
        case "LE1M"
            bbFileName = "bleCapturesLE1M.bb";
        case "LE2M"
            bbFileName = "bleCapturesLE2M.bb";
        case "LE500K"
            bbFileName = "bleCapturesLE500K.bb";
        case "LE125K"
            bbFileName = "bleCapturesLE125K.bb";
        otherwise
            error("Invalid PHY transmission mode. Valid entries are LE1M, LE2M, LE500K and LE125K.");
    end
    sigSrc = comm.BasebandFileReader(bbFileName);
    sigSrcInfo = info(sigSrc);
    sigSrc.SamplesPerFrame = sigSrcInfo.NumSamplesInData;
    bbSampleRate = sigSrc.SampleRate;
    bleParam.SamplesPerSymbol = bbSampleRate/bleParam.SymbolRate;

elseif signalSource == "ADALM-PLUTO"

Check if the ADALM-PLUTO hardware support package (HSP) add-on exists.

    if isempty(which("plutoradio.internal.getRootDir"))
        link = sprintf('<a href="https://www.mathworks.com/hardware-support/adalm-pluto-radio.html"> ADALM-PLUTO Radio Support From Communications Toolbox</a>');
        error("Unable to find Communications Toolbox Support Package for ADALM-PLUTO Radio. To install the support package, visit %s.", link);
    end

Specify the base-band sample rate.

    bbSampleRate = bleParam.SymbolRate*bleParam.SamplesPerSymbol;

Create receiver System object™ for radio hardware

    sigSrc = sdrrx("Pluto",RadioID="usb:0", ...
        CenterFrequency=2.402e9, ...
        BasebandSampleRate=bbSampleRate, ...
        SamplesPerFrame=1e7, ...
        GainSource="Manual", ...
        Gain=25, ...
        OutputDataType="double");
else
    error("Invalid signal source. Valid entries are File and ADALM-PLUTO.");
end

Set the configuration to display the frequency spectrum of the PHY waveform.

spectrumScope = spectrumAnalyzer(Method="welch", ...
    SampleRate=bbSampleRate, ...
    SpectrumType="Power density", ...
    SpectralAverages=10, ...
    YLimits=[-130 -20], ...
    Title="Received Baseband Bluetooth LE Signal Spectrum", ...
    YLabel="Power spectral density");

Capture Bluetooth LE Packets

Capture the transmitted waveform as a burst.

dataCaptures = sigSrc();

Visualize the power spectral density of the received waveform.

spectrumScope(dataCaptures)

Receiver Processing

This figure shows the workflow of receiver.

Block Diagram.png

To decode the PDU header information and raw message bits from the received base-band samples, the Bluetooth LE receiver performs these functions:

  1. Perform automatic gain control (AGC).

  2. Remove DC offset.

  3. Estimate and correct for the carrier frequency offset.

  4. Perform matched filtering with Gaussian pulse.

  5. Perform timing synchronization

  6. Perform GMSK demodulation.

  7. Perform FEC decoding and pattern demapping for LE coded PHY (LE500K and LE125K).

  8. Perform data de-whitening.

  9. Perform CRC check on the decoded PDU.

  10. Compute packet error rate (PER).

Create an AGC System object™, specifying the maximum gain as 20 dB and the desired output power as 2 dBm.

agc = comm.AGC(MaxPowerGain=20,DesiredOutputPower=2);

Create a coarse frequency compensator object to compensate for the carrier frequency offset.

freqCompensator = comm.CoarseFrequencyCompensator(Modulation="OQPSK", ...
    SampleRate=bbSampleRate, ...
    SamplesPerSymbol=2*bleParam.SamplesPerSymbol, ...
    FrequencyResolution=100);

Create a preamble detector System object™, specifying the preamble and output of the index for the first detection.

prbDet = comm.PreambleDetector(bleParam.RefSeq,Detections="First");

Initialize the packet count and the CRC count to 0.

[packetCount,crcCount] = deal(0);

Enable the displayFlag flag to print the received data.

displayFlag = true;

Loop to decode the captured Bluetooth LE samples

while length(dataCaptures) > bleParam.MinimumPacketLen

Consider two frames from the captured signal for each iteration

    startIndex = 1;
    endIndex = min(length(dataCaptures),2*bleParam.FrameLength);
    rcvSig = dataCaptures(startIndex:endIndex);

Perform AGC on the received signal.

    rcvAGC = agc(rcvSig);

Remove the DC offset.

    rcvDCFree = rcvAGC - mean(rcvAGC);

Estimate and compensate for the carrier frequency offset.

    rcvFreqComp = freqCompensator(rcvDCFree);

Perform matched filtering Gaussian pulse.

    rcvFilt = conv(rcvFreqComp,bleParam.h,"same");

Perform frame timing synchronization on the filtered waveform.

    [~, dtMt] = prbDet(rcvFilt);
    release(prbDet)
    prbDet.Threshold = max(dtMt);
    prbIdx = prbDet(rcvFilt);

Extract message information by using the helperBLEPhyBitRecover helper function.

    [cfgLLAdv,packetCount,crcCount,remStartIdx] = helperBLEPhyBitRecover(rcvFilt, ...
        prbIdx,packetCount,crcCount,bleParam);
    dataCaptures = dataCaptures(1+remStartIdx:end);

Display the decoded information.

    if displayFlag && ~isempty(cfgLLAdv)
        fprintf("Advertising PDU Type: %s\n",cfgLLAdv.PDUType)
        fprintf("Advertising Address: %s\n",cfgLLAdv.AdvertiserAddress)
    end

Release System objects.

    release(agc)
    release(freqCompensator)
    release(prbDet)
end
Advertising PDU Type: Advertising indication
Advertising Address: 1234567890AB
Advertising PDU Type: Advertising indication
Advertising Address: 1234567890AB

Release the signal source.

release(sigSrc)

Determine the PER

if packetCount
    per = 1 - (crcCount/packetCount);
    fprintf("Packet error rate for %s mode is %f.\n",bleParam.Mode,per)
else
    fprintf("\n No Bluetooth LE packets were detected.\n")
end
Packet error rate for LE1M mode is 0.000000.

Further Exploration

You can explore and run the Bluetooth LE Waveform Generation and Transmission Using SDR example to generate and transmit a standard-compliant Bluetooth LE waveform by using the SDR. Then, use this example to demodulate and decode the LE waveform. You can also use this example to transmit the data channel PDUs by changing the channel index, the access address and the center frequency values.

Troubleshooting

General tips for troubleshooting SDR hardware and the Communications Toolbox Support Package for ADALM-PLUTO Radio can be found in Common Problems and Fixes.

Appendix

This example uses these helper functions.

Selected Bibliography

  • Bluetooth Technology Website. “Bluetooth Technology Website | The Official Website of Bluetooth Technology.” Accessed June 30, 2024. https://www.bluetooth.com/

  • Bluetooth Special Interest Group (SIG). "Bluetooth Core Specification". Version 5.3. https://www.bluetooth.com/

Related Topics