397397% Simulations ---------------------------------------------------------------------
398398
399399% top level function to set up and run a test
400- function results = test_trellis(nframes = 100 , dec= 1 , ntxcw= 8 , nstages= 3 , EbNodB= 3 , verbose= 0 )
400+ function [ results target_ ] = test_trellis(target_fn , nframes= 100 , dec= 1 , ntxcw= 8 , nstages= 3 , EbNodB= 3 , verbose= 0 )
401401 K = 20 ; K_st= 2 + 1 ; K_en= 16 + 1 ;
402402 vq_fn = " ../build_linux/vq_stage1_bs004.f32" ;
403403 vq_output_fn = " ../build_linux/all_speech_8k_test.f32" ;
404- target_fn = " ../build_linux/all_speech_8k_lim.f32" ;
405404
406405 % load VQ
407406 vq = load_f32(vq_fn , K );
408407 [vq_size tmp ] = size(vq );
409- vq = vq(: ,K_st : K_en );
408+ vqsub = vq(: ,K_st : K_en );
410409
411410 % load file of VQ-ed vectors to train up SD PDF estimator
412411 [sd_table h_table ] = vq_hist(vq_output_fn , dec );
415414 target = load_f32(target_fn , K );
416415
417416 % limit test to the first nframes vectors
418- target = target(1 : dec : dec * nframes ,K_st : K_en );
417+ if nframes != - 1
418+ last = nframes ;
419+ else
420+ last = length(target );
421+ end
422+ target = target(1 : dec : last ,K_st : K_en );
419423
420424 % run a test
421425 EbNo= 10 ^(EbNodB / 10 );
422- results = run_test(target , vq , sd_table , h_table , ntxcw , nstages , EbNo , verbose );
426+ results = run_test(target , vqsub , sd_table , h_table , ntxcw , nstages , EbNo , verbose );
423427 if verbose
424428 for f= 2 : nframes - 1
425429 printf(" f: %03d tx_index: %04d rx_index: %04d\n" , f , results .tx_indexes(f ), results .rx_indexes(f ));
426430 end
427- end
431+ end
432+
433+ % return full band vq-ed vectors
434+ target_ = zeros(last ,K );
435+ target_(1 : dec : last ,: ) = vq(results .rx_indexes + 1 ,: );
436+
437+ % use linear interpolation to restore original frame rate
438+ for f= 1 : dec : last - dec
439+ prev = f ; next = f + dec ;
440+ for g= prev + 1 : next - 1
441+ cnext = (g - prev )/dec ; cprev = 1 - cnext ;
442+ target_(g ,: ) = cprev * target_(prev ,: ) + cnext * target_(next ,: );
443+ % printf("f: %d g: %d cprev: %f cnext: %f\n", f, g, cprev, cnext);
444+ end
445+ end
428446endfunction
429447
430448% Plot histograms of SD at different decimations in time
@@ -514,8 +532,10 @@ function test_vq(vq_fn)
514532function [EbNodB rms_sd ] = run_curves(frames = 100 , dec= 1 , nstages= 5 )
515533 results_log = [];
516534 EbNodB = [0 1 2 3 4 5 ];
535+ target_fn = " ../build_linux/all_speech_8k_lim.f32" ;
536+
517537 for i= 1 : length(EbNodB )
518- results = test_trellis(frames , dec , ntxcw= 8 , nstages , EbNodB(i ), verbose= 0 );
538+ results = test_trellis(target_fn , frames , dec , ntxcw= 8 , nstages , EbNodB(i ), verbose= 0 );
519539 results_log = [results_log results ];
520540 end
521541 for i= 1 : length(results_log )
@@ -545,6 +565,11 @@ function test_vq(vq_fn)
545565 print(" -dpng" , sprintf(" trellis_dec_%d_rms_sd.png" ,dec ));
546566endfunction
547567
568+ function vq_file(vq_fn , dec , EbNodB , in_fn , out_fn )
569+ [results target_ ] = test_trellis(in_fn , nframes= -1 , dec , ntxcw= 8 , nstages= 3 , EbNodB , verbose= 0 );
570+ save_f32(out_fn , target_ );
571+ endfunction
572+
548573% -------------------------------------------------------------------
549574
550575more off ;
@@ -553,16 +578,16 @@ function test_vq(vq_fn)
553578% uncomment one of the below to run a test or simulation
554579
555580% These two tests show where we are at:
556- % test_trellis(nframes=600, dec=1, ntxcw=8, nstages=3, EbNodB=3, verbose=0);
557- % test_trellis(nframes=600, dec=4, ntxcw=8, nstages=3, EbNodB=3, verbose=0);
581+ % test_trellis(target_fn, nframes=600, dec=1, ntxcw=8, nstages=3, EbNodB=3, verbose=0);
582+ % test_trellis(target_fn, nframes=600, dec=4, ntxcw=8, nstages=3, EbNodB=3, verbose=0);
558583
559584% run_curves(600,1)
560585% run_curves(600,2)
561586% run_curves(600,4)
562- [EbNodB rms_sd ] = run_curves(30 * 100 ,3 ,3 )
587+ % [EbNodB rms_sd] = run_curves(30*100,3,3)
563588
564- % test_trellis(nframes=200, dec=1, ntxcw=1, nstages=3, EbNodB=3, verbose=0);
565- % test_trellis(nframes=100, dec=2, ntxcw=8, nstages=3, EbNodB=3, verbose=0);
589+ % test_trellis(target_fn, nframes=200, dec=1, ntxcw=1, nstages=3, EbNodB=3, verbose=0);
590+ % test_trellis(target_fn, nframes=100, dec=2, ntxcw=8, nstages=3, EbNodB=3, verbose=0);
566591% test_vq("../build_linux/vq_stage1.f32");
567592% vq_hist_dec("../build_linux/all_speech_8k_test.f32");
568593% test_single
0 commit comments