⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sbiterr.m

📁 数字通信第四版原书的例程
💻 M
📖 第 1 页 / 共 2 页
字号:
                     'HorizontalA','Center',...
                     'VerticalA',  'Middle');
              % title for error number
              uicontrol(h_fig, 'Style', 'text', 'Units', 'norm',...
                        'Pos', [p_beg1, ((len_rate - ii) * 3 + 1 + 1)/totlin+.001, p_wid, 1/totlin-.002],...
                        'String','Error Number'); 
              % title for error rate
              uicontrol(h_fig, 'Style', 'text', 'Units', 'norm',...
                        'Pos', [p_beg1, ((len_rate - ii) * 3 + 1)/totlin+.001, p_wid, 1/totlin-.002],...
                        'String','Error Rate'); 
              h_tmp = text(p_beg, ((len_rate - ii) * 3 + 3/2 + 1)/totlin, 'Error Number');
              set(h_tmp, 'HorizontalA','Center',...
                     'FontSize', 9,...
                     'Color',[0 0 0],...
                     'VerticalA',  'Middle');
              h_tmp = text(p_beg, ((len_rate - ii) * 3 + 1/2 + 1)/totlin, 'Error Rate');
              set(h_tmp, 'HorizontalA','Center',...
                     'FontSize', 9,...
                     'Color',[0 0 0],...
                     'VerticalA',  'Middle');
            else
              %error number
              kk = (i-1)*2 + (length(u) * 2 - 1)*(ii - 1);
              set(h_plot, 'XData', [get(h_plot, 'XData') [p_beg1 p_beg1]-.001 NaN],...
                        'YData', [get(h_plot, 'YData') ((len_rate - ii)* 3 + 1)/totlin ((len_rate - ii)* 3 + 2 + 1)/totlin NaN]);

              h_sym_bit(kk) = text(p_beg, ((len_rate-ii)*3*2 + 3 + 2)/2/totlin, '0');
              set(h_sym_bit(kk), ...
                     'UserData', 0,...
                     'FontSize', 9,...
                     'Color',[0 0 0],...
                     'HorizontalA','Center',...
                     'VerticalA',  'Middle');
              %error rate

              h_sym_bit(kk+1) = text(p_beg, ((len_rate-ii)*3*2 +1 + 2)/2/totlin, '0');
              set(h_sym_bit(kk+1), ...
                     'UserData', 0,...
                     'FontSize', 9,...
                     'Color',[0 0 0],...
                     'HorizontalA','Center',...
                     'VerticalA',  'Middle');
            end;
          end;
        end;
        set(h_axes, 'Xlim',[0 1], 'Ylim',[0 1])
        current_point = 0;
        set(h_fig, 'UserData', [current_point, h_sym_bit, h_record]);
        set(h_fig,'NextPlot','new');
      end;
      x(1) = h_fig;

      tmp1 = uicontrol(h_fig,...
             'Style', 'pushbutton',...
             'Unit', 'norm',...
             'Position', [0 0 .5 1/totlin], ...
             'String', 'Reset error count',...
             'Callback',['sbiterrs(gcf,',num2str(len_rate),',',num2str(len_u),')']);

      tmp1 = uicontrol(h_fig,...
             'Style', 'pushbutton',...
             'Unit', 'norm',...
             'Position', [.5 0 .5 1/totlin], ...
             'String', 'Close',...
             'Callback','close(gcf)');
    elseif x(1) < 0
      %figure has been closed
      return;
    end;

    plot_flag_test = get(0,'child');
    if isempty(plot_flag_test)
      return;
    elseif isempty(find(plot_flag_test == x(1)))
      x(1) = -1;
      return;
    end;

    handles = get(x(1), 'UserData');
    h_fig =  x(1);
    current_point = handles(1);
    if K == 1
      h_sym_bit = handles(2 : length(u)*2);
      h_record = handles(length(u)*2+1 : length(handles));
      t_tras = get(h_sym_bit(1), 'UserData') + 1;
      set(h_sym_bit(1), 'UserData', t_tras, 'String', num2str(t_tras, 8));
    else
      h_sym_bit = handles(2 : length(u)*4-1);
      h_record = handles(length(u)*4 : length(handles));
      t_tras(1) = get(h_sym_bit(1), 'UserData') + 1;
      t_tras(2) = get(h_sym_bit(length(u)*2), 'UserData') + K;
      set(h_sym_bit(1), 'UserData', t_tras(1), 'String', num2str(t_tras(1),  8));
      set(h_sym_bit(length(u)*2), 'UserData', t_tras(2), 'String', num2str(t_tras(2), 8));
    end;
    if num_lin > 0
      if current_point == 0
        set(h_record(1), 'UserData', rem(get(h_record(1), 'UserData') + 1, 2));
      end;
      col = colormap(get(h_record(1), 'UserData') + 1, :);
    end;
    next_point = rem(current_point + 1, num_lin);
    last_point = rem(current_point-1+num_lin, num_lin);
    for i = 1 : length(u)
      if i == 1
        if num_lin > 0
          set(h_record(current_point * length(u) + i), 'String', num2str(x(3), 8), 'Color',col);
        end;
      else
        if num_lin > 0
          if u(i) == x(3)
            set(h_record(current_point * length(u) + i), 'String', num2str(u(i), 8), 'Color',col);
          else
            set(h_record(current_point * length(u) + i), 'String', ...
                   num2str(u(i), 8), 'Color',colormap(3,:));
          end
        end;
        if u(i) ~= x(3)
          % in case of error
          % number of errors
          num = get(h_sym_bit((i-1)*2), 'UserData') + 1;
          set(h_sym_bit((i-1)*2), 'UserData', num, 'String', num2str(num, 8));
          % errors rate
          set(h_sym_bit((i-1)*2+1), 'String', num2str(num/t_tras(1), 8));
          if K > 1
            % number
            kk = (i-1)*2 + (length(u) * 2 - 1);
            num = get(h_sym_bit(kk), 'UserData');
            erb = sum(de2bi(flxor(x(3), u(i))));
            erb = erb + num;
            set(h_sym_bit(kk), 'UserData', erb, 'String', num2str(erb, 8));
            % rate
            set(h_sym_bit(kk+1), 'String', num2str(erb/t_tras(2),8));
          end;
        else
          tmp = get(h_sym_bit((i-1)*2), 'UserData');
          if tmp 
             set(h_sym_bit((i-1)*2 + 1), 'String', ...
                 num2str(tmp / t_tras(1), 8));
          end;
          if K > 1
            kk = (i-1)*2 + (length(u) * 2 - 1);
            tmp = get(h_sym_bit(kk), 'UserData');
            if tmp 
               set(h_sym_bit(kk + 1), 'String', ...
                 num2str(tmp / t_tras(2), 8));
            end
          end;
        end;
      end;
    end
    current_point = next_point;
    sys = [h_fig; x(2:length(x))];
    set(h_fig, 'UserData', [current_point, h_sym_bit, h_record]);
    % second in User data is the current position for the line of h_record.
  end;

  if flag == 9
    sys = [];
  end;
