Main Content

Estimate Distance Between Bluetooth LE Devices by Using Channel Sounding

Since R2024a

This example shows how to estimate the distance between two Bluetooth® low energy (LE) devices by using the channel sounding (CS) SYNC packet exchange.

Using this example, you can:

  1. Create and configure a Bluetooth LE CS SYNC packet and waveform by using a CS sequence.

  2. Add propagation delay to the waveform based on the distance between the two devices.

  3. Compute round-trip time (RTT) of flight between the two devices.

  4. Simulate the scenario, and estimate the distance between the two devices by using a fractional timing estimate.

  5. Compare the estimated distance and the actual distance between the devices by calculating the mean squared error (MSE).

Channel Sounding

The Bluetooth Special Interest Group (SIG) [1] has introduced CS for Bluetooth LE in the uncoded LE1M and LE2M physical layer (PHY) transmission modes. CS specifies 79 radio frequency (RF) channels within the 2.4 GHz industrial, scientific, and medical (ISM) band, assigning a unique channel index to each channel.

CS SYNC Packet

CS uses a distinct modulated bit sequence referred to as CS SYNC. The packet format of CS SYNC is similar to that of the LE uncoded PHY packet format, with the exception of the protocol data unit (PDU), cyclic redundancy check (CRC), and constant tone extension (CTE) fields. This figure shows the CS SYNC packet format.

CS-SYNC packet format for LE1M and LE2M PHY Transmission modes.

In the LE1M PHY mode, the Preamble field contains 8 bits during transmission or reception, and in the LE2M PHY mode, it contains 16 bits. The CS Access Address field is 32 bits long, generated by using the CS deterministic random bit generator (DRBG). The Trailer field is a 4-bit alternating sequence of 0s and 1s. The Sounding Sequence or Random Sequence field is optional. If included, the Sounding Sequence field must be of 32 or 96 bits in length. The Random Sequence field, if included, must be 32, 64, 96, or 128 bits in length. When neither field is present, CS packets transmit in 44 microseconds on LE1M PHY and in 26 microseconds on LE2M PHY. Including the Sounding Sequence or Random Sequence field increases the CS packet transmission time, with the specific increase dependent on the size of the field and the specified PHY transmission mode.

To estimate the distance between two Bluetooth LE devices, this example uses the sounding sequence specified in [3].

Compute RTT and Distance

Bluetooth LE devices use the CS SYNC packet exchange procedure to measure the time of flight (TOF) of the propagation channel. The TOF represents the travel time for the Bluetooth LE CS SYNC packet from the Initiator to the Reflector, or in the opposite direction. The RTT measures the time for a packet to travel from the Initiator to the Reflector and back again. This figure shows a single-step CS SYNC packet exchange between an Initiator device and a Reflector device. In this figure:

  • TODI is the time of departure of the first packet transmitted from the Initiator.

  • TOAI is the time of arrival of the response packet received from the Initiator.

  • TOAR is the time of arrival of the packet received at the Reflector from the Initiator.

  • TODR is the time of departure of the response packet transmitted from the Reflector.

Round Trip Time of Flight in CS SYNC packet exchange

The Initiator initiates the CS SYNC procedure by transmitting the first packet in the CS SYNC exchange. The Reflector receives the transmission from the Initiator, and then sends a response back to the Initiator.

The CS SYNC packet exchange assesses the physical attributes of the transmission channel. These packet exchanges are bidirectional, with both the Initiator and the Reflector alternating between sending and receiving RF signals. The devices estimate the TOF by using the TOD and the TOA. This equation calculates the total time from when the Initiator device sends out a CS SYNC packet to when the response CS SYNC packet arrives back at the antenna of the Initiator device.

tInitiator=TOAI-TODI

Similarly, this equation calculates the total time starting from the moment a CS SYNC packet arrives at the antenna of the Reflector device to the moment when the Reflector device transmits the response CS SYNC packet.

tReflector=TODR-TOAR

This equation calculates the RTT of the CS SYNC packet by determining the difference between tInitiator and tReflector. This difference signifies the total flight time of the CS SYNC packet, encompassing the time TOF1 it takes to travel from the Initiator to the Reflector and the time TOF2 it takes for the response CS SYNC packet to travel back from the Reflector to the Initiator.

RTT=tInitiator-tReflector=(TOAI-TODI)-(TODR-TOAR)=TOF1+TOF2$x = \frac{(TOA_A-TOD_A)-(TOD_B-TOA_B)}{2} \times c$

Assuming both devices operate on the same time base and maintain line-of-sight conditions without reflections, the propagation channel exhibits symmetry between the transmissions from the Initiator to the Reflector and from the Reflector back to the Initiator. Consequently, TOF1 and TOF2 must be identical.

TOF1=TOF2=TOF

This equation derives the TOF from the RTT:

RTT=TOF1+TOF2=2×TOF

TOF=RTT2=(TOAI-TODI)-(TODR-TOAR)2

This equation computes the distance between the two devices by using the TOF at the Initiator device.

d=TOF×c=(TOAI-TODI)-(TODR-TOAR)2×c

where:

  • d — Distance between two the Initiator and the Reflector

  • RTT — Round-trip TOF

  • c — Speed of light

CS SYNC Packet Exchange

This figure shows the CS SYNC packet exchange procedure that this example uses.

Channel Sounding CS SYNC Packet exchange procedure.

To estimate the distance between the Initiator and the Reflector, perform these steps.

  1. Generate the CS SYNC waveform at the Initiator.

  2. Add the propagation delay to the generated Bluetooth LE CS SYNC waveform.

  3. Pass the delayed waveform through the AWGN channel.

  4. Receive the noisy waveform at the Reflector.

  5. Calculate the TOA for the waveform, and generate a response waveform at the Reflector.

  6. Add the propagation delay to the response waveform.

  7. Pass the delayed response waveform through the AWGN channel.

  8. Receive the noisy response waveform at the Initiator.

  9. Calculate the TOA for the response waveform, and compute the RTT.

  10. Estimate the distance between the Initiator and the Reflector by using the RTT.

Simulation Configuration

Control random number generator by using the default algorithm and seed.

rng("default")

Specify the noise power spectral density (Eb/No), samples per symbol, and the speed of light.

EbNo = 6:4:30;                             % Eb/No in dB
sps = 8;                                   % Samples per symbol
lightSpeedConst = physconst("LightSpeed"); % Speed of light in m/s

Specify the PHY transmission mode as "LE1M" or "LE2M".

phyMode = "LE1M";

Specify the type of optional sequence in the CS SYNC packet format as "Sounding Sequence".

sequenceType = "Sounding Sequence";

Define the sounding sequence length as 32, or 96.

sequenceLength = 96;

Calculate the sampling frequency (in Hz) of the generated waveform.

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

Specify the maximum number of packets simulated at each Eb/No point. Once the number of packets reaches this value, the simulation is complete.

maxNumPackets = 20;

Calculate the number of Eb/No points of simulation.

snrLength = length(EbNo);

Specify the configuration parameters of the CS SYNC exchange from the Initiator to the Reflector.

configFormatI = struct(Mode=phyMode, ...
    SamplesPerSymbol=sps, ...
    SequenceLength=sequenceLength, ...
    SequenceType=sequenceType, ...
    TransmissionType="InitiatorToReflector");

Specify the configuration parameters of the CS SYNC exchange from the Reflector to the Initiator.

configFormatR = struct(Mode=phyMode, ...
    SamplesPerSymbol=sps, ...
    SequenceLength=sequenceLength, ...
    SequenceType=sequenceType, ...
    TransmissionType="ReflectorToInitiator");

Specify the length of the preamble, the access address, and the trailer in bits in the Bluetooth LE CS SYNC packet format.

preambleLength = 8*(1+1*(phyMode=="LE2M"));
accessAddressLength = 32;
trailerLength = 4;

Compute the length of the CS SYNC packet.

packetLength = preambleLength + accessAddressLength + trailerLength + sequenceLength;

Set the signal-to-noise ratio (SNR).

snr = EbNo-10*log10(sps);

Preallocate the space to compute and store the mean square error.

avgError = zeros(1,snrLength);

Preallocate the space to store the idle wait time and the TOA of the Reflector device.

[idleWaitTimeOfR,timeOfArrivalR] = deal(0);

Specify the distance (in meters) between the Initiator and the Reflector devices.

distance = randi([2 80],1,1);

Compute the waveform propagation time (in seconds) between the devices.

propagationTime = distance/lightSpeedConst;

To configure the delay profile, create a variable fractional delay object by using the dsp.VariableFractionalDelay (DSP System Toolbox) System object™.

timingDelay = dsp.VariableFractionalDelay;

Specify the number of samples to delay, based on the distance between the Initiator and Reflector devices.

samplesToDelay = propagationTime*sampleRate;

Simulations and Results

Simulate each Bluetooth LE CS SYNC packet for different Eb/No values.

for countSnr = 1:snrLength

Preallocate the space to store the estimated distance.

    estimatedDistance = zeros(maxNumPackets,1);

Initialize the the packet count to 1.

    countPacket = 1;

Simulate each Bluetooth LE CS SYNC packet by performing the steps from the CS SYNC packet exchange procedure.

    while countPacket <= maxNumPackets

Specify the TODI (in seconds) from the Initiator.

        timeOfDepartureI = randsrc(1,1,0:0.1:10)*(1e-6);

Generate a CS SYNC waveform at the Initiator by using the helperBLECSWaveformGenerate helper function.

        [waveformInitI,accessAddressI] = helperBLECSWaveformGenerate(configFormatI);

Add propagation delay to the generated waveform.

        delayWaveformRtoI = timingDelay([waveformInitI; zeros((ceil(samplesToDelay/sps))*sps,1)],samplesToDelay);

Add AWGN to the delayed waveform.

        noisyWaveformI = awgn(delayWaveformRtoI,snr(countSnr),"measured");

Calculate TOF by using the helperBLETOAEstimate helper function.

        configFormatI.AccessAddress = accessAddressI;
        [timeOfFlightItoR,qualityIndexItoR] = helperBLETOAEstimate(noisyWaveformI,configFormatI);

The quality index value associated with a received or intended-to-be-received CS SYNC packet serves as an integrity check. Use only CS SYNC packets with a quality index value of 0 for the RTT measurements. If the quality indication value for a packet is 0, calculate the TOAR at the Reflector.

        if ~qualityIndexItoR
            timeOfArrivalR  = timeOfDepartureI + timeOfFlightItoR;

Specify the idle wait time before the Reflector begins its response.

            if configFormatR.TransmissionType == "ReflectorToInitiator"
                % Define an integer specifying the time equal to the number
                % of frames to wait
                intFramesToDelay = randsrc(1,1,1:10);
                deviceIdleSamples = intFramesToDelay*packetLength*sps;

                % Define idle wait time of the Reflector in integer
                % multiples of the received waveform
                idleWaitTimeOfR = deviceIdleSamples/sampleRate;
            end

Generate a CS SYNC waveform at the Reflector by using the helperBLECSWaveformGenerate helper function.

            [waveformInitR,accessAddressR] = helperBLECSWaveformGenerate(configFormatR);

Add propagation delay to the generated waveform.

            delayWaveformRtoI = timingDelay([waveformInitR; zeros((ceil(samplesToDelay/sps))*sps,1)],samplesToDelay);

Add AWGN to the delayed waveform.

            noisyWaveformI = awgn(delayWaveformRtoI,snr(countSnr),"measured");

Calculate TOF by using the helperBLETOAEstimate helper function.

            configFormatR.AccessAddress = accessAddressR;
            [timeOfFlightRtoI,qualityIndexRtoI] = helperBLETOAEstimate(noisyWaveformI,configFormatR);

If quality indication value is 0, calculate the TOA at the Initiator.

            if ~qualityIndexRtoI

Compute the TODR from the Reflector.

                timeOfDepartureR = timeOfArrivalR + idleWaitTimeOfR;

Compute the TOAI at the Initiator.

                timeOfArrivalI = timeOfDepartureR + timeOfFlightRtoI;

Calculate the RTT at the Initiator device.

                roundTripTime = (timeOfArrivalI - timeOfDepartureI) - (timeOfDepartureR - timeOfArrivalR);

Estimate the distance between the Initiator and the Reflector.

                estimatedDistance(countPacket) = (roundTripTime/2)*lightSpeedConst;

Increment the packet count by one.

                countPacket = countPacket + 1;
            end
        end
    end
    reset(timingDelay)

Calculate the MSE of the estimated distance derived from the CS SYNC packet exchange.

    errorDistPercentage = 100*(estimatedDistance-distance)/distance;
    avgError(countSnr) = sqrt(mean(errorDistPercentage.^2));

Display a message for the specific value of the SNR.

    disp(join(["For Mode = ",phyMode,", Eb/No = ",num2str(EbNo(countSnr)), ...
        "dB and Distance = ",distance,"m : MSE(%) is ",num2str(avgError(countSnr))," %."],""))
end
For Mode = LE1M, Eb/No = 6dB and Distance = 66m : MSE(%) is 8.2247 %.
For Mode = LE1M, Eb/No = 10dB and Distance = 66m : MSE(%) is 6.53 %.
For Mode = LE1M, Eb/No = 14dB and Distance = 66m : MSE(%) is 3.2779 %.
For Mode = LE1M, Eb/No = 18dB and Distance = 66m : MSE(%) is 1.7188 %.
For Mode = LE1M, Eb/No = 22dB and Distance = 66m : MSE(%) is 1.3619 %.
For Mode = LE1M, Eb/No = 26dB and Distance = 66m : MSE(%) is 0.77394 %.
For Mode = LE1M, Eb/No = 30dB and Distance = 66m : MSE(%) is 0.7352 %.

Plot MSE of the Estimated Distance

plot(EbNo,avgError,"-ob")
grid on
xlabel("Eb/No (dB)")
ylabel("Distance Error (%)")
legend(phyMode)
title("MSE of the Estimated Distance for Each Eb/No Point")

The plot displays the error involved in estimating the distance from the RTT. AWGN distorts the waveform shown in the plot. As the SNR, measured by Eb/No, increases, the curve shows a reduction in the distance estimation error. This suggests that greater Eb/No values lead to more precise distance measurements.

Appendix

The example uses these helpers.

Selected Bibliography

[1] Bluetooth Technology Website. “Bluetooth Technology Website | The Official Website of Bluetooth Technology.” Accessed October 30, 2023. https://www.bluetooth.com/

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

[3] Bluetooth® Technology Website. “Channel Sounding,” October 30, 2023. https://www.bluetooth.com/specifications/specs/channel-sounding-cr-pr/.