Skip to content

Commit

Permalink
agc and hilbert compression
Browse files Browse the repository at this point in the history
  • Loading branch information
drowe67 committed Dec 13, 2024
1 parent 67a669f commit eb887d1
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions asr_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,26 @@ function print_help {
echo "Automated Speech Recognition (ASR) dataset processing for Radio Autoencoder testing"
echo
echo " usage ./asr_test.sh path/to/source dest [test option below]"
echo " usage ./ota_test.sh ~/.cache/LibriSpeech/test-clean ~/.cache/LibriSpeech/test-awgn-2dB --awgn 2"
echo " usage ./ota_test.sh ~/.cache/LibriSpeech/test-clean ~/.cache/LibriSpeech/test-awgn-2dB --No -30"
echo
echo " --awgn SNRdB AWGN channel simulation"
echo " --No NodB ch channel simulation No value (experiment to get desired SNR)"
echo " -n numSamples number of dataset samples to process (default all)"
echo " -d verbose debug information"
exit
}

n_samples=0
No=-100
setpoint_rms=2048
comp_gain=6

POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
--awgn)
awgn_snr_dB="$2"
--No)
No="$2"
shift
shift
;;
Expand Down Expand Up @@ -63,6 +66,7 @@ fi

source=$1
dest=$2
rm -Rf $dest

# cp translation files to new dataset directory
function cp_translation_files {
Expand All @@ -85,14 +89,34 @@ function process {
n=$(echo "$flac" | wc -l)
printf "Processing %d samples in dataset\n" $n

in=t.raw
comp=comp.raw
ch_log=ch_log.txt
snr_log=snr_log.txt
rm -f ${snr_log}
for f in $flac
do
d=$(dirname $f)
mkdir -p ${dest}/${d}
sox ${source}/${f} -t .s16 -r 8000 - | ch - - --No -30 | sox -t .s16 -r 8000 -c 1 - -r 16000 ${dest}/${f}
sox ${source}/${f} -t .s16 -r 8000 ${in}
# AGC and Hilbert compression
set_rms ${in} $setpoint_rms
analog_compressor ${in} ${comp} ${comp_gain}
papr=$(measure_cpapr ${comp})
ch ${comp} - --No ${No} 2>${ch_log} | sox -t .s16 -r 8000 -c 1 - -r 16000 ${dest}/${f}
snr=$(cat $ch_log | grep "SNR3k" | tr -s ' ' | cut -d' ' -f3)
snr=$(cat $ch_log | grep "SNR3k" | tr -s ' ' | cut -d' ' -f3)
echo $snr >> ${snr_log}
echo ${dest}/${f} ${snr} ${papr}
done
python3 <<EOF
import numpy as np
s=np.loadtxt("snr_log.txt")
print(f"mean SNR: {np.mean(s):5.2f}")
EOF

}

#cp_translation_files
cp_translation_files
process

0 comments on commit eb887d1

Please sign in to comment.