elseif flag  == 0,      % Initialization

    % Keep number of states.
    num_state = max(0, ceil(TDelay/Sample(1))) + 1;

    if TDelay < 0
        error('Time delay cannot be negative.');
    end;

    if length(Sample) < 1
        error('Sample time cannot be empty.');
    elseif length(Sample) == 1
        Sample  = [Sample, 0];
    else
        Sample = Sample(:)';
        Sample = Sample(1:2);
    end;
    if rem(TDelay+Sample(2), Sample(1)) == 0
        Sample2 = [];
        STnum = 1;
    else
        Sample2 = [Sample(1), rem(TDelay+Sample(2), Sample(1))];
        STnum = 2;
    end;    

    ts = [Sample; Sample2];
    if Sample <= 0
        error('Sample time for error rate meter has to be larger than zero.')
    end;

   % Return system sizes
   sys(1) = 0;                     % 0 continuous states
   sys(2) = num_state+6;           % discrete states
   sys(3) = 0;                     % 0 outputs
   sys(4) = -1;                    % autowidth number of inputs
   sys(5) = 0;                     % 0 roots
   sys(6) = 0;                     % no direct feedthrough
   sys(7) = STnum;                 % 2 sample time
   if isempty(Sample2)
        Sample2 = Sample;
   end;
   x0 = [0; num_state;     % figure number. 0 indicates the first
   zeros(num_state, 1);
   STnum; Sample(1); 
   Sample(2); Sample2(2)]; % number of state.
elseif (flag == 4)
    posi_STnum = x(2) + 3;
    rel_err = abs(rem(t, x(posi_STnum + 1)) / x(posi_STnum + 1));
    if x(posi_STnum) == 1
        if (rel_err < .0000001) & (x(posi_STnum+2) > eps)
            sys = t + x(posi_STnum + 2);
        else
            sys = t + x(posi_STnum + 1);
        end;
    else
        if (rel_err < .0000001) & (max(x(posi_STnum+[2:3]) > eps))
            ind = find(x(posi_STnum+[2:3]) > 0);
            sys = t + max(x(posi_STnum+1+ind));
        elseif (abs(rel_err - x(posi_STnum + 2)/x(posi_STnum+1)) < .0000001) & (x(posi_STnum + 2) > eps)
            if x(posi_STnum+2) > x(posi_STnum+3)
                sys = ceil(t / x(posi_STnum+1)) * x(posi_STnum+1) + x(posi_STnum+3);
            elseif x(posi_STnum+2) < x(posi_STnum+3)
                sys = floor(t / x(posi_STnum+1)) * x(posi_STnum+1) + x(posi_STnum+3);
            else
                sys = t + x(posi_STnum+1);
            end;
        elseif (abs(rel_err - x(posi_STnum + 3)/x(posi_STnum+1)) < .0000001)& (x(posi_STnum + 2) > eps)
            if x(posi_STnum+3) > x(posi_STnum+2)
                sys = ceil(t / x(posi_STnum+1)) * x(posi_STnum+1) + x(posi_STnum+2);
            elseif x(posi_STnum+3) < x(posi_STnum+2)
                sys = floor(t / x(posi_STnum+1)) * x(posi_STnum+1) + x(posi_STnum+2);
            else
                sys = t + x(posi_STnum+1);
            end;
        else
            sys = t + x(posi_STnum+1);
        end;
    end
else
  % Other flag options not defined.
    sys = [];
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -