Skip to content

Commit 8efd6f8

Browse files
committed
building up ota test script to support 2020 modes
1 parent 6f2bcad commit 8efd6f8

File tree

2 files changed

+93
-17
lines changed

2 files changed

+93
-17
lines changed

script/test_2020x.sh

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,48 @@ FADING_DIR=$CODEC2_PATH/build_linux/unittest
1010
No_AWGN=-20
1111
No_Multipath=-25
1212
serial=0
13+
compressor_gain=6
14+
15+
# Approximation of Hilbert clipper analog compressor
16+
function analog_compressor {
17+
input_file=$1
18+
output_file=$2
19+
gain=$3
20+
cat $input_file | ch - - 2>/dev/null | \
21+
ch - - --No -100 --clip 16384 --gain $gain 2>/dev/null | \
22+
# final line prints peak and CPAPR for SSB
23+
ch - - --clip 16384 |
24+
# manually adjusted to get similar peak levels for SSB and FreeDV
25+
sox -t .s16 -r 8000 -c 1 -v 0.85 - -t .s16 $output_file
26+
}
27+
28+
function run_sim_ssb() {
29+
fullfile=$1
30+
filename=$(basename -- "$fullfile")
31+
extension="${filename##*.}"
32+
filename="${filename%.*}"
33+
channel=$2
34+
No=-100
35+
if [ "$channel" == "awgn" ]; then
36+
channel_opt=""
37+
No=$No_AWGN
38+
fi
39+
if [ "$channel" == "mpp" ] || [ "$channel" == "mpd" ]; then
40+
channel_opt='--'${channel}
41+
No=$No_Multipath
42+
fi
43+
fn=${filename}_ssb_${channel}.wav
44+
analog_compressor ${fullfile} ${filename}_ssb.raw ${compressor_gain}
45+
tmp=$(mktemp)
46+
ch ${filename}_ssb.raw $tmp --No $No ${channel_opt} --fading_dir ${FADING_DIR} 2>t.txt
47+
cat $tmp | sox -t .s16 -r 8000 -c 1 - ${fn} trim 0 6
48+
snr=$(cat t.txt | grep "SNR3k(dB):" | tr -s ' ' | cut -d' ' -f3)
49+
50+
echo "<tr>"
51+
echo "<td><a href=\"${fn}\">${serial}</a></td><td>ssb</td><td></td><td></td><td>${channel}</td><td>${snr}</td>"
52+
echo "</tr>"
53+
serial=$((serial+1))
54+
}
1355

