diff --git a/tests/test_flight_2.csv b/tests/test_flight_2.csv index 6f4aab4..5c81eee 100644 --- a/tests/test_flight_2.csv +++ b/tests/test_flight_2.csv @@ -1,2 +1,2 @@ segment, startxyz, endxyz, speeds -constant-speed flyby, -10 20 30, 10 20 30, 30 30 \ No newline at end of file +constant-speed flyby, 0 -10 30, 0 10 30, 30 30 \ No newline at end of file diff --git a/tests/test_flight_3.csv b/tests/test_flight_3.csv new file mode 100644 index 0000000..6f4aab4 --- /dev/null +++ b/tests/test_flight_3.csv @@ -0,0 +1,2 @@ +segment, startxyz, endxyz, speeds +constant-speed flyby, -10 20 30, 10 20 30, 30 30 \ No newline at end of file diff --git a/tests/tests.py b/tests/tests.py index 71e38f9..3c891f0 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -107,6 +107,10 @@ def __init__(self, methodName: str = "runTest") -> None: renderer_2 = UASEventRenderer(params_2, 'asphalt', fs, 1.5) self.xout_2 = renderer_2.render(self.x) + params_3 = utils.load_params('tests/test_flight_3.csv') + renderer_3 = UASEventRenderer(params_3, 'asphalt', fs, 1.5) + self.xout_3 = renderer_3.render(self.x) + def test_output_sensible(self): # rendering should equal length of calculated trajectory self.assertEqual(len(self.renderer._flightpath.T), len(self.xout)) @@ -123,4 +127,10 @@ def test_output_sensible(self): self.assertTrue((self.renderer.r[:n] == 0).all()) # rendering of greater distance should have lower max amplitude - self.assertGreater(np.max(abs(self.xout)), np.max(abs(self.xout_2))) + self.assertGreater(np.max(abs(self.xout)), np.max(abs(self.xout_3))) + + # rendering of flight along Y should result in zero signal in Y channel + self.assertAlmostEqual(self.xout.T[1].sum(), 0) + + # rendering of flight along X should result in zero signal in X channel + self.assertAlmostEqual(self.xout_2.T[3].sum(), 0) diff --git a/uasevent/environment_model.py b/uasevent/environment_model.py index 3d1ee44..793587f 100644 --- a/uasevent/environment_model.py +++ b/uasevent/environment_model.py @@ -109,25 +109,27 @@ def __init__( ): self.max_amp = max_amp - self.c = c self.fs = fs self.reflection_surface = reflection_surface - self.theta, self.phi, self.r = utils.cart_to_sph(flightpath) # calculate delays and amplitude curve - delays = (self.r / self.c) * self.fs + _, _, r = utils.cart_to_sph(flightpath) + delays = (r / c) * self.fs self.init_delay = delays[0] self.delta_delays = np.diff(delays) - self.amp_env = 1 / (self.r**2) + self.amp_env = 1 / (r**2) self.frame_len = frame_len self.hop_len = frame_len // 2 - self.phi_per_frame = np.lib.stride_tricks.sliding_window_view( - self.phi, self.frame_len)[::self.hop_len].mean(1) - self.theta_per_frame = np.lib.stride_tricks.sliding_window_view( - self.theta, self.frame_len)[::self.hop_len].mean(1) self.N = N + # calculate angles per frame for reflection filter and spatialisation + position_per_frame = np.lib.stride_tricks.sliding_window_view( + flightpath, self.frame_len, 1)[:, ::self.hop_len].mean(2) + + self.theta_per_frame, self.phi_per_frame, _ = \ + utils.cart_to_sph(position_per_frame) + def apply_doppler(self, x): # init output array and initial read position out = np.zeros(len(self.delta_delays) + 1) @@ -192,7 +194,7 @@ def spatialise(self, x): return x_out def process(self, x): - if len(x) < len(self.r): + if len(x) < len(self.delta_delays + 1): raise ValueError('Input signal shorter than path to be rendered') return \