diff --git a/where_fi/config/models.py b/where_fi/config/models.py index 9d07d90..8033205 100644 --- a/where_fi/config/models.py +++ b/where_fi/config/models.py @@ -105,16 +105,16 @@ class Config(BaseModel): raise ValueError(f"{self.central_freq} is not a valid Wi-Fi channel") @property - def num_pilots(self) -> int: + def num_guards(self) -> int: if self.channel_width == 20: - return 8 - if self.channel_width == 40: - return 14 - return 24 + return 7 + return 11 @property def subcarriers(self) -> int: - return int((self.channel_width * 1e6) // self.delta_f) - self.num_pilots + return ( + int((self.channel_width * 1e6) // self.delta_f) - self.num_guards + ) // self.preprocessing.subcarrier_step @property def _delta_f_no_skipping(self) -> int: diff --git a/where_fi/processing/preprocess.py b/where_fi/processing/preprocess.py index b933192..be37609 100644 --- a/where_fi/processing/preprocess.py +++ b/where_fi/processing/preprocess.py @@ -147,11 +147,27 @@ class Preprocessor: This is done by averaging the subcarriers before and after the pilot subcarriers. Pilots are detected by checking that the value is exactly 0. + + Also, it adds placeholders for the middle null subcarriers. """ + + num_middle = 1 if config.channel_width == 20 else 3 + assert csi.shape[0] + num_middle == config.subcarriers + with_middle = np.zeros( + (csi.shape[0] + num_middle, csi.shape[1], csi.shape[2]), dtype=np.complex64 + ) + with_middle[: csi.shape[0] // 2, :, :] = csi[: csi.shape[0] // 2, :, :] + with_middle[csi.shape[0] // 2 + num_middle :, :, :] = csi[ + csi.shape[0] // 2 :, :, : + ] + if num_middle == 3: + with_middle[csi.shape[0] // 2 + 1, :, :] = ( + csi[csi.shape[0] // 2 - 1, :, :] + csi[csi.shape[0] // 2, :, :] + ) / 2 return np.where( - np.expand_dims(csi[:, 0, 0] == 0, axis=(1, 2)), - correlate(csi, [[[1 / 2]], [[0]], [[1 / 2]]], mode="same"), - csi, + np.expand_dims(with_middle[:, 0, 0] == 0, axis=(1, 2)), + correlate(with_middle, [[[1 / 2]], [[0]], [[1 / 2]]], mode="same"), + with_middle, ) def bandpass(self, csi: CSIMatrix) -> CSIMatrix: @@ -206,7 +222,7 @@ class Preprocessor: case "bandpass": h_hat = self.bandpass(h_hat) - logger.debug(f"CSI shape: {h_hat.shape}") + logger.info(f"CSI shape: {h_hat.shape}") self._last_sample = h_hat