% plot_waveforms    - Plot 4 acquisition channels

function data = plot_waveforms(data, flag)

tit{1} = 'ADC0';
tit{2} = 'ADC1';

switch(data.sel)
  case 0
    tit{3} = 'ADC2';
    tit{4} = 'ADC3';
  case 1
    tit{3} = 'CAV_SUM';
    tit{4} = 'ERR';
  case 2
    tit{3} = 'ERR';
    tit{4} = 'KLY';
  case 3
    tit{3} = 'ERR';
    tit{4} = 'ADC3';
end

if (nargin == 1)
  for k=1:4
    data.title{k} = tit{k};
  end
end

clf
if isfield(data, 'iq')
  % After I/Q processing
  for k=1:3
    subplot(3, 2, 2*k-1);
    plot(data.t_iq, data.amp(:,k), 'linewidth', 2); grid;
    xlabel('Time (\mus)');
    ylabel(data.units{k});
    title(data.title{k});
    subplot(3, 2, 2*k);
    plot(data.t_iq, data.ph(:,k), 'r', 'linewidth', 2); grid;
    xlabel('Time (\mus)');
    ylabel('Degrees');
    title(data.title{k});
  end
else
  for k=1:4
    subplot(2, 2, k);
    plot(data.t, data.chan(:,k)); grid
    xlabel('Time (\mus)');
    ylabel('Counts');
    title(data.title{k});
  end
end
