Skip to content

Commit 2bc6597

Browse files
committed
Add sample size consistency check between Python and C++
Introduced a check in sim_radar to validate that the Python 'samples_per_pulse' matches the C++ 'sample_size_' property. Raises a ValueError with detailed instructions if a mismatch is detected, helping prevent configuration inconsistencies between the two implementations.
1 parent d4ac290 commit 2bc6597

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/radarsimpy/includes/radarsimc.pxd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,9 @@ cdef extern from "radar.hpp":
288288
void InitBaseband(H *bb_real, # Real baseband buffer
289289
H *bb_imag) except + # Imaginary baseband buffer
290290
void SyncBaseband() except + # Synchronize device memory
291+
292+
# Radar properties
293+
int sample_size_ # Number of samples per pulse
291294

292295
#------------------------------------------------------------------------------
293296
# Simulation Engines

src/radarsimpy/simulator_radar.pyx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,22 @@ cpdef sim_radar(radar, targets, frame_time=None, density=1, level=None, interf=N
360360

361361
radar_c = cp_Radar(radar, frame_start_time)
362362

363+
# Validate samples_per_pulse consistency between Python and C++
364+
cdef int_t cpp_samples_per_pulse = radar_c.get()[0].sample_size_
365+
cdef int_t py_samples_per_pulse = radar.sample_prop["samples_per_pulse"]
366+
if cpp_samples_per_pulse != py_samples_per_pulse:
367+
raise ValueError(
368+
f"\nSamples Per Pulse Mismatch\n"
369+
f"-------------------------\n"
370+
f"Inconsistency detected between Python and C++ radar configurations.\n\n"
371+
f"Python samples_per_pulse: {py_samples_per_pulse}\n"
372+
f"C++ sample_size_: {cpp_samples_per_pulse}\n\n"
373+
f"This typically occurs when:\n"
374+
f"1. The pulse_length * sampling_frequency calculation differs between implementations\n"
375+
f"2. Rounding methods (ceil vs int) are inconsistent\n\n"
376+
f"Please ensure both implementations use the same calculation method."
377+
)
378+
363379
cdef double[:,:,::1] bb_real = np.empty(ts_shape, order='C', dtype=np.float64)
364380
cdef double[:,:,::1] bb_imag = np.empty(ts_shape, order='C', dtype=np.float64)
365381

0 commit comments

Comments
 (0)