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

📄 eyediasi.m

📁 数字通信第四版原书的例程
💻 M
📖 第 1 页 / 共 2 页
字号:
function  [sys, x0, str, ts]  = eyesampl(t,x,u,flag,time_range,boundary,store_length,eye_line,scatter_line,two_d_line)
%EYEDIASI SIMULINK eye diagram and scater plot
%
%   This M-file is designed to be used in a SIMULINK S-function block.
%   It plots eyediagram aganst time and the scater plot.
%   The parameter for the block of this figure are:
%
%   Time range ( and offset if it is a two element variable)
%   Lower bounary and upper boundary of the y axis.
%   keep number of traces in storage for print purpose.
%   Line type for eye-pattern diagram (0 for no such plot)
%   Symbol type for scatter plot (0 for no such plot)
%   Line type for 2-D trace plot (for 2-D signal only, 0 for no such plot)
%   
%   This file takes scaler input + trigger signal input
%   or 2 dimentional vector input + trigger signal input
%
%   Set this M-file up in an S-function block.
%   Set the function parameter up as a four element vector
%   which defines the axis of the graph. The line type must be in
%   quotes.
%
%   See also PLOT, SFUNYST, SFUNXY, LORENZ2.

%       Wes Wang 4-28-93, 8-17-93, 12-15-93
%       Copyright (c) 1990-96 by The MathWorks, Inc.