1456
function run_sim() {
1557
fullfile=$1
@@ -56,13 +98,16 @@ function run_sim() {
5698
fi
5799

58100
fn=${filename}_${mode}_${clip}_${channel}${indopt_str}.wav
101+
tmp=$(mktemp)
102+
# note we let ch finish to get SNR stats (trim at end of sox causes an early termination)
59103
freedv_tx ${mode} ${fullfile} - --clip ${clipflag} ${indopt_flag} | \
60-
ch - - --No $No ${channel_opt} --fading_dir ${FADING_DIR} | \
61-
freedv_rx ${mode} - - | \
104+
ch - $tmp --No $No ${channel_opt} --fading_dir ${FADING_DIR} 2>t.txt
105+
freedv_rx ${mode} ${indopt_flag} $tmp - | \
62106
sox -t .s16 -r ${rateHz} -c 1 - ${fn} trim 0 6
107+
snr=$(cat t.txt | grep "SNR3k(dB):" | tr -s ' ' | cut -d' ' -f3)
63108

64109
echo "<tr>"
65-
echo "<td><a href=\"${fn}\">${serial}</a></td><td>${mode}</td><td>${clip_html}</td><td>${indopt_html}</td><td>${channel}</td>"
110+
echo "<td><a href=\"${fn}\">${serial}</a></td><td>${mode}</td><td>${clip_html}</td><td>${indopt_html}</td><td>${channel}</td><td>${snr}</td>"
66111
echo "</tr>"
67112
serial=$((serial+1))
68113
}
@@ -75,10 +120,14 @@ sox $SPEECH_IN_16k_WAV -t .s16 $SPEECH_IN_16k_RAW
75120
sox $SPEECH_IN_16k_WAV -t .s16 -r 8000 $SPEECH_IN_8k_RAW
76121

77122
echo "<html><table>"
78-
echo "<tr><th>Serial</th><th>Mode</th><th>Clip</th><th>index_opt</th><th>Channel</th></tr>"
123+
echo "<tr><th>Serial</th><th>Mode</th><th>Clip</th><th>index_opt</th><th>Channel</th><th>SNR (dB)</th></tr>"
79124

80125
# run simulations
81126

127+
run_sim_ssb $SPEECH_IN_8k_RAW awgn
128+
run_sim_ssb $SPEECH_IN_8k_RAW mpp
129+
run_sim_ssb $SPEECH_IN_8k_RAW mpd
130+
82131
run_sim $SPEECH_IN_16k_RAW 2020 noclip clean
83132
run_sim $SPEECH_IN_8k_RAW 700E clip clean
84133

unittest/ota_voice_test.sh

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# cd ~ && git clone git@github.com:jks-prv/kiwiclient.git
99
# 3. Install Hamlib cli tools
1010

11+
set -x
1112
MY_PATH=`dirname $0`
1213
BUILD_PATH=`echo $MY_PATH/../build_*/src`
1314
PATH=${PATH}:${BUILD_PATH}:${HOME}/kiwiclient
@@ -25,24 +26,27 @@ serialPort="/dev/ttyUSB0"
2526
rxwavefile=0
2627
soundDevice="plughw:CARD=CODEC,DEV=0"
2728
txstats=0
29+
stationid=""
2830

2931
function print_help {
3032
echo
3133
echo "Automated Over The Air (OTA) voice test for FreeDV HF voice modes"
3234
echo
33-
echo " usage ./ota_voice_test.sh [options] SpeechFile [kiwi_url]"
35+
echo " usage ./ota_voice_test.sh [options] SpeechWaveFile [kiwi_url]"
3436
echo " or:"
3537
echo " usage ./ota_voice_test.sh -r rxWaveFile"
3638
echo
37-
echo " -c dev The sound device (in ALSA format on Linux, CoreAudio for macOS)"
38-
echo " -d debug mode; trace script execution"
39-
echo " -g SSB (analog) compressor gain"
39+
echo " -c dev The sound device (in ALSA format on Linux, CoreAudio for macOS)"
40+
echo " -d debug mode; trace script execution"
41+
echo " -g SSB (analog) compressor gain"
42+
echo " -i StationIDWaveFile Prepend this file to identify transmission (should be 8KHz mono)"
4043
echo " -m mode 700c|700d|700e"
41-
echo " -o model select radio model number ('rigctl -l' to list)"
42-
echo " -r Rx wave file mode: Rx process supplied rx wave file"
43-
echo " -s port The serial port (or hostname:port) to connect to for TX, default /dev/ttyUSB0"
44-
echo " -t Tx only, useful for manually observing SDRs"
45-
echo " -x Generate tx.wav file and exit"
44+
echo " -o model select radio model number ('rigctl -l' to list)"
45+
echo " -r Rx wave file mode: Rx process supplied rx wave file"
46+
echo " -s port The serial port (or hostname:port) to control SSB radio,"
47+
echo " default /dev/ttyUSB0"
48+
echo " -t Tx only, useful for manually observing SDRs"
49+
echo " -x Generate tx.wav file and exit"
4650
echo
4751
exit
4852
}
@@ -86,7 +90,7 @@ function process_rx {
8690
plot_specgram(s, 8000, 200, 3000); print('spec.jpg', '-djpg'); \
8791
quit" | octave-cli -p ${CODEC2}/octave -qf > /dev/null
8892
# attempt to decode
89-
freedv_rx ${mode} ${rx} - -v --highpassthroughgain 2>rx_stats.txt | sox -t .s16 -r 8000 -c 1 - rx_freedv.wav
93+
freedv_rx ${mode} ${rx} - -v --highpassthroughgain 2>rx_stats.txt | sox -t .s16 -r $speechFs -c 1 - rx_freedv.wav
9094
cat rx_stats.txt | tr -s ' ' | cut -f5 -d' ' | awk '$0==($0+0)' > sync.txt
9195
cat rx_stats.txt | tr -s ' ' | cut -f10 -d' ' | awk '$0==($0+0)' > snr.txt
9296
# time domain plot of output speech, SNR, and sync
@@ -120,6 +124,11 @@ case $key in
120124
shift
121125
shift
122126
;;
127+
-i)
128+
stationid="$2"
129+
shift
130+
shift
131+
;;
123132
-o)
124133
model="$2"
125134
shift
@@ -175,7 +184,7 @@ fi
175184

176185
speechfile="$1"
177186
if [ ! -f $speechfile ]; then
178-
echo "Can't find ${speechfile}!"
187+
echo "Can't find input speech wave file: ${speechfile}!"
179188
exit 1
180189
fi
181190

@@ -191,12 +200,30 @@ fi
191200
echo $mode
192201

193202
# create compressed analog
203+
speechfile_raw_8k=$(mktemp)
204+
comp_in=$(mktemp)
194205
speech_comp=$(mktemp)
195206
speech_freedv=$(mktemp)
196-
analog_compressor $speechfile $speech_comp $gain
207+
# If 16kHz input files for 2020x, we need an 8kHz version for SSB
208+
sox $speechfile -r 8000 -t .s16 -c 1 $speechfile_raw_8k
209+
if [ -z $stationid ]; then
210+
cp $speechfile_raw_8k $comp_in
211+
else
212+
# append station ID and apply analog compression
213+
stationid_raw_8k=$(mktemp)
214+
sox $stationid -r 8000 -t .s16 -c 1 $stationid_raw_8k
215+
cat $stationid_raw_8k $speechfile_raw_8k> $comp_in
216+
fi
217+
analog_compressor $comp_in $speech_comp $gain
218+
219+
# determine sample rate of input file we require for freedv_tx
220+
speechFs=8000
221+
if [ "$mode" == "2020" ] || [ "$mode" == "2020A" ] || [ "$mode$" == "2020B" ]; then
222+
speechFs=16000
223+
fi
197224

198225
# create modulated FreeDV, with compressor enabled
199-
freedv_tx $mode $speechfile $speech_freedv --clip 1
226+
sox $speechfile -t .s16 -r $speechFs - | freedv_tx $mode - $speech_freedv --clip 1
200227
cat $speech_comp $speech_freedv > tx.raw
201228
sox -t .s16 -r 8000 -c 1 tx.raw tx.wav
202229

0 commit comments

Comments
 (0)