Skip to content

Commit

Permalink
added some stand alone sc_tx/sc_rx tests
Browse files Browse the repository at this point in the history
  • Loading branch information
drowe67 committed Nov 5, 2024
1 parent 519955f commit 0035125
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 7 deletions.
40 changes: 35 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ add_test(NAME chirp_mpp
# Low SNR ota_test.sh, with chirp measurement, AWGN
add_test(NAME ota_test_awgn
COMMAND sh -c "cd ${CMAKE_SOURCE_DIR}; \
./test/ota_test_cal.sh ~/codec2-dev/build_linux/ -21 0.4")
./test/ota_test_cal.sh ${CODEC2_DEV_BUILD_DIR} -21 0.4")

# Low SNR ota_test.sh, with chirp measurement, MPP, high loss threshold as we only care about gross errors,
# like stuck in false sync
add_test(NAME ota_test_mpp
COMMAND sh -c "cd ${CMAKE_SOURCE_DIR}; \
./test/ota_test_cal.sh ~/codec2-dev/build_linux/ -24 0.4 --mpp --freq -25")
./test/ota_test_cal.sh ${CODEC2_DEV_BUILD_DIR} -24 0.4 --mpp --freq -25")


# Acquisition tests ------------------------------------------------------------------------------------
Expand Down Expand Up @@ -395,8 +395,38 @@ add_test(NAME radae_rx_aux_mpp

# BBFM -----------------------------------------------------------------------------------------------

add_test(NAME bbfm_single_carrier
# single carrier modem internal (inside single_carrier class) tests
add_test(NAME bbfm_sc_internal
COMMAND sh -c "cd ${CMAKE_SOURCE_DIR}; \
python3 -c 'from radae import single_carrier,single_carrier_tests; exit(single_carrier_tests())'")
set_tests_properties(bbfm_single_carrier PROPERTIES PASS_REGULAR_EXPRESSION "ALL PASS")
python3 -c 'from radae import single_carrier,single_carrier_tests; single_carrier_tests()'")
set_tests_properties(bbfm_sc_internal PROPERTIES PASS_REGULAR_EXPRESSION "ALL PASS")

# single carrier modem stand alone tx/rx, using BPSK symbol/BER test mode
add_test(NAME bbfm_sc_ber
COMMAND sh -c "cd ${CMAKE_SOURCE_DIR}; \
./bbfm_inference.sh model_bbfm_01/checkpoints/checkpoint_epoch_100.pth wav/brian_g8sez.wav /dev/null --write_latent z.f32; \
cat z.f32 | python3 sc_tx.py --ber_test > t.int16; \
cat t.int16 | python3 sc_rx.py --ber_test --target_ber 0 > /dev/null")
set_tests_properties(bbfm_sc_ber PROPERTIES PASS_REGULAR_EXPRESSION "PASS")

# single carrier modem stand alone tx/rx, using continuously valued BBFM symbols, compare loss in decoded features
add_test(NAME bbfm_sc_loss
COMMAND sh -c "cd ${CMAKE_SOURCE_DIR}; \
./bbfm_inference.sh model_bbfm_01/checkpoints/checkpoint_epoch_100.pth wav/brian_g8sez.wav /dev/null --write_latent z.f32; \
cat z.f32 | python3 sc_tx.py | python3 sc_rx.py > z_hat.f32; \
./bbfm_rx.sh model_bbfm_01/checkpoints/checkpoint_epoch_100.pth z_hat.f32 /dev/null; \
python3 loss.py features_in.f32 features_out.f32 --features_hat2 features_rx_out.f32 --compare")
set_tests_properties(bbfm_sc_loss PROPERTIES PASS_REGULAR_EXPRESSION "PASS")

# single carrier modem stand alone tx/rx with external 300-2700Hz band pass filter and no noise, measure loss. In practice, SNR will be
# quite high, so channel distortions other than noise may dominate
add_test(NAME bbfm_sc_bpf_loss
COMMAND sh -c "cd ${CMAKE_SOURCE_DIR}; \
./bbfm_inference.sh model_bbfm_01/checkpoints/checkpoint_epoch_100.pth wav/brian_g8sez.wav /dev/null --write_latent z.f32; \
cat z.f32 | python3 sc_tx.py | ${CODEC2_DEV_BUILD_DIR}/src/ch - - | python3 sc_rx.py > z_hat.f32; \
./bbfm_rx.sh model_bbfm_01/checkpoints/checkpoint_epoch_100.pth z_hat.f32 /dev/null; \
python3 loss.py features_in.f32 features_out.f32 --features_hat2 features_rx_out.f32 --compare")
set_tests_properties(bbfm_sc_bpf_loss PROPERTIES PASS_REGULAR_EXPRESSION "PASS")



2 changes: 1 addition & 1 deletion loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
parser.add_argument('--clip_start', type=int, default=0, help='remove this many frames from end, useful to remove start of over resync (default 0)')
parser.add_argument('--clip_end', type=int, default=0, help='remove this many frames from end, useful to remove end of over noise (default 0)')
parser.add_argument('--plot', action='store_true', help='plot loss versus time')
parser.add_argument('--compare', action='store_true', help='plot loss versus time')
parser.add_argument('--compare', action='store_true', help='compare features_hat and features_hat2')
args = parser.parse_args()

device = torch.device("cpu")
Expand Down
9 changes: 8 additions & 1 deletion sc_rx.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
parser.add_argument('--complex', dest="real", action='store_false', help='complex 2*int16 input samples (default real)')
parser.add_argument('-v', type=int, default=2, help='Verbose level (default 2)')
parser.add_argument('--plots', action='store_true', help='Enable plots when input data finished')
parser.add_argument('--target_ber', type=float, help='less than target BER to print Pass',default=2.0)
parser.set_defaults(real=True)
args = parser.parse_args()

Expand Down Expand Up @@ -114,12 +115,18 @@

print(f"{frames} frames processed", file=sys.stderr)

# optional debug info
# optional BER tests (BSPK symbols)
if args.ber_test:
ber = 0
if total_bits:
ber = total_errors/total_bits
print(f"total_bits: {total_bits:4d} total_errors: {total_errors:4d} BER: {ber:5.4f}", file=sys.stderr)
if args.target_ber < 1:
test_pass = ber <= args.target_ber
if test_pass:
print("PASS", file=sys.stderr)
else:
print("FAIL", file=sys.stderr)

if args.plots:
plt.figure(1)
Expand Down

0 comments on commit 0035125

Please sign in to comment.