2
0

pllpcpf.m 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. % Copyright David Rowe 2012
  2. % This program is distributed under the terms of the GNU General Public License
  3. % Version 2
  4. %
  5. % Plot amplitude modelling information from dump files to test and develop
  6. % LPC post filter.
  7. function pllpcpf(samname, f)
  8. % switch some stuff off to unclutter display
  9. plot_Am = 0;
  10. plot_Amq = 0;
  11. plot_err = 0;
  12. plot_lsp = 0;
  13. plot_snr = 0;
  14. plot_vsnr = 0;
  15. plot_sw = 0;
  16. plot_pw = 1;
  17. plot_pwb = 1;
  18. plot_rw = 1;
  19. sn_name = strcat(samname,"_sn.txt");
  20. Sn = load(sn_name);
  21. sw_name = strcat(samname,"_sw.txt");
  22. Sw = load(sw_name);
  23. sw__name = strcat(samname,"_sw_.txt");
  24. if (file_in_path(".",sw__name))
  25. Sw_ = load(sw__name);
  26. endif
  27. model_name = strcat(samname,"_model.txt");
  28. model = load(model_name);
  29. modelq_name = strcat(samname,"_qmodel.txt");
  30. if (file_in_path(".",modelq_name))
  31. modelq = load(modelq_name);
  32. endif
  33. % Pw (LPC synth filter spectrum) before post filter
  34. pwb_name = strcat(samname,"_pwb.txt");
  35. if (file_in_path(".",pwb_name))
  36. Pwb = load(pwb_name);
  37. endif
  38. % Rw (Post filter spectrum)
  39. rw_name = strcat(samname,"_rw.txt");
  40. if (file_in_path(".",rw_name))
  41. Rw = load(rw_name);
  42. endif
  43. % Pw (LPC synth filter spectrum) after post filter
  44. pw_name = strcat(samname,"_pw.txt");
  45. if (file_in_path(".",pw_name))
  46. Pw = load(pw_name);
  47. endif
  48. Ew_on = 1;
  49. k = ' ';
  50. do
  51. figure(1);
  52. clf;
  53. s = [ Sn(2*f-1,:) Sn(2*f,:) ];
  54. size(s);
  55. plot(s);
  56. axis([1 length(s) -20000 20000]);
  57. figure(2);
  58. clf;
  59. Wo = model(f,1);
  60. L = model(f,2);
  61. Am = model(f,3:(L+2));
  62. if plot_Am
  63. plot((1:L)*Wo*4000/pi, 20*log10(Am),";Am;r");
  64. end
  65. axis([1 4000 -10 80]);
  66. hold on;
  67. if plot_sw
  68. plot((0:255)*4000/256, Sw(f,:),";Sw;");
  69. end
  70. if (file_in_path(".",modelq_name))
  71. Amq = modelq(f,3:(L+2));
  72. if plot_Amq
  73. plot((1:L)*Wo*4000/pi, 20*log10(Amq),";Amq;g" );
  74. end
  75. if (file_in_path(".",pwb_name) && plot_pwb)
  76. plot((0:255)*4000/256, 10*log10(Pwb(f,:)),";Pwb;r");
  77. endif
  78. if (file_in_path(".",rw_name) && plot_rw)
  79. plot((0:255)*4000/256, 10*log10(Rw(f,:)),";Rw;b");
  80. endif
  81. if (file_in_path(".",pw_name) && plot_pw)
  82. plot((0:255)*4000/256, 10*log10(Pw(f,:)),";Pw;g.");
  83. endif
  84. signal = Am * Am';
  85. noise = (Am-Amq) * (Am-Amq)';
  86. snr1 = 10*log10(signal/noise);
  87. Am_err_label = sprintf(";Am error SNR %4.2f dB;m",snr1);
  88. if plot_err
  89. plot((1:L)*Wo*4000/pi, 20*log10(Amq) - 20*log10(Am), Am_err_label);
  90. end
  91. endif
  92. hold off;
  93. % interactive menu
  94. printf("\rframe: %d menu: n-next b-back p-png q-quit", f);
  95. fflush(stdout);
  96. k = kbhit();
  97. if (k == 'n')
  98. f = f + 1;
  99. endif
  100. if (k == 'b')
  101. f = f - 1;
  102. endif
  103. % optional print to PNG
  104. if (k == 'p')
  105. figure(1);
  106. pngname = sprintf("%s_%d_sn.png",samname,f);
  107. print(pngname, '-dpng', "-S500,500")
  108. pngname = sprintf("%s_%d_sn_large.png",samname,f);
  109. print(pngname, '-dpng', "-S800,600")
  110. figure(2);
  111. pngname = sprintf("%s_%d_sw.png",samname,f);
  112. print(pngname, '-dpng', "-S500,500")
  113. pngname = sprintf("%s_%d_sw_large.png",samname,f);
  114. print(pngname, '-dpng', "-S1200,800")
  115. endif
  116. until (k == 'q')
  117. printf("\n");
  118. endfunction