%%%%%% begin
if (flag == 2) | (flag == 9)
  threshold = .2;
  eye_plot = ~((eye_line(1)==0) + (eye_line(1)=='0'));
  scatter_plot = ~((scatter_line(1)==0) + (scatter_line(1) == '0'));
  two_d_plot = ~((two_d_line(1)==0) + (two_d_line(1) == '0'));
  len_u = length(u)-1;

  if two_d_plot & (len_u ~= 2)
    [sl_name,block] = get_param;
    error(['Please set 2-D plot line type to be zero in block ', sl_name, '/', block]);
    if len_u > 2
      error('The input signal length is limited to two.')
    end;
  end;

  plot_type = eye_plot + scatter_plot + two_d_plot;
  % in case of no plot
  if plot_type <= 0
    if flag == 9
      sys=[];
    end;
    return;
  end;

  if length(time_range) < 2
    time_range(2) = 0;
  else
    time_range(2) = rem(rem(time_range(2), time_range(1)) + time_range(1), time_range(1));
  end;

  % initialize the figure
  if x(1) == 0
    h_fig = x(1);
    % Initialize graph
    [sl_name,block] = get_param;
    [n_b, m_b]= size(block);
    if n_b < 1
      error('Cannot delete block while simulating')
    elseif n_b > 1
      error('Something wrong in get_param, You don''t have the current SIMULINK')
    end;
    ind = find(sl_name == setstr(10));
    dash = '_';
    sl_name(ind)=dash(ones(size(ind)));

    % findout if the graphics window exist
    % in case of figure exists
    Figures = get(0,'Chil');
    new_figure = 1; % figure needs re-initialization
	old_figure = 0; % use the old figure frame.
    i = 1;
	while ((new_figure) & ( i <= length(Figures)))
      if strcmp(get(Figures(i), 'Type'), 'figure')
        if strcmp(get(Figures(i), 'Name'), sl_name)
          h_fig = Figures(i);
          set(h_fig,'NextPlot','add');
          set(0,'CurrentFigure',h_fig);  
          handles = get(h_fig, 'UserData');
	      new_figure = 0;
	      old_figure = 0;
          x(1) = h_fig;
	      if (eye_plot > 0) ~= (handles(1) > 0)
			old_figure = 1;
	      elseif (scatter_plot > 0) ~= (handles(2) > 0)
			old_figure = 1;
	      elseif (two_d_plot > 0) ~= (handles(3) > 0)
			old_figure = 1;
	      elseif length(get(h_fig,'child')) ~= plot_type
			old_figure = 1;
	      else
			set(0,'CurrentFigure',h_fig);
            set(h_fig,'NextPlot','add');
	    	if eye_plot
		      eye_plot = handles(1);
		      delete(get(eye_plot,'child'));
              set(x(1),'CurrentAxes',eye_plot);
              set(eye_plot,'NextPlot','Add');
              ax = [];
              lines = eye_line;
              for j = 1:len_u+1;
                [col, lines] = strtok(lines, '/');
                if length(col) <= 1
                  col = 'w-';
                end;
                if lower(col(1)) == 'n'
                  ax(j) = 0
                else
                  ax(j) = plot(0,0,col,...    
                          'Erasemode','none',...
                          'Color',col(1),'LineStyle',col(2:length(col)));
                  set(ax(j), 'XData', [], 'YData', []);
                end;
              end;
              set(eye_plot,'Xlim',[rem(time_range(2)/time_range(1), 1)*time_range(1), time_range(1)+time_range(2)], ...
                           'Ylim',[boundary(1), boundary(2)]);
              set(eye_plot,'UserData',[ax, 0  ],'NextPlot','new');
              %                        |   | |==>space for time points
              %                        |   |==> number of NaN added
              %                        |===> have size of length(u)
			end; %if eye_plot
			if scatter_plot
			  scatter_plot = handles(2);
			  delete(get(scatter_plot, 'child'))
              set(x(1),'CurrentAxes',scatter_plot);
              set(scatter_plot,'NextPlot','add');
              ax = [];
              lines = scatter_line;
              for j = 1:len_u
                [col, lines] = strtok(lines, '/');
                if length(col) <= 1
                  col = 'w-';
                end;
                if ((len_u == 2) & (j == 2))
                  ax(j) = 0;
                else
                  if lower(col(1)) == 'n'
                    ax(j) = 0;
                  else
                    ax(j) = plot(0,0,col,...
                            'Erasemode','none',...
                            'Color',col(1),'LineStyle',col(2:length(col)));
                    if col(2) == '.'
                      set(ax(j), 'MarkerSize', 10);
                    end;
                    set(ax(j), 'XData', [], 'YData', []);
                  end;
                end;
              end;
              if len_u == 2
                set(scatter_plot,'Xlim',[boundary(1), boundary(2)], ...
                    'Ylim',[boundary(1), boundary(2)]);
              else
                set(scatter_plot,'Xlim',[-1, 1],...
                    'Ylim',[boundary(1), boundary(2)]);
              end;
              set(scatter_plot,'UserData',[ax, abs(scatter_line)]);
			end; %scatter_plot
			if two_d_plot
			  two_d_plot = handles(3);
			  delete(get(two_d_plot,'child'))
              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 % two_d_plot
            set(x(1),'UserData',[eye_plot, scatter_plot, two_d_plot, time_range, boundary, abs(eye_line)]);
			set(x(1),'Color',get(x(1),'Color'));
          end; % old_figure
	    end; % Name
	  end; % Type
      i = i + 1;
	end

    if new_figure | old_figure
      if flag == 9
        sys=[];
        return;
      end;
      % generate a new figure here.
      if plot_type == 1
		%open a single window figure
		if ~old_figure
	      x(1) = figure('Position',[5 5 360 350], ...
	                    'Name', sl_name, 'Number', 'off'); 
        else
          delete(get(x(1),'child'));
          set(x(1),'NextPlot','add');
        end;
        plt(1) = axes('Unit','norm','Pos',[.08, .08 .87,.87], 'Clipping', 'on');
      elseif plot_type == 2
		% open a double window figure
		if ~old_figure
          x(1) = figure('Position',[5 5 660 350],...
            			'Name', sl_name, 'Number', 'off'); 
        else
          delete(get(x(1),'child'));
        end;
        plt(1) = axes('Unit','norm','Pos',[.08, .08 .8/2,.87], 'Clipping', 'on');
        plt(2) = axes('Unit','norm','Pos',[.08+.5, .08 .8/2,.87]);
      elseif plot_type == 3
	    % open a three window figure
	    if ~old_figure
          x(1) = figure('Position',[5 5 960 350],...
	        		'Name', sl_name, 'Number', 'off'); 
        else
          delete(get(x(1),'child'));
        end;
        plt(1) = axes('Unit','norm','Pos',[.04, .08 .79/3,.87], 'Clipping', 'on');
        plt(2) = axes('Unit','norm','Pos',[.04+1/3, .08 .79/3,.87]);
        plt(3) = axes('Unit','norm','Pos',[.04+2/3, .08 .79/3,.87]);
      end;
      i = 1;
      if eye_plot
        eye_plot = plt(i);
        i = i+1;
        set(x(1),'CurrentAxes',eye_plot);
        set(eye_plot,'NextPlot','Add');
        ax = [];
        lines = eye_line;
        for j = 1:len_u+1;
          [col, lines] = strtok(lines, '/');
          if length(col) <= 1
            col = 'w-';
          end;
          if lower(col(1)) == 'n'
            ax(j) = 0
          else
            ax(j) = plot(0,0,col,...    
                   'Erasemode','none',...
                   'Color',col(1),'LineStyle',col(2:length(col)));
            set(ax(j), 'XData', [], 'YData', []);
          end;
        end;

        set(eye_plot,'Xlim',[rem(time_range(2)/time_range(1),1)*time_range(1), time_range(1)+time_range(2)], ...
                     'Ylim',[boundary(1), boundary(2)], 'Clipping', 'on');
        set(eye_plot,'UserData',[ax, 0  ],'NextPlot','new');
        %                        |   | |==>space for time points
        %                        |   |==> number of NaN added
        %                        |===> have size of length(u)
      end;
      if (scatter_plot)
        scatter_plot = plt(i);
        i = i + 1;
        set(x(1),'CurrentAxes',scatter_plot);
        set(scatter_plot,'NextPlot','add');
        ax = [];
        lines = scatter_line;
        for j = 1:len_u
          [col, lines] = strtok(lines, '/');
          if length(col) <= 1
            col = 'w-';
          end;
          if ((len_u == 2) & (j == 2))
            ax(j) = 0;
          else
            if lower(col(1)) == 'n'
              ax(j) = 0
            else
              ax(j) = plot(0,0,col,...
                     'Erasemode','none',...
                     'Color',col(1),'LineStyle',col(2:length(col)));
              if col(2) == '.'
		        set(ax(j), 'MarkerSize', 10);
              end;
              set(ax(j), 'XData', [], 'YData', []);
            end;
          end;
        end;
        if len_u == 2
          set(scatter_plot,'Xlim',[boundary(1), boundary(2)], ...
              'Ylim',[boundary(1), boundary(2)]);

⌨️ 快捷键说明

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