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

📄 eyediasi.m

📁 数字通信第四版原书的例程
💻 M
📖 第 1 页 / 共 2 页
字号:
        else
          set(scatter_plot,'Xlim',[-1, 1],...
                           'Ylim',[boundary(1), boundary(2)]);
        end;
        set(scatter_plot,'UserData',[ax, abs(scatter_line)]);
      end;
      if two_d_plot
        two_d_plot = plt(i);
        % This case, length(u) must be 3
        set(x(1),'CurrentAxes',two_d_plot);
        set(two_d_plot,'Xlim',[boundary(1), boundary(2)], ...
                       'Ylim',[boundary(1), boundary(2)]);
        [col, lines] = strtok(two_d_line, '/');
        if length(col) <= 1
          col = 'w-';
        end;
        ax = plot(0,0,col,...
             'Erasemode','none',...
             'Color',col(1),'LineStyle',col(2:length(col)));
        set(two_d_plot,'Xlim',[boundary(1), boundary(2)], ...
             'Ylim',[boundary(1), boundary(2)]);
        set(ax, 'XData', [], 'YData', []);
        set(two_d_plot,'UserData',[ax, 0 abs(two_d_line)]);
      end;
      set(x(1),'UserData',[eye_plot, scatter_plot, two_d_plot, time_range, boundary, abs(eye_line)]);
      %                    1         2             3           4           6         8
      set(x(1),'NextPlot','new');
    end
  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');
  len_u = length(u) - 1;
  changed_boundary   = 0;
  if max(boundary ~= handles(6:7)) > 0
    changed_boundary = 1;
  end;

  triggered = 0;
  if (u(len_u+1) >= threshold) & (x(2) < threshold)
    triggered = 1;
  end;
  x(2) = u(len_u+1);
   
  if handles(1) & eye_plot
    %eye_pattern plot
    sub_han = get(handles(1),'UserData');
    changed_time_range = 0;
    if max(time_range ~= handles(4:5)) > 0
      changed_time_range = 1;
    end;
    if changed_boundary
      set(handles(1), 'Ylim', boundary);
    end;
    if changed_time_range
      %this is a complicated process. Deal it later.
    end;
    len_h_userdata = length(handles);
    changed_linetype = 0;
    if (length(eye_line) ~= len_h_userdata-7)
      changed_line_type = 1;
    elseif max(abs(eye_line) ~= handles(8:len_h_userdata))
      changed_line_type = 1;
    end;
    if changed_line_type
      lines = eye_line;
      for i = 1 : len_u+1
        [col, lines] = strtok(lines, '/');
        if length(col) <= 1
          col = 'w-';
        end;
        if sub_han(i)
          set(sub_han(i), 'Color',col(1),'LineStyle',col(2:length(col)));
        end;
      end;
      set(x(1),'UserData',[handles(1:7), abs(eye_line)]);
    end;
    mod_time = rem((t - time_range(2))/time_range(1), 1) * time_range(1) + time_range(2);
    last_time = x(3);
    if ~handles(3) 
      x(3) = mod_time;
    end;
    if (mod_time < last_time)
      if store_length <= 0
        store_length = 1;
      end
      %hit the boundary of switching point.
      pre_point = mod_time + time_range(1);
      aft_point = mod_time;
      ind = [];
      if sub_han(len_u+2) >= store_length
        ind = find(isnan(sub_han(len_u+3:length(sub_han))));
        sub_han(len_u+3:ind(max(1, length(ind)-store_length))) = [];
        sub_han(len_u+2) = sum(isnan(sub_han(len_u+3:length(sub_han))));
      end;
      sub_han(len_u + 2) = sub_han(len_u + 2) + 1;
      sub_han = [sub_han t NaN t];
      set(handles(1),'UserData',sub_han);
      for i = 1 : len_u
        if sub_han(i)
          tmp_x = get(sub_han(i), 'XData');
          tmp_y = get(sub_han(i), 'YData');
          if ~isempty(ind)
            tmp_x(1:ind(max(1, length(ind)-store_length))-len_u-2) = [];
            tmp_y(1:ind(max(1, length(ind)-store_length))-len_u-2) = [];
          end;
          set(sub_han(i), 'XData',[tmp_x, pre_point, NaN, aft_point],...
                          'YData',[tmp_y, u(i),      NaN, u(i)]);
        end;
      end;
    else
      set(handles(1), 'UserData',[get(handles(1), 'UserData') t])
      for i = 1 : len_u
        if sub_han(i)
          set(sub_han(i), 'XData', [get(sub_han(i), 'XData'), mod_time], ...
                          'YData', [get(sub_han(i), 'YData'), u(i)]);
        end;
      end;
    end;

    if triggered & sub_han(len_u) & (t > 0)
      if store_length <= 0
        store_length = 1;
      end
      tmp_x = get(sub_han(len_u + 1), 'XData');
      tmp_y = get(sub_han(len_u + 1), 'YData');
      if length(tmp_x) > 3*store_length
        tmp_x(1:3) = [];
        tmp_y(1:3) = [];
      end;
      tmp_x = [tmp_x, mod_time, mod_time, NaN];
      tmp_y = [tmp_y, get(handles(1), 'YLim'), NaN];
      set(sub_han(len_u + 1), 'XData', tmp_x, 'YData', tmp_y);
    end;
  end;

  if handles(2) & triggered & (t>0) & scatter_plot
    if store_length <= 0
      store_length = 1;
    end    
    %scatter plot
    sub_han = get(handles(2), 'UserData');
    if changed_boundary
      set(handles(2), 'Ylim', boundary);
      if len_u == 2
        set(handles(2), 'Xlim', boundary);
      end;
    end;
    len_h_userdata = length(sub_han);
    changed_linetype = 0;
    if (length(scatter_line) ~= len_h_userdata - len_u)
      changed_line_type = 1;
      elseif max(abs(scatter_line) ~= sub_han(len_u+1:len_h_userdata))
        changed_line_type = 1;
      end;
      if changed_line_type
        lines = scatter_line;
        for i = 1 : len_u
          [col, lines] = strtok(lines, '/');
          if length(col) <= 1
            col = 'w-';
          end;
          if ~((i == 2) & (len_u == 2))
            set(sub_han(i), 'Color',col(1),'LineStyle',col(2:length(col)));
            if col(2) == '.'
		      set(sub_han(i), 'MarkerSize', 10);
		    else
		      set(sub_han(i), 'MarkerSize', 6);
		    end;
          end;
        end;
        set(handles(2), 'UserData',[sub_han(1:len_u), abs(scatter_line)]);
      end;
      if len_u == 2
        tmp_x = get(sub_han(1), 'XData');
        tmp_y = get(sub_han(1), 'YData');
        if length(tmp_x) > 2*store_length
          tmp_x(1:2) = [];
          tmp_y(1:2) = [];
        end;
        tmp_x = [tmp_x, u(1), NaN];
        tmp_y = [tmp_y, u(2), NaN];
        set(sub_han(1), 'XData', tmp_x, 'YData', tmp_y);
      else
      for i = 1 : len_u
        tmp_x = get(sub_han(i), 'XData');
        tmp_y = get(sub_han(i), 'YData');
        if length(tmp_x) > 2*store_length
          tmp_x(1:2) = [];
          tmp_y(1:2) = [];
        end;
        tmp_x = [tmp_x, 0, NaN];
        tmp_y = [tmp_y, u(i), NaN];
        set(sub_han(i), 'XData', tmp_x, 'YData', tmp_y);
      end;
    end;
  end;

  if handles(3) & two_d_plot
    %2-d eye_plot
    sub_han = get(handles(3), 'UserData');
    if changed_boundary
      set(handles(3), 'Xlim', boundary, 'Ylim', boundary);
    end;
    len_h_userdata = length(sub_han);
    changed_linetype = 0;
    if (length(two_d_line) ~= len_h_userdata - 2)
      changed_line_type = 1;
    elseif max(abs(two_d_line) ~= sub_han(3:len_h_userdata))
      changed_line_type = 1;
    end;
    if changed_line_type
      [col, lines] = strtok(two_d_line, '/');
      if length(col) <= 1
        col = 'w-';
      end;
      set(sub_han(1), 'Color',col(1),'LineStyle',col(2:length(col)));
      set(handles(3), 'UserData',[sub_han(1:2), abs(two_d_line)]);
    end;
    mod_time = rem((t - time_range(2))/time_range(1),1)*time_range(1) + time_range(2);
    last_time = x(3);
    x(3) = mod_time;
    if mod_time < last_time
      if store_length <= 0
        store_length = 1;
      end                
      tmp_x = get(sub_han(1),'XData');
      tmp_y = get(sub_han(1),'YData');
      if sub_han(2) >= store_length
        ind = find(isnan(tmp_x));
        tmp_x(1:ind(1)) = [];
        tmp_y(1:ind(1)) = [];
      end;
      tmp_x = [tmp_x u(1) NaN u(1)];
      tmp_y = [tmp_y u(2) NaN u(2)];
      set(handles(3),'UserData',[sub_han(1) sum(isnan(tmp_x)) abs(two_d_line)])
      set(sub_han(1),'XData',tmp_x,'YData',tmp_y);
    else
      set(sub_han(1), 'XData', [get(sub_han(1), 'XData'), u(1)], ...
                      'YData', [get(sub_han(1), 'YData'), u(2)]);
    end;
    drawnow;
  end;
  sys = x;
  if flag == 9
    sys = [];
  end;
elseif flag  == 0,        % Initialization

   % Return system sizes

   sys(1) = 0;             % 0 continuous states
   sys(2) = 3;             % 2 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) = 1;             % 1 sample time

   x0 = [0, 0, 0];         % figure handle, u[last] input, last_mod_time
   % x(1), the figure handle.
   ts = [-1, 0];
elseif (flag == 4) & (nargin > 6)
   sys = [];
else
   % Other flag options not defined.
   sys = [];
end
if (flag == 9)
  sys = [];
end;







⌨️ 快捷键说明

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