From 4f8c7ea4fb7758bbb0c06dfc3ba6b27fabdad1c5 Mon Sep 17 00:00:00 2001 From: David Date: Wed, 4 Dec 2019 14:26:24 +1030 Subject: [PATCH] added some tests for est_n0, working OK for basic impulse case --- phasenn_test11.py | 4 ++-- plot_n0.py | 9 ++++++--- run_n0_est.sh | 18 ++++++++++++++++++ test_n0_est.sh | 15 +++++++++++++++ 4 files changed, 41 insertions(+), 5 deletions(-) create mode 100755 run_n0_est.sh create mode 100755 test_n0_est.sh diff --git a/phasenn_test11.py b/phasenn_test11.py index b7e36c6..f5c214e 100755 --- a/phasenn_test11.py +++ b/phasenn_test11.py @@ -102,9 +102,9 @@ for i in range(nb_samples): alpha2 = alpha1 + 0.4*np.pi*r2[0] gamma2 = 0.9 + 0.05*r2[1] else: - alpha1 = 0.5*np.pi + 0.9*np.pi*r1[0] + alpha1 = 0.5*np.pi + 0.4*np.pi*r1[0] gamma1 = 0.8 + 0.1*r1[1] - alpha2 = 0.5*np.pi + 0.9*np.pi*r2[0] + alpha2 = 0.5*np.pi + 0.4*np.pi*r2[0] gamma2 = 0.8 + 0.1*r2[1] w1,h1 = signal.freqz(1, [1, -2*gamma1*np.cos(alpha1), gamma1*gamma1], range(1,L[i]+1)*Wo[i]) diff --git a/plot_n0.py b/plot_n0.py index deb5f7e..d5267ca 100755 --- a/plot_n0.py +++ b/plot_n0.py @@ -36,7 +36,9 @@ nb_samples = Wo.size; amp = 20.0*np.log10(A+1E-6) # read in n0 estimates n0_est = np.loadtxt(sys.argv[2]) + print(n0_est[:20]) +print(Wo[:20]) print("removing linear phase component....") phase_n0_removed = np.zeros((nb_samples, width)) for i in range(nb_samples): @@ -58,7 +60,7 @@ def sample_time(r): s = np.zeros(2*N); for m in range(1,L[r]+1): - s = s + A[r,m]*np.cos(m*Wo[r]*range(2*N) + phase[r,m]) + s = s + A[r,m]*np.cos(m*Wo[r]*range(-N,N) + phase[r,m]) return s plot_en = 1; @@ -89,9 +91,10 @@ if plot_en: plt.subplot(3,4,r+1) f = frame[r]; s = sample_time(f) - plt.plot(s,'g') + plt.plot(range(-N,N),s,'g') mx = np.max(np.abs(s)) - plt.plot([n0_est[f],n0_est[f]], [-mx/2,mx/2],'b') + print(r,f,n0_est[f]) + plt.plot([-n0_est[f],-n0_est[f]], [-mx/2,mx/2],'b') plt.show(block=False) # click on last figure to close all and finish diff --git a/run_n0_est.sh b/run_n0_est.sh new file mode 100755 index 0000000..70ac9d3 --- /dev/null +++ b/run_n0_est.sh @@ -0,0 +1,18 @@ +#!/bin/bash -x +# David Dec 2019 +# + +PATH=$PATH:~/codec2/build_linux/src:~/codec2/build_linux/misc + +if [ "$#" -ne 1 ]; then + echo "usage: ./run_n0_est.sh rawFile" +fi +speech=$1 +x=$(basename $speech) +base="${x%.*}" + +c2sim $speech --modelout $base'.model' +cat $base.model | est_n0 > $base'_n0.txt' +./plot_n0.py $base'.model' $base'_n0.txt' + + diff --git a/test_n0_est.sh b/test_n0_est.sh new file mode 100755 index 0000000..b8e17cf --- /dev/null +++ b/test_n0_est.sh @@ -0,0 +1,15 @@ +#!/bin/bash -x +# David Dec 2019 +# + +PATH=$PATH:~/codec2/build_linux/src:~/codec2/build_linux/misc + +if [ "$#" -ne 1 ]; then + n0=1 +else + n0=$1 +fi +timpulse 190 $n0 | c2sim - --modelout imp.model +cat imp.model | est_n0 > imp_n0.txt +./plot_n0.py imp.model imp_n0.txt +