Skip to content

Commit 14f4ea6

Browse files
eriksandgrenhermabe
authored andcommitted
bluetooth: cs_de: Changes to IFFT algo
The IFFT distance estimate algorithm should be able to handle missing channels. This commit removes the assumption that it would not. - Remove interpolation of IQ values for channels 23,24,25. Just set the IQs for these channels to 0. - Remove early return in `calculate_dist_ifft` when IQ values for one channel would be missing. The algo should handle this ok and we can still produce a distance estimate. Another change included in this commit is to resort to not doing any "left null compensation" in the specific case where: - The left_null_index is greater than the peak_index but not large enough for the left null compensation to result in a positive distance estimate. Previously this case would result in the distance estimate of 0. Signed-off-by: Erik Sandgren <[email protected]>
1 parent 9c4d837 commit 14f4ea6

File tree

1 file changed

+1
-30
lines changed

1 file changed

+1
-30
lines changed

subsys/bluetooth/cs_de/cs_de.c

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -153,46 +153,17 @@ static int32_t calculate_left_null_compensation_of_peak(int32_t peak_index,
153153
CONFIG_BT_CS_DE_NFFT_SIZE) > 0
154154
? (left_null_index + NORMAL_PEAK_TO_NULL -
155155
CONFIG_BT_CS_DE_NFFT_SIZE)
156-
: 0;
156+
: peak_index;
157157
} else {
158158
compensated_peak_index = left_null_index + NORMAL_PEAK_TO_NULL;
159159
}
160160
}
161161
return compensated_peak_index;
162162
}
163163

164-
static void interpolate_missing_frequencies(float *iq)
165-
{
166-
/* Channels 23, 24, and 25 are not allowed for use with channel sounding.
167-
* However, the FFT algorithm requires evenly spaced samples.
168-
* IQ values are therefore linearly interpolated from channels 22 and 26.
169-
*/
170-
171-
const uint8_t ch_22 = 22 - CHANNEL_INDEX_OFFSET;
172-
const uint8_t ch_26 = 26 - CHANNEL_INDEX_OFFSET;
173-
const float i_slope = (iq[2 * ch_26] - iq[2 * ch_22]) / 4.0f;
174-
const float q_slope = (iq[2 * ch_26 + 1] - iq[2 * ch_22 + 1]) / 4.0f;
175-
176-
for (uint8_t i = ch_22 + 1; i < ch_26; i++) {
177-
iq[2 * i] = iq[2 * ch_22] + i_slope * (i - ch_22);
178-
iq[2 * i + 1] = iq[2 * ch_22 + 1] + q_slope * (i - ch_22);
179-
}
180-
}
181164

182165
static void calculate_dist_ifft(float *dist, float iq_tones_comb[2 * CONFIG_BT_CS_DE_NFFT_SIZE])
183166
{
184-
interpolate_missing_frequencies(iq_tones_comb);
185-
186-
for (uint8_t n = 0; n < 2 * NUM_CHANNELS; n += 2) {
187-
if (iq_tones_comb[n] == 0.0f && iq_tones_comb[n + 1] == 0.0f) {
188-
/* Phase measurements are missing for some channels.
189-
* FFT cannot be used.
190-
*/
191-
LOG_DBG("Could not compute iFFT due to missing frequencies.");
192-
return;
193-
}
194-
}
195-
196167
#if CONFIG_BT_CS_DE_NFFT_SIZE == 512
197168
arm_cfft_f32(&arm_cfft_sR_f32_len512, iq_tones_comb, 0, 1);
198169
#elif CONFIG_BT_CS_DE_NFFT_SIZE == 1024

0 commit comments

Comments
 (0)