diff --git a/where_fi/application.py b/where_fi/application.py index d51400a..d0e82bd 100644 --- a/where_fi/application.py +++ b/where_fi/application.py @@ -131,7 +131,6 @@ class CSIApplication: """ def decorator(data: CSIMatrix) -> None: - self.visualise_data(data, visualise.figures.Figure.RAW_CSI) func(data) self.preprocessed_csi_callback = decorator diff --git a/where_fi/processing/preprocess.py b/where_fi/processing/preprocess.py index 4f4c70a..8c70b72 100644 --- a/where_fi/processing/preprocess.py +++ b/where_fi/processing/preprocess.py @@ -123,9 +123,28 @@ class Preprocessor: return csi + def normalise_magnitude( + self, csi: CSIMatrix, frames: dict[CSIHost, CSI] + ) -> CSIMatrix: + """ + Normalise the magnitude of the CSI data to compensate for the effect of the + Automatic Gain Control (AGC) of the receiver + + References: + [1] - + """ + rssi = [ + frames[host].header.rssi1 if antenna == 0 else frames[host].header.rssi2 + for host, antenna in config.antennas.order + ] + rssi_linear = np.reshape(10 ** (np.array(rssi) / 10), (1, -1, 1)) + csi_power = np.sum(np.abs(csi) ** 2) + return csi * np.sqrt(rssi_linear / csi_power) + def preprocess( self, h: CSIMatrix, + frames: dict[CSIHost, CSI], visualiser: None | Callable[[npt.NDArray[Any], visualise.figures.Figure], None] = None, ) -> CSIMatrix: @@ -144,6 +163,7 @@ class Preprocessor: # h_hat = correlate(h_hat, np.ones((3, 1, 1)) / 3) # h_hat = correlate(h_hat, [[[1 / 4]], [[1 / 2]], [[1 / 4]]], mode="valid") + h_hat = self.normalise_magnitude(h_hat, frames) h_hat = self.remove_sfo(h_hat, visualiser=visualiser) # Skip subcarrierss per config