Main Content

Bluetooth LE Waveform Generation and Visualization with Frequency Hopping

This example shows how to generate and visualize Bluetooth® low energy (LE) waveforms with frequency hopping for channel selection, supporting different physical layer (PHY) modes, by using Bluetooth Toolbox.

Using this example, you can:

  1. Create, configure, and generate a Bluetooth LE waveform by specifying the PHY generating mode as "LE1M", "LE2M", "LE500K", or "LE125K".

  2. Configure adaptive frequency hopping (AFH) and specify the channel selection algorithm as Algorithm #1 or Algorithm #2.

  3. Visualize the spectrum, spectrogram, and timescope of the generated Bluetooth LE waveform in both the time domain and frequency domain.

Additionally, this example script enables you to run the simulations for different used channel indices, and generate waveforms with or without frequency hopping.

Bluetooth LE Channel Selection and Frequency Hopping

Bluetooth LE is a standard, introduced by the Special Interest Group (SIG) [1], 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 uses 40 RF channels (each channel is 2 MHz wide). This figure shows the mapping between the frequencies and Bluetooth LE channels. Each of these RF channels receives a unique channel index (labeled as Channel in the figure).

Frequency hopping is a method of transmitting radio signals by rapidly switching a carrier among many frequency channels, using a pseudorandom sequence known to both transmitter and receiver. Bluetooth LE employs adaptive frequency hopping (AFH) to mitigate interference and improve its coexistence with other protocols. It transmits each component using a different channel, chosen according to the pseudo random/hopping sequence that changes periodically. The Bluetooth Core Specification defines Algorithm #1 and Algorithm #2 channel selection algorithms to select data channels for each connection event. For more information about the channel selection algorithms, see Vol 6, Part B, Section 4.5.8 of [2] and Bluetooth LE Channel Selection Algorithms.

Simulation Configuration

Specify the input parameters for generating a Bluetooth LE waveform. You can generate a Bluetooth LE waveform by specifying the PHY generating mode as "LE1M", "LE2M", "LE500K", or "LE125K".

numPackets = 10;       % Number of packets to generate
sps = 16;              % Samples per symbol
messageLength = 2000;  % Length of message in bits
phyMode = "LE1M";   
channelBW = 2e6;       % Channel spacing (Hz) as per standard

Define the symbol rate based on the PHY mode.

if any(strcmp(phyMode,["LE1M" "LE500K" "LE125K"]))
    symbolRate = 1e6;
else
    symbolRate = 2e6;
end

Frequency Hopping

Enable frequency hopping. Specify the channel selection algorithm as 1 for Algorithm #1 and 2 for Algorithm #2.

The two channel selection algorithms exclude channels susceptible to transmission errors by using a channel map exchanged between the Central and Peripheral nodes. The channel map identifies good (used) and bad (unused) data channels based on factors like signal-to-noise ratio (SNR) and packet error rate (PER). Communication between devices occurs over only good data channels, with the Central device updating the channel map upon identifying any bad channels. If the channel map deems a selected data channel bad, the Central device remaps it to a good one through a unique remapping procedure specific to each algorithm. For more information about the channel selection algorithms, see Vol 6, Part B, Section 4.5.8 of [2].

frequencyHopping = 1;
csa = 1;              % CSA Algorithm #1 or #2

Visualization

Create and configure a timescope (DSP System Toolbox) and spectrumAnalyzer (DSP System Toolbox) to display the time-domain signal and frequency spectrum of time-domain signal, respectively.

timeScopeVis = timescope(SampleRate=symbolRate*sps,TimeSpanSource="Auto", ...
    ShowLegend=true);

specAnalyzer = spectrumAnalyzer(Method="welch", ...
    SpectrumType="Power density", ...
    ViewType="spectrum-and-spectrogram", ...
    SampleRate=symbolRate*sps);

Channel Selection

Create and configure a bleChannelSelection System object™, specifying the type of channel selection algorithm and used channels.

if frequencyHopping
    frequencyHop = bleChannelSelection(Algorithm=csa);
    frequencyHop.UsedChannels = [0 5 9 13 24];
    if(csa == 1)
        frequencyHop.HopIncrement = 8;
    end
end

To ensure repeatability of results, set the seed for the random number generator to default. The seed value controls the pattern of random number generation. Initializing the random number generator using the same seed ensures the same result. To improve the accuracy of your simulation results after running the simulation, you can change the seed value, run the simulation again, and average the results over multiple simulations.

rng default

Simulation and Visualization

Loop over the number of packets for generating and visualizing Bluetooth LE waveform.

for packetIdx = 1:numPackets

Generate random message bits of 0 or 1 for the configured message length.

    message = randi([0 1],messageLength,1);

When frequency hopping is on, allocate the channel index based on the specified channel selection algorithm. If you turn off frequency hopping, the Central device selects a random channel index in the range [0, 39].

    if frequencyHopping
        channelIndex = frequencyHop();      % Channel index based on frequency hopping
    else
        channelIndex = randi([0 39],1,1);   % Channel index without frequency hopping
    end

According to the selected channel index, set the access address. The access address for the periodic advertising channel defaults to a predetermined value. For data channels, generate a random 32-bit access address according to the requirements specified in Vol 6, Part B, Section 2.2.1 of [2].

    if(channelIndex >= 37)
        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]';    % Default access address for periodic advertising channels
    else
        accessAddress = [0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 0 1 0 ...
            0 0 1 0 1 0 1 1 0 0 1 1 1]';    % Random access address for data channels
    end

Generate a Bluetooth LE waveform, specifying the PHY mode, samples per symbol, channel index, and access address.

    waveform = bleWaveformGenerator(message, ...
        Mode=phyMode, ...
        SamplesPerSymbol=sps, ...
        ChannelIndex=channelIndex, ...
        AccessAddress=accessAddress);     

Visualize the Bluetooth LE waveform in the time and frequency domains.

    specAnalyzer.FrequencyOffset = channelBW*channelIndex;
    specAnalyzer.Title = "Spectrum of " + phyMode + " Waveform for Channel Index = " + num2str(channelIndex);
    tic
    while toc < 0.5                         % To hold the spectrum for 0.5 seconds
        specAnalyzer(waveform)
    end
    timeScopeVis.Title = "Bluetooth LE " + phyMode + " Waveform for Channel Index = " + num2str(channelIndex);
    timeScopeVis(waveform)                    
end

Selected Bibliography

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

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

See Also

Functions

Objects

Related Topics

Go to top of page