Main Content

Bluetooth LE Waveform Generation and Transmission Using SDR

This example shows how to implement a Bluetooth® Low Energy (LE) transmitter using the Bluetooth® Library. You can either transmit Bluetooth LE signals using the ADALM-PLUTO radio or write in-phase and quadrature phase (IQ) samples corresponding to the Bluetooth LE waveform to a baseband file (*.bb). To receive the Bluetooth LE waveform,see Bluetooth LE Waveform Reception 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 and Software

To transmit signals in real time, you need 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 Bluetooth LE for low power short range communications, 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

Transmitter 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";

Link layer (LL) PDUs can be either advertising channel PDUs or data channel PDUs. You can configure and generate advertising channel PDUs using bleLLAdvertisingChannelPDUConfig and bleLLAdvertisingChannelPDU functions respectively. You can configure and generate data channel PDUs using bleLLDataChannelPDUConfig and bleLLAdvertisingChannelPDUDecode functions respectively.

Create and configure the Bluetooth LE LL advertising channel configuration object.

cfgLLAdv = bleLLAdvertisingChannelPDUConfig(PDUType="Advertising indication", ...
    AdvertisingData="0123456789ABCDEF", ...
    AdvertiserAddress="1234567890AB");

Generate a Bluetooth LE LL advertising channel PDU by using the corresponding configuration object.

messageBits = bleLLAdvertisingChannelPDU(cfgLLAdv);

Specify the samples per symbol

sps = 8;

Specify the channel index in the range [0, 39].

channelIndex = 37;

Specify the length of access address as 32.

accessAddressLen = 32;

Specify the access address value in hexadecimal and binary.

accessAddressHex = "8E89BED6";
accessAddressBin = int2bit(hex2dec(accessAddressHex),accessAddressLen,false);

Calculate the sampling frequency of the generated waveform in Hz.

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

Generate Bluetooth LE baseband IQ waveform by using the bleWaveformGenerator function.

txWaveform = bleWaveformGenerator(messageBits, ...
    Mode=phyMode, ...
    SamplesPerSymbol=sps, ...
    ChannelIndex=channelIndex, ...
    AccessAddress=accessAddressBin);

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

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

Show power spectral density of the Bluetooth LE signal.

spectrumScope(txWaveform);

Transmit Bluetooth LE Packets

Initialize the parameters required for signal source.

txCenterFrequency = 2.402e9;        % In Hz
txFrameLength = length(txWaveform);
txNumberOfFrames = 1e4;
txFrontEndSampleRate = sampleRate;

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

  • File — Uses the comm.BasebandFileWriter to write a baseband file.

  • ADALM-PLUTO — Uses the sdrtx System object™ to transmit a live signal from the SDR hardware.

signalSink = "File";
if signalSink == "File"

Write the baseband data to file bleCaptures.bb.

    sigSink = comm.BasebandFileWriter(CenterFrequency=txCenterFrequency, ...
        Filename="bleCaptures.bb", ...
        SampleRate=txFrontEndSampleRate);
    sigSink(txWaveform);

elseif signalSink=="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
    % If you assign ADALM-PLUTO as the signal source, the example searches
    % your computer for the ADALM-PLUTO radio.
    connectedRadios = findPlutoRadio;
    radioID = connectedRadios(1).RadioID;

Create a transmitter System object for an ADALM-PLUTO radio.

    sigSink = sdrtx("Pluto",RadioID=radioID, ...
        CenterFrequency=txCenterFrequency, ...
        Gain=0, ...
        SamplesPerFrame=txFrameLength, ...
        BasebandSampleRate=txFrontEndSampleRate);

Initialize the current frame to 1.

    currentFrame = 1;

Catch any exception generated by transfer of baseband data to the SDR hardware. If there is an exception, release the hardware resources used by the SDR System object.

    try
        while currentFrame <= txNumberOfFrames
            % Data transmission
            sigSink(txWaveform);
            % Update the counter
            currentFrame = currentFrame + 1;
        end
    catch ME
        release(sigSink);
        rethrow(ME)
    end
else
    error("Invalid signal sink. Valid entries are File and ADALM-PLUTO.");
end

Release the hardware resources used by the SDR System object.

release(sigSink)

Further Exploration

You can explore and run the Bluetooth LE Waveform Reception Using SDR example to receive a standard-compliant Bluetooth LE waveform by using the SDR and decode the waveform transmitted by this example. 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.

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/

See Also

Topics