Estimate Distance Between Bluetooth LE Devices by Using Channel Sounding and Round-Trip Timing
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:
Create and configure a Bluetooth LE CS SYNC packet and waveform by using a CS sequence.
Add propagation delay to the waveform based on the distance between the two devices.
Compute round-trip time (RTT) of flight between the two devices.
Simulate the scenario, and estimate the distance between the two devices by using a fractional timing estimate.
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.
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 [2].
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:
is the time of departure of the first packet transmitted from the Initiator.
is the time of arrival of the response packet received from the Initiator.
is the time of arrival of the packet received at the Reflector from the Initiator.
is the time of departure of the response packet transmitted from the Reflector.
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.
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.
This equation calculates the RTT of the CS SYNC packet by determining the difference between and . This difference signifies the total flight time of the CS SYNC packet, encompassing the time it takes to travel from the Initiator to the Reflector and the time it takes for the response CS SYNC packet to travel back from the Reflector to the Initiator.
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, and must be identical.
This equation derives the TOF from the RTT:
This equation computes the distance between the two devices by using the at the Initiator device.
where:
— Distance between two the Initiator and the Reflector
— Round-trip TOF
— Speed of light
CS SYNC Packet Exchange
This figure shows the CS SYNC packet exchange procedure that this example uses.
To estimate the distance between the Initiator and the Reflector, perform these steps.
Generate the CS SYNC waveform at the Initiator.
Add the propagation delay to the generated Bluetooth LE CS SYNC waveform.
Pass the delayed waveform through the AWGN channel.
Receive the noisy waveform at the Reflector.
Calculate the TOA for the waveform, and generate a response waveform at the Reflector.
Add the propagation delay to the response waveform.
Pass the delayed response waveform through the AWGN channel.
Receive the noisy response waveform at the Initiator.
Calculate the TOA for the response waveform, and compute the RTT.
Estimate the distance between the Initiator and the Reflector by using the RTT.
Simulation Configuration
To ensure repeatability of results, set the seed for the random number generator to 1234
. 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(1234)
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 CS step mode as 1
for CS SYNC exchanges.
csStepMode = 1;
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;
Specify the PHY transmission mode as "LE1M
" and "LE2M
".
simMode = ["LE1M","LE2M"]; numMode = length(simMode);
Calculate the number of Eb/No points of simulation.
snrLength = length(EbNo);
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 = 400;
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;
Preallocate the space to compute and store the mean square error.
avgError = zeros(numMode,snrLength);
Simulate for "LE1M
", and "LE2M
" PHY modes.
for countMode = 1:numMode
phyMode = simMode(countMode);
Calculate the sampling frequency (in Hz) of the generated waveform.
sampleRate = sps*1e6*(1+1*(phyMode=="LE2M"));
Specify the configuration parameters of the CS SYNC exchange from the Initiator to the Reflector.
configFormatI = bleCSConfig(Mode=phyMode, ... SamplesPerSymbol=sps, ... StepMode=csStepMode, ... SequenceLength=sequenceLength, ... SequenceType=sequenceType, ... DeviceRole="Initiator");
Specify the configuration parameters of the CS SYNC exchange from the Reflector to the Initiator.
configFormatR = bleCSConfig(Mode=phyMode, ... SamplesPerSymbol=sps, ... StepMode=csStepMode, ... SequenceLength=sequenceLength, ... SequenceType=sequenceType, ... DeviceRole="Reflector");
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 store the idle wait time and the TOA of the Reflector device.
[idleWaitTimeOfR,timeOfArrivalR] = deal(0);
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 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 (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 bleCSWaveform helper function.
[waveformInitI,accessAddressI] = bleCSWaveform(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.
[timeOfFlightItoR,qualityIndexItoR,accAddI] = helperBLETOAEstimate(noisyWaveformI,configFormatI,accessAddressI);
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 at the Reflector.
if ~qualityIndexItoR
timeOfArrivalR = timeOfDepartureI + timeOfFlightItoR;
Specify the idle wait time before the Reflector begins its response.
if configFormatR.DeviceRole == "Reflector" % 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 bleCSWaveform helper function.
[waveformInitR,accessAddressR] = bleCSWaveform(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.
[timeOfFlightRtoI,qualityIndexRtoI,accAddR] = helperBLETOAEstimate(noisyWaveformI,configFormatR,accessAddressR);
If quality indication value is 0, calculate the TOA at the Initiator.
if ~qualityIndexRtoI
Compute the from the Reflector.
timeOfDepartureR = timeOfArrivalR + idleWaitTimeOfR;
Compute the 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.
absoluteErrorDist = (estimatedDistance-distance); avgError(countMode,countSnr) = rms(absoluteErrorDist);
Display a message for the specific value of the SNR.
disp("For Mode = "+phyMode+", Eb/No = "+num2str(EbNo(countSnr))+ ... "dB and Distance = "+distance+"m : MSE is "+num2str(avgError(countMode,countSnr))+"m.") end end
For Mode = LE1M, Eb/No = 6dB and Distance = 17m : MSE is 13.958m. For Mode = LE1M, Eb/No = 10dB and Distance = 17m : MSE is 8.9078m. For Mode = LE1M, Eb/No = 14dB and Distance = 17m : MSE is 5.6773m. For Mode = LE1M, Eb/No = 18dB and Distance = 17m : MSE is 3.6054m. For Mode = LE1M, Eb/No = 22dB and Distance = 17m : MSE is 2.2801m. For Mode = LE1M, Eb/No = 26dB and Distance = 17m : MSE is 1.4355m. For Mode = LE1M, Eb/No = 30dB and Distance = 17m : MSE is 0.89882m. For Mode = LE2M, Eb/No = 6dB and Distance = 17m : MSE is 7.203m. For Mode = LE2M, Eb/No = 10dB and Distance = 17m : MSE is 4.5479m. For Mode = LE2M, Eb/No = 14dB and Distance = 17m : MSE is 2.8889m. For Mode = LE2M, Eb/No = 18dB and Distance = 17m : MSE is 1.842m. For Mode = LE2M, Eb/No = 22dB and Distance = 17m : MSE is 1.1792m. For Mode = LE2M, Eb/No = 26dB and Distance = 17m : MSE is 0.75948m. For Mode = LE2M, Eb/No = 30dB and Distance = 17m : MSE is 0.49386m.
Plot MSE of the Estimated Distance
Plot the MSE of the estimated distance for each Eb/No point.
marker = "+x"; legendVar = strings(numMode,1); for countMode = 1:numMode plot(EbNo,avgError(countMode,:),"-"+marker{1}(countMode),"LineWidth",2) hold on legendVar(countMode) = simMode(countMode); end grid on xlabel("Eb/No (dB)") ylabel("Distance Error (meters)") legend(legendVar) title("MSE of the Estimated Distance for Each Eb/No Point")
The plot shows the MSE of the estimated distance between each Eb/No point and RTT in the LE1M and LE2M PHY modes. As compared to LE2M PHY mode, the MSE of the estimated distance in LE1M is higher. Moreover, with an increase in Eb/NO, the MSE of the estimated distance reduces, leading to more accurate distance measurements.
Appendix
The example uses this helper.
helperBLETOAEstimate
— Estimate the time of arrival of the Bluetooth LE CS SYNC waveform using RTT
Selected Bibliography
[1] Bluetooth Technology Website. “Bluetooth Technology Website | The Official Website of Bluetooth Technology.” Accessed October 30, 2024. https://www.bluetooth.com/
[2] Bluetooth Special Interest Group (SIG). "Bluetooth Core Specification". Version 6.0. https://www.bluetooth.com/specifications/specs/core-specification-6-0/