1818% cd codec2/build_linux
1919% ../script/train_trellis.sh
2020%
21+ % Results so far (August 2021):
22+ %
23+ % 1/ 2dB improvement with nstages=3, dec=1
24+ % 2/ No useful improvement with nstages=3, dec=4. This is required for a practical codec to
25+ % get a useful bit rate.
2126
22271 ;
2328
372377 mse_vanilla = mean(diff_vanilla(: ).^2 );
373378 diff = target - target_ ;
374379 mse = mean(diff(: ).^2 );
375- printf(" Eb/No: %3.2f dB nframes: %2d nerrors %d %d BER: %4.3f %4.3f PER: %3.2f %3.2f mse: %3.2f %3.2f %3.2f\n" ,
380+ printf(" Eb/No: %3.2f dB nframes: %2d nerrors %3d %3d BER: %4.3f %4.3f PER: %3.2f %3.2f mse: %3.2f %3.2f %3.2f\n" ,
376381 EbNodB , nframes , nerrors , nerrors_vanilla , nerrors / tbits , nerrors_vanilla / tbits ,
377382 nper / nframes , nper_vanilla / nframes ,
378383 mse_noerrors , mse , mse_vanilla );
391396% Simulations ---------------------------------------------------------------------
392397
393398% top level function to set up and run a test
394- function results = test_trellis(nframes = 100 , ntxcw= 8 , nstages= 3 , EbNodB= 3 , verbose= 0 )
399+ function results = test_trellis(nframes = 100 , dec = 1 , ntxcw= 8 , nstages= 3 , EbNodB= 3 , verbose= 0 )
395400 K = 20 ; K_st= 2 + 1 ; K_en= 16 + 1 ;
396401 vq_fn = " ../build_linux/vq_stage1.f32" ;
397402 vq_output_fn = " ../build_linux/all_speech_8k_test.f32" ;
403408 vq = vq(: ,K_st : K_en );
404409
405410 % load file of VQ-ed vectors to train up SD PDF estimator
406- [sd_table h_table ] = vq_hist(vq_output_fn , dec= 1 );
411+ [sd_table h_table ] = vq_hist(vq_output_fn , dec );
407412
408413 % load sequence of target vectors we wish to VQ
409414 target = load_f32(target_fn , K );
410415
411416 % limit test to the first nframes vectors
412- target = target(1 : nframes ,K_st : K_en );
417+ target = target(1 : dec : dec * nframes ,K_st : K_en );
413418
414419 % run a test
415420 EbNo= 10 ^(EbNodB / 10 );
@@ -499,6 +504,38 @@ function test_vq(vq_fn)
499504 printf(" EbNo: %4.2f dB tbits: %d errs: %d BER: %4.3f %4.3f\n" , EbNodB , tbits , nerrors , nerrors / tbits , 0.5 * erfc(sqrt(EbNo )));
500505endfunction
501506
507+ % generate sets of curves
508+ function run_curves(frames = 100 , dec= 1 )
509+ results_log = [];
510+ EbNodB = [1 2 3 4 ];
511+ for i= 1 : length(EbNodB )
512+ results = test_trellis(frames , dec , ntxcw= 8 , nstages= 3 , EbNodB(i ), verbose= 0 );
513+ results_log = [results_log results ];
514+ end
515+ for i= 1 : length(results_log )
516+ ber(i ) = results_log(i ).ber;
517+ ber_vanilla(i ) = results_log(i ).ber_vanilla;
518+ per(i ) = results_log(i ).per;
519+ per_vanilla(i ) = results_log(i ).per_vanilla;
520+ mse_noerrors(i ) = sqrt(results_log(i ).mse_noerrors);
521+ mse(i ) = sqrt(results_log(i ).mse);
522+ mse_vanilla(i ) = sqrt(results_log(i ).mse_vanilla);
523+ end
524+
525+ figure(1 ); clf ; semilogy(EbNodB , ber_vanilla , " r+-;uncoded;" ); hold on ;
526+ semilogy(EbNodB , ber , " g+-;trellis;" ); hold off ;
527+ grid ; title(sprintf(" BER dec=%d nstages=%d" ,dec ,nstages ));
528+
529+ figure(2 ); clf ; semilogy(EbNodB , per_vanilla , " r+-;uncoded;" ); hold on ;
530+ semilogy(EbNodB , per , " g+-;trellis;" );
531+ grid ; title(sprintf(" PER dec=%d nstages=%d" ,dec ,nstages ));
532+
533+ figure(3 ); clf ; plot(EbNodB , mse_noerrors , " b+-;no errors;" ); hold on ;
534+ plot(EbNodB , mse_vanilla , " r+-;uncoded;" );
535+ plot(EbNodB , mse , " g+-;trellis;" ); hold off ;
536+ grid ; title(sprintf(" RMS SD dec=%d nstages=%d" ,dec ,nstages ));
537+ endfunction
538+
502539% -------------------------------------------------------------------
503540
504541graphics_toolkit (" gnuplot" );
@@ -507,10 +544,15 @@ function test_vq(vq_fn)
507544
508545% uncomment one of the below to run a test or simulation
509546
510- % test_bpsk_ber
547+ % These two tests show where we are at:
548+ test_trellis(nframes = 600 , dec= 1 , ntxcw= 8 , nstages= 3 , EbNodB= 3 , verbose= 0 );
549+ test_trellis(nframes = 600 , dec= 4 , ntxcw= 8 , nstages= 3 , EbNodB= 3 , verbose= 0 );
511550
512- test_trellis( nframes = 100 , ntxcw = 8 , nstages = 3 , EbNodB = 3 , verbose = 0 );
551+ % run_curves(600,4)
513552
553+ % test_trellis(nframes=200, dec=1, ntxcw=1, nstages=3, EbNodB=3, verbose=0);
554+ % test_trellis(nframes=100, dec=2, ntxcw=8, nstages=3, EbNodB=3, verbose=0);
514555% test_vq("../build_linux/vq_stage1.f32");
515556% vq_hist_dec("../build_linux/all_speech_8k_test.f32");
516557% test_single
558+ % test_bpsk_ber
0 commit comments