1% Copyright David Rowe 2009
2% This program is distributed under the terms of the GNU General Public License
3% Version 2
4%
5% Plot NLP states from dump files.
6
7function plnlp(samname, f)
8
9  sn_name = strcat(samname,"_sn.txt");
10  Sn = load(sn_name);
11
12  sw_name = strcat(samname,"_sw.txt");
13  Sw = load(sw_name);
14
15  fw_name = strcat(samname,"_fw.txt");
16  if (file_in_path(".",fw_name))
17    fw = load(fw_name);
18  endif
19
20  e_name = strcat(samname,"_e.txt");
21  if (file_in_path(".",e_name))
22    e = load(e_name);
23  endif
24
25  p_name = strcat(samname,".p");
26  if (file_in_path(".",p_name))
27    p = load(p_name);
28  endif
29
30  sq_name = strcat(samname,"_sq.txt");
31  if (file_in_path(".",sq_name))
32    sq = load(sq_name);
33  endif
34
35  dec_name = strcat(samname,"_dec.txt");
36  if (file_in_path(".",dec_name))
37    dec = load(dec_name);
38  endif
39
40  do
41    figure(1);
42    clf;
43    s = [ Sn(2*f-1,:) Sn(2*f,:) ];
44    plot(s, ";Sn;");
45    grid
46    axis([1 length(s) -20000 20000]);
47
48    figure(2);
49    plot((0:255)*4000/256, Sw(f,:),";Sw;");
50    grid
51    axis([1 4000 -10 80]);
52    hold on;
53
54    f0 = 8000/p(f);
55    Wo = 2*pi/p(f);
56    L = floor(pi/Wo);
57    f0_label = sprintf("b;P=%3.1f F0=%3.0f;",p(f),f0);
58    for m=1:L-1
59      plot([ m*Wo*4000/pi m*Wo*4000/pi], [10 60], 'b');
60    endfor
61    plot([ L*Wo*4000/pi L*Wo*4000/pi], [10 60], f0_label);
62
63    hold off;
64
65    if (file_in_path(".",fw_name))
66      figure(3);
67      if (file_in_path(".",e_name))
68         subplot(211);
69      endif
70      plot((0:255)*800/256, fw(f,:)/max(fw(f,:)), ";Fw;");
71      axis([1 400 0 1]);
72      if (file_in_path(".",e_name))
73        subplot(212);
74        e_concat = [ e(2*f-1,:) e(2*f,:) ];
75        plot(e_concat(1:400)/max(e_concat(1:400)), "+;MBE E(f);");
76        axis([1 400 0 1]);
77      endif
78    endif
79
80    if (file_in_path(".",sq_name))
81      figure(4);
82      sq_concat = [ sq(2*f-1,:) sq(2*f,:) ];
83      axis
84      plot(sq_concat, ";sq;");
85    endif
86
87    if (file_in_path(".",dec_name))
88      figure(5);
89      plot(dec(f,:), ";dec;");
90    endif
91
92    figure(2);
93
94    % interactive menu
95
96    printf("\rframe: %d  menu: n-next  b-back  p-png  q-quit ", f);
97    fflush(stdout);
98    k = kbhit();
99    if (k == 'n')
100      f = f + 1;
101    endif
102    if (k == 'b')
103      f = f - 1;
104    endif
105
106    % optional print to PNG
107
108    if (k == 'p')
109
110      pngname = sprintf("%s_%d",samname,f);
111
112      % small image
113
114      __gnuplot_set__ terminal png size 420,300
115      ss = sprintf("__gnuplot_set__ output \"%s.png\"", pngname);
116      eval(ss)
117      replot;
118
119      % larger image
120
121      __gnuplot_set__ terminal png size 800,600
122      ss = sprintf("__gnuplot_set__ output \"%s_large.png\"", pngname);
123      eval(ss)
124      replot;
125
126      % for some reason I need this to stop large plot getting wiped
127      __gnuplot_set__ output "/dev/null"
128
129    endif
130
131  until (k == 'q')
132  printf("\n");
133
134endfunction
135