From: drowe67 Date: Thu, 10 Sep 2009 04:11:10 +0000 (+0000) Subject: added plphase.m to explore zero phase model some more X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=925679f1e8d432f46600dbee0dfef78a9a392ba1;p=freetel-svn-tracking.git added plphase.m to explore zero phase model some more git-svn-id: https://svn.code.sf.net/p/freetel/code@53 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/codec2/TODO.txt b/codec2/TODO.txt index c8faad82..098a9278 100644 --- a/codec2/TODO.txt +++ b/codec2/TODO.txt @@ -1,6 +1,8 @@ TODO for codec2 --------------- +Planned tasks and half formed ideas for codec2..... + [X] Convert files from DOS to Unix [X] Get sinenc and sinedec to build and run under gcc [ ] refactor @@ -18,3 +20,19 @@ TODO for codec2 [ ] Go through papers referenced in thesis and credit various techniques to papers. + sure there was somthing about zero phase synthesis is those papers + +[ ] voicing errors can be clearly seen in synthesised speech using pl2.m + +[ ] Voicing improvement + + voicing tracker, if enery about the same in frame n-1,n,n+1, and n-1, n+1 + are voiced then make frame n voiced. + +[ ] mmt1 with zero phase model + + male with lots of background noise + + zero order synth model sounds more "clicky" on mmt1, this suggests less + dispersion + + could be due to IRS filtering or background noise + + exploring this could lead to better understanding on phase, e.g. add + noise to clean samples and explore effect on zero phase model + + wrote plphase.m to start analysing this + diff --git a/codec2/octave/plphase.m b/codec2/octave/plphase.m new file mode 100644 index 00000000..4af9577a --- /dev/null +++ b/codec2/octave/plphase.m @@ -0,0 +1,182 @@ +% Copyright David Rowe 2009 +% This program is distributed under the terms of the GNU General Public License +% Version 2 +% +% Plot phase modelling information from dump files. + +function plphase(samname, f) + + sn_name = strcat(samname,"_sn.txt"); + Sn = load(sn_name); + + sw_name = strcat(samname,"_sw.txt"); + Sw = load(sw_name); + + model_name = strcat(samname,"_model.txt"); + model = load(model_name); + + pw_name = strcat(samname,"_pw.txt"); + if (file_in_path(".",pw_name)) + Pw = load(pw_name); + endif + + ak_name = strcat(samname,"_ak.txt"); + if (file_in_path(".",ak_name)) + ak = load(ak_name); + endif + + phase_name = strcat(samname,"_phase.txt"); + if (file_in_path(".",phase_name)) + phase = load(phase_name); + endif + + phase_name_ = strcat(samname,"_phase_.txt"); + if (file_in_path(".",phase_name_)) + phase_ = load(phase_name_); + endif + + snr_name = strcat(samname,"_snr.txt"); + if (file_in_path(".",snr_name)) + snr = load(snr_name); + endif + + sn_name_ = strcat(samname,".raw"); + if (file_in_path(".",sn_name_)) + fs_ = fopen(sn_name_,"rb"); + sn_ = fread(fs_,Inf,"short"); + endif + + do + figure(1); + clg; + s = [ Sn(2*f-1,:) Sn(2*f,:) ]; + plot(s); + grid; + axis([1 length(s) -20000 20000]); + + figure(2); + Wo = model(f,1); + L = model(f,2); + Am = model(f,3:(L+2)); + plot((1:L)*Wo*4000/pi, 20*log10(Am),";Am;"); + axis([1 4000 -10 80]); + hold on; + plot((0:255)*4000/256, Sw(f,:),";Sw;"); + grid; + + if (file_in_path(".",pw_name)) + plot((0:255)*4000/256, 10*log10(Pw(f,:)),";Pw;"); + endif + + if (file_in_path(".",snr_name)) + snr_label = sprintf(";phase SNR %4.2f dB;",snr(f)); + plot(1,1,snr_label); + endif + + % phase model - determine SNR and error spectrum for phase model 1 + + if (file_in_path(".",phase_name_)) + orig = Am.*exp(j*phase(f,1:L)); + synth = Am.*exp(j*phase_(f,1:L)); + signal = orig * orig'; + noise = (orig-synth) * (orig-synth)'; + snr_phase = 10*log10(signal/noise); + + phase_err_label = sprintf(";phase_err SNR %4.2f dB;",snr_phase); + plot((1:L)*Wo*4000/pi, 20*log10(orig-synth), phase_err_label); + hold off; + endif + + if (file_in_path(".",phase_name)) + figure(3); + plot((1:L)*Wo*4000/pi, phase(f,1:L)*180/pi, "-o;phase;"); + axis; + if (file_in_path(".", phase_name_)) + hold on; + plot((1:L)*Wo*4000/pi, phase_(f,1:L)*180/pi, ";phase_;"); + grid + hold off; + endif + endif + + % synthesised speech + + if (file_in_path(".",sn_name_)) + figure(4); + s_ = sn_((f-3)*80+1:(f+1)*80); + plot(s_); + axis([1 length(s_) -20000 20000]); + endif + + if (file_in_path(".",ak_name)) + figure(5); + axis; + akw = ak(f,:); + weight = 1.0 .^ (0:length(akw)-1); + akw = akw .* weight; + H = 1./fft(akw,8000); + subplot(211); + plot(20*log10(abs(H(1:4000))),";LPC mag spec;"); + grid; + subplot(212); + plot(angle(H(1:4000))*180/pi,";LPC phase spec;"); + grid; + endif + + hold off; + + % autocorrelation function to research voicing est + + %M = length(s); + %sw = s .* hanning(M)'; + %for k=0:159 + % R(k+1) = sw(1:320-k) * sw(1+k:320)'; + %endfor + %figure(4); + %R_label = sprintf(";R(k) %3.2f;",max(R(20:159))/R(1)); + %plot(R/R(1),R_label); + %grid + + figure(2); + + % interactive menu + + printf("\rframe: %d menu: n-next b-back p-png q-quit ", f); + fflush(stdout); + k = kbhit(); + if (k == 'n') + f = f + 1; + endif + if (k == 'b') + f = f - 1; + endif + + % optional print to PNG + + if (k == 'p') + + pngname = sprintf("%s_%d",samname,f); + + % small image + + __gnuplot_set__ terminal png size 420,300 + ss = sprintf("__gnuplot_set__ output \"%s.png\"", pngname); + eval(ss) + replot; + + % larger image + + __gnuplot_set__ terminal png size 800,600 + ss = sprintf("__gnuplot_set__ output \"%s_large.png\"", pngname); + eval(ss) + replot; + + % for some reason I need this to stop large plot getting wiped + __gnuplot_set__ output "/dev/null" + + endif + + until (k == 'q') + printf("\n"); + +endfunction diff --git a/codec2/src/dump.c b/codec2/src/dump.c index c52d574b..9e5ad14c 100644 --- a/codec2/src/dump.c +++ b/codec2/src/dump.c @@ -46,6 +46,7 @@ static FILE *fe = NULL; static FILE *fsq = NULL; static FILE *fdec = NULL; static FILE *fsnr = NULL; +static FILE *fak = NULL; static char prefix[MAX_STR]; @@ -83,6 +84,8 @@ void dump_off(){ fclose(fdec); if (fsnr != NULL) fclose(fsnr); + if (fak != NULL) + fclose(fak); } void dump_Sn(float Sn[]) { @@ -231,7 +234,7 @@ void dump_snr(float snr) { if (!dumpon) return; - if (fphase_ == NULL) { + if (fsnr == NULL) { sprintf(s,"%s_snr.txt", prefix); fsnr = fopen(s, "wt"); assert(fsnr != NULL); @@ -274,6 +277,23 @@ void dump_lsp(float lsp[]) { fprintf(flsp,"\n"); } +void dump_ak(float ak[], int order) { + int i; + char s[MAX_STR]; + + if (!dumpon) return; + + if (fak == NULL) { + sprintf(s,"%s_ak.txt", prefix); + fak = fopen(s, "wt"); + assert(fak != NULL); + } + + for(i=0; i<=order; i++) + fprintf(fak,"%f\t",ak[i]); + fprintf(fak,"\n"); +} + void dump_Fw(COMP Fw[]) { int i; char s[MAX_STR]; diff --git a/codec2/src/dump.h b/codec2/src/dump.h index 2d3bbc25..59ccb348 100644 --- a/codec2/src/dump.h +++ b/codec2/src/dump.h @@ -38,6 +38,7 @@ void dump_model(MODEL *m); void dump_quantised_model(MODEL *m); void dump_Pw(COMP Pw[]); void dump_lsp(float lsp[]); +void dump_ak(float ak[], int order); /* phase modelling */ diff --git a/codec2/src/phase.c b/codec2/src/phase.c index ffb132af..f455fd1e 100644 --- a/codec2/src/phase.c +++ b/codec2/src/phase.c @@ -32,8 +32,8 @@ #include #include -#define VTHRESH1 3.0 -#define VTHRESH2 3.0 +#define VTHRESH1 2.0 +#define VTHRESH2 2.0 /*---------------------------------------------------------------------------*\ @@ -133,7 +133,7 @@ float phase_model_first_order( ) { float G; /* LPC gain */ - int i,m; + int m; float E,Emin; /* current and minimum error so far */ int P; /* current pitch period */ @@ -162,8 +162,8 @@ float phase_model_first_order( #ifdef NO_LPC_PHASE /* useful for testing with Sn[] an impulse train */ - for(i=1; i<=PHASE_LPC_ORD; i++) - aks[i] = 0; + for(m=1; m<=PHASE_LPC_ORD; m++) + aks[m] = 0; #endif G = 1.0; aks_to_H(&model,aks,G,H,PHASE_LPC_ORD); diff --git a/codec2/src/sinedec.c b/codec2/src/sinedec.c index 9d72a274..d2dee22f 100644 --- a/codec2/src/sinedec.c +++ b/codec2/src/sinedec.c @@ -217,7 +217,9 @@ int main(int argc, char *argv[]) else assert(order == PHASE_LPC_ORD); + dump_ak(ak, PHASE_LPC_ORD); snr = phase_model_first_order(ak, H, &n_min, &min_Am); + dump_snr(snr); if (phase_model == 0) { phase_synth_zero_order(snr, H, &prev_Wo, &ex_phase);