Estimate Distance Between Bluetooth LE Devices by Using Channel Sounding and Phase-Based Ranging
This example shows how to estimate the distance between two Bluetooth® low energy (LE) devices by using the channel sounding (CS) tone exchanges and phase-based ranging (PBR).
Using this example, you can:
Create, configure, and generate a Bluetooth LE CS waveform.
Add propagation delay to the generated waveform based on the distance between the two devices.
Compute the phase rotations of the CS tone transmission between the two devices.
Simulate the scenario, and estimate the distance between the two devices by using a PBR estimate.
Compare the estimated distance and the actual distance between the devices by calculating the mean squared error (MSE).
Channel Sounding
CS for Bluetooth LE, introduced by the Bluetooth Special Interest Group (SIG) [1] in the uncoded LE1M and LE2M physical layer (PHY) transmission modes, 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 Steps and Step Mode-2 Packet
CS outlines a series of interconnected transfers between two devices, where the device initiating the CS procedures is known as the Initiator and the responding device is called the Reflector. The CS step count starts at 0 and increments by 1 with each step in the procedure, regardless of the execution of the step. The CS steps include a combination of modulated packets and CS tones.
The CS steps contain these distinct modes, each designed for specific purposes:
Step mode-0 — Measures the frequency offset between devices
Step mode-1 — Measures the round-trip times between the devices
Step mode-2 — Measures phase rotations based on the distance between the devices
Step mode-3 — Combines measurements of round-trip times and phase rotations
Executing CS steps requires the Initiator and the Reflector to synchronize their timing precisely. The steps occur at intervals that allow for a frequency hop, which ensures the CS procedure runs smoothly. To estimate the distance between two Bluetooth LE devices, this example employs CS step mode-2 as defined in [3].
In CS step mode-2, amplitude-shift keying (ASK) modulation measures the phase rotations of the signal between the Initiator and Reflector. This figure shows the CS Tone packet format, which maintains a constant sinusoidal tone throughout the duration of CS step mode-2.
The equation computes the duration of the CS step mode-2.
where,
is the total duration of CS step mode-2.
represents the number of antenna paths between the Initiator and the Reflector.
is the duration of the CS tone.
is the duration of the CS tone extension slot.
The duration of the CS tone, the duration of the CS tone extension slot, and the number of antenna paths between the Initiator and the Reflector determines the duration of CS step mode-2. The duration of the CS tone extension slot matches the duration of the last CS tone . This table shows the permitted values for the CS tone duration.
Index | |
0 | 10 |
1 | 20 |
2 | 40 |
To estimate the distance between two Bluetooth devices, this example uses a single antenna path configuration of 1:1, as defined in [3]. Each CS tone set is followed by a CS tone extension slot.
Compute Phase Rotations and Distance
To measure the phase rotations of the propagation channel, Bluetooth LE devices use the CS tone exchange procedure. This procedure captures the phase rotations for the Bluetooth LE CS tone packet traveling from the Initiator to the Reflector or the other way around. The PBR measures the phase of the packet as it travels from the Initiator to the Reflector and back to the Initiator. This figure shows a single CS tone packet exchange between an Initiator device and a Reflector device.
In this figure:
is the initial phase of the Initiator device.
is the initial phase of the Reflector device.
is the phase-based rotations at the Reflector from the Initiator.
The Initiator initiates the CS tone procedure by transmitting the first CS tone in the CS tone exchange. The CS tone undergoes phase rotation while traveling from the Initiator to the Reflector.
The CS tone 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 distance by using the phase rotations and the frequency of the channel .
The angle of the signal at the Initiator device is . At the Reflector device, the observed phase rotations of the signal from the Initiator to the Reflector .
Similarly, at the Initiator device, the observed phase rotations of the response signal from the Reflector device to the Initiator device .
Adding the phase calculations, you get:
This estimate of phase rotation is compromised by the ambiguity. To obtain an unambiguous estimate, you must combine the results from measurements over several frequencies as
.
This equation computes the distance between the two devices.
,
where:
— Distance between the Initiator and the Reflector
— Speed of light
CS Tone Exchange Procedure
This figure shows the CS tone exchange procedure for CS step mode-2.
To estimate the distance between the Initiator and the Reflector, perform these steps.
Generate the CS tone waveform at the Initiator.
Add the propagation delay to the generated Bluetooth LE CS tone.
Add the additive white Gaussian noise (AWGN) to the delayed waveform.
Receive the noisy waveform at the Reflector.
Calculate the phase rotations for the waveform, and generate a response waveform at the Reflector.
Add the propagation delay to the response CS tone.
Add the AWGN to the delayed response waveform.
Receive the noisy response waveform at the Initiator.
Calculate the phase rotations for the response waveform.
Estimate the distance between the Initiator and the Reflector by using the difference of phase rotations for two different channel frequencies.
Simulation Configuration
To ensure repeatability of results, set the seed for the random number generator to 0
. 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 results, after running the simulation, you can change the seed value, run the simulation again, and average the results over multiple simulations.
rng(0)
Specify the noise power spectral density (Eb/No), samples per symbol, and the speed of light.
EbNo = 6:4:22; % Eb/No in dB sps = 8; % Samples per symbol lightSpeedConst = physconst("LightSpeed"); % Speed of light in m/s
Specify the CS step mode as 2
for CS tone exchanges.
csStepMode = 2;
Specify the duration of the CS tone as 10
, 20
, or 40
microseconds.
toneDuration = 40;
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 distance between the Initiator and the Reflector devices.
distance = randsrc(1,1,0.5:0.5:20); % In meters tPropagation = distance/lightSpeedConst; % In seconds
Preallocate the space to compute and store the mean square error.
avgError = zeros(numMode,snrLength);
Define carrier frequencies for two channels between 2.404
GHz and 2.478
GHz.
k = randi([0 74],1,1); Fc = [2404+k 2404+k+1]*1e6;
Specify the initial phases of the Initiator and the Reflector.
phi0I = rand*pi/4; phi0R = rand*pi/4;
Specify the maximum number of packets to simulate at each Eb/No point. Once the number of packets reaches this value, the simulation is complete.
maxNumPackets = 100;
Specify the types of device roles as "Initiator
" and "Reflector
".
devices = ["Initiator","Reflector"];
Simulate for the "LE1M
" and "LE2M
" PHY modes.
for countMode = 1:numMode
phyMode = simMode(countMode);
Calculate the sampling frequency of the generated waveform.
sampleRate = sps*1e6*(1+1*(phyMode=="LE2M")); % In Hz
Specify the Bluetooth LE CS configuration object for the Bluetooth LE CS device.
configObject = bleCSConfig(Mode=phyMode, ... SamplesPerSymbol=sps, ... ToneDuration=toneDuration, ... StepMode=csStepMode);
Set the signal-to-noise ratio (SNR).
snr = EbNo - 10*log10(sps);
Simulations and Results
Simulate each Bluetooth LE CS packet for different Eb/No values.
for countSnr = 1:snrLength
snrVal = snr(countSnr);
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 tone packet by performing the steps from the CS tone packet exchange procedure.
while countPacket <= maxNumPackets
Preallocate memory to store the estimated phase.
phaseEstimate = deal(zeros(2,1));
Simulate each packet for two different channels.
for countFc = 1:length(Fc)
Define the frequency of the channel.
fc = Fc(countFc); % 2.4 GHz - 2.485 GHz
Specify the phase to delay by using the propagation time and the frequency of the channel.
phaseToDelay = (2*pi*fc)*tPropagation;
Preallocate memory to store the estimate of the phase rotations of the two devices.
phaseRotation = zeros(2,1);
Simulate for the "Initiator
" and the "Reflector
" devices.
for countDeviceRole = 1:2
deviceRole = devices(countDeviceRole);
Specify the device role.
configObject.DeviceRole = deviceRole;
Generate the CS tone waveform.
waveformInit = bleCSWaveform(configObject);
Add a propagation delay to the generated waveform.
delayWaveform = waveformInit*exp(1j*(-phaseToDelay))*exp((-1j)*(-1)^countDeviceRole*(phi0I-phi0R));
Add AWGN to the delayed waveform.
noisyWaveform = awgn(delayWaveform,snrVal,"measured");
Calculate phase rotations between the two devices by using the helperBLEPhaseEstimate
helper function.
phaseRotation(countDeviceRole) = helperBLEPhaseEstimate(noisyWaveform,configObject);
end
Estimate the phase-based rotations between the Initiator and the Reflector by adding the phase rotations.
phaseEstimate(countFc) = sum(phaseRotation);
end
Compute the difference of the phase-based rotations between the different channels.
phaseChangeCalc = phaseEstimate(2) - phaseEstimate(1);
Wrap the difference in the phase rotations to 2.
deltaPhaseASK = wrapTo2Pi(phaseChangeCalc);
Compute the frequency change between the two channels.
deltaF = diff(Fc);
Estimate the distance between the Initiator and the Reflector.
estimatedDistance(countPacket) = (lightSpeedConst/(4*pi*deltaF))*deltaPhaseASK;
Increment the packet count by one.
countPacket = countPacket + 1;
end
Calculate the MSE of the estimated distance derived from the CS step mode-2 packet exchange.
absoluteErrorDist = (estimatedDistance-distance); avgError(countMode,countSnr) = rms(absoluteErrorDist);
Display a message for the particular value of the SNR.
disp("For Mode = "+phyMode+", Eb/No = "+num2str(EbNo(countSnr))+ ... "dB and Distance = "+distance+"m : MSE(m) is "+num2str(avgError(countMode,countSnr))) end end
For Mode = LE1M, Eb/No = 6dB and Distance = 16.5m : MSE(m) is 2.888 For Mode = LE1M, Eb/No = 10dB and Distance = 16.5m : MSE(m) is 1.815 For Mode = LE1M, Eb/No = 14dB and Distance = 16.5m : MSE(m) is 1.1096 For Mode = LE1M, Eb/No = 18dB and Distance = 16.5m : MSE(m) is 0.71905 For Mode = LE1M, Eb/No = 22dB and Distance = 16.5m : MSE(m) is 0.45867 For Mode = LE2M, Eb/No = 6dB and Distance = 16.5m : MSE(m) is 1.5144 For Mode = LE2M, Eb/No = 10dB and Distance = 16.5m : MSE(m) is 1.0057 For Mode = LE2M, Eb/No = 14dB and Distance = 16.5m : MSE(m) is 0.62419 For Mode = LE2M, Eb/No = 18dB and Distance = 16.5m : MSE(m) is 0.41054 For Mode = LE2M, Eb/No = 22dB and Distance = 16.5m : MSE(m) is 0.25096
Estimate Distance and Plot MSE
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 PBR in the LE1M and LE2M PHY modes. As compared to the 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 decreases, leading to more accurate distance measurements.
Appendix
The example uses this helper function.
helperBLEPhaseEstimate
— Estimate the time of arrival of the Bluetooth LE CS tone waveform using PBR.
Selected Bibliography
[1] Bluetooth Technology Website. “Bluetooth Technology Website | The Official Website of Bluetooth Technology.” Accessed March 30, 2024. 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.” March 30, 2024. https://www.bluetooth.com/specifications/specs/channel-sounding-cr-pr/.