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

📄 sbiterr.m

📁 现代通信系统(prokis)的所有matlab源程序,对初学者很有帮助的。
💻 M
📖 第 1 页 / 共 2 页
字号:
	      'VerticalA',  'Middle');

	  % title for error number
	  uicontrol(figureHandle, ...
	      'Style', 'text', ...
	      'Units', 'normalized',...
	      'Position', [p_beg1,...
		  ((len_rate - ii) * 3 + 1 + 1)/totalLine+.001, ...
		  p_wid, 1/totalLine-.002],...
	      'String','Error Number'); 

	  % title for error rate
	  uicontrol(figureHandle,...
	      'Style', 'text',...
	      'Units', 'normalized',...
	      'Position', [p_beg1, ...
		  ((len_rate - ii) * 3 + 1)/totalLine+.001,...
		  p_wid, 1/totalLine-.002],...
	      'String','Error Rate'); 
	else
	  %error number
	  kk = (i-1)*2 + (inputLength * 2 - 1)*(ii - 1);
	  set(linePlot, ...
	      'XData', [get(linePlot, 'XData') [p_beg1 p_beg1]-.001 NaN],...
	      'YData', [get(linePlot, 'YData'),...
		  ((len_rate - ii)* 3 + 1)/totalLine,...
		  ((len_rate - ii)* 3 + 2 + 1)/totalLine,...
		  NaN]);
	  
	  h_sym_bit(kk) = text(p_beg, ...
	      ((len_rate-ii)*3*2 + 3 + 2)/2/totalLine,...
	      '0',...
	      'Parent', handleAxes);
	  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/totalLine, ...
	      '0',...
	      'Parent', handleAxes);
	  set(h_sym_bit(kk+1), ...
	      'UserData', 0,...
	      'FontSize', 9,...
	      'Color',[0 0 0],...
	      'HorizontalA','Center',...
	      'VerticalA',  'Middle');
	end;
      end;
    end;
    set(handleAxes, 'Xlim',[0 1],...
	'Ylim',[0 1])
    current_point = 0;
    set(figureHandle, 'UserData', [current_point, h_sym_bit, handleRecord]);
    
    x(1) = figureHandle;
    tmp1 = uicontrol(...
	figureHandle,...
	'Style', 'pushbutton',...
	'Unit', 'normalized',...
	'Position', [0 0 .5 1/totalLine], ...
	'String', 'Reset error count',...
	'Callback',...
	['sbiterrs(gcbf,',num2str(len_rate),',',num2str(inputLength),')']);
    
    tmp1 = uicontrol(...
	figureHandle,...
	'Style', 'pushbutton',...
	'Unit', 'normalized',...
	'Position', [.5 0 .5 1/totalLine], ...
	'String', 'Close',...
	'Callback','close(gcbf)');
  elseif x(1) < 0
    %  figure has been closed
    return;
  end;
  
  plot_flag_test = allchild(0);
  if isempty(plot_flag_test)
    return;
  elseif isempty(find(plot_flag_test == x(1)))
    x(1) = -1;
    return;
  end;
  
  inputLength = inputLength;
  handles = get(x(1), 'UserData');
  figureHandle =  x(1);
  current_point = handles(1);
  if K == 1
    h_sym_bit = handles(2 : inputLength*2);
    handleRecord = handles(inputLength*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 : inputLength*4-1);
    handleRecord = handles(inputLength*4 : length(handles));
    t_tras(1) = get(h_sym_bit(1), 'UserData') + 1;
    t_tras(2) = get(h_sym_bit(inputLength*2), 'UserData') + K;
    set(h_sym_bit(1), 'UserData', t_tras(1), ...
	'String', num2str(t_tras(1),  8));
    set(h_sym_bit(inputLength*2), 'UserData', t_tras(2), ...
	'String', num2str(t_tras(2), 8));
  end;    
  if numLine > 0
    if current_point == 0
      set(handleRecord(1), 'UserData', rem(get(handleRecord(1), 'UserData') + 1, 2));
    end;
    col = colorMap(get(handleRecord(1), 'UserData') + 1, :);
    next_point = rem(current_point + 1, numLine);
    last_point = rem(current_point-1+numLine, numLine);
  else
    next_point = 0;
    last_point = 0;
  end;
  for i = 1 : inputLength
    if i == 1
      if numLine > 0
	set(handleRecord(current_point * inputLength + i), ...
	    'String', num2str(x(3), 8), 'Color',col);
      end;
    else
      if numLine > 0
	if u(i) == x(3)
	  set(handleRecord(current_point * inputLength + i), ...
	      'String', num2str(u(i), 8), 'Color',col);
	else
	  set(handleRecord(current_point * inputLength + 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 + (inputLength * 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 + (inputLength * 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 = [figureHandle; x(2:length(x))];
  % save all the current displaying information in figureHandle  
  set(figureHandle, 'UserData', [current_point, h_sym_bit, handleRecord]);
  %second in User data is the current position for the line of handleRecord.
end;  

% end mdlUpdate

%
%=============================================================================
% LocalFigureDeleteFcn
% This is the Graph figure window's DeleteFcn.  The figure window is
% being deleted, update the Graph block's UserData to reflect the change.
%=============================================================================
%
function LocalFigureDeleteFcn

%
% Get the block associated with this figure and set it's figure to -1
%
close(gcbf);

% end LocalFigureDeleteFcn

%
%=============================================================================
% LocalBlockStartFcn
% Function that is called when the simulation starts.  Initialize the
% Graph scope figure.
%=============================================================================
%
function LocalBlockStartFcn

%
% get the figure associated with this block, create a figure if it doesn't
% exist
%
figureHandle = GetSBiterrFigure(gcbh);
if ~ishandle(figureHandle),
  figureHandle = CreateSBiterrFigure;
end

ud = get(figureHandle,'UserData');
set(figureHandle,'UserData',ud);

% end LocalBlockStartFcn

%
%=============================================================================
% LocalBlockStopFcn
% At the end of the simulation, set the line's X and Y data to contain
% the complete set of points that were acquire during the simulation.
% Recall that during the simulation, the lines are only small segments from
% the last time step to the current one.
%=============================================================================
%
function LocalBlockStopFcn

%
% Locate the figure window associated with this block. If it's not a valid
% handle (it may have been closed by the user), then return.
%
figureHandle=GetSBiterrFigure(gcbh);
if ishandle(figureHandle),
  %
  % Get UserData of the figure.
  %
  ud = get(figureHandle,'UserData');
  % Currently do nothing in LocalBlockStopFcn

end

% end LocalBlockStopFcn

%
%=============================================================================
% LocalBlockNameChangeFcn
% Function that handles name changes on the Bit-Error Meter.
%=============================================================================
%
function LocalBlockNameChangeFcn

%
% the figure handle is stored in the block's UserData
%
figureHandle = GetSBiterrFigure(gcbh);
if ishandle(figureHandle),
  set(figureHandle,'Name',get_param(gcbh,'Name'));
end

% end LocalBlockNameChangeFcn

%
%=============================================================================
% LocalBlockLoadCopyFcn
% Function that initializes the Bit-Error Meter's UserData when it is
% loaded from an mdl file and when it is copied.
%=============================================================================
%
function LocalBlockLoadCopyFcn

SetSBiterrFigure(gcbh,[]);

% end LocalBlockLoadCopyFcn

%
%=============================================================================
% LocalBlockDeleteFcn
% Function that handles the Bit-Error Meter's deletion from a block
% diagram.
%=============================================================================
%
function LocalBlockDeleteFcn

%
% the figure handle is stored in the block's UserData
%
figureHandle = GetSBiterrFigure(gcbh);
if ishandle(figureHandle),
  delete(figureHandle);
  SetSBiterrFigure(gcbh,[]);
end

% end LocalBlockDeleteFcn

%
%=============================================================================
% GetSBiterrFigure
% Retrieves the figure window associated with this S-function Bit-Error Meter
% from the block's parent subsystem's UserData.
%=============================================================================
%
function figureHandle=GetSBiterrFigure(block)

if strcmp(get_param(block,'BlockType'),'S-Function'),
  block=get_param(block,'Parent');
end

ud = get_param(block,'UserData');
if ishandle(ud)
  figureHandle = ud;
else
  if isempty(ud)
    ud.figureHandle = [];
    set_param(block,'Userdata', ud);
  end;  
  figureHandle = ud.figureHandle;
end;

if isempty(figureHandle),
  figureHandle = -1;
end

% end GetSBiterrFigure

%
%=============================================================================
% SetSBiterrFigure
% Stores the figure window associated with this S-function Bit-Error Meter
% in the block's parent subsystem's UserData.
%=============================================================================
%
function SetSBiterrFigure(block,figureHandle)

if strcmp(get_param(block,'BlockType'),'S-Function'),
  block=get_param(block,'Parent');
end

ud = get_param(block,'UserData');
ud.figureHandle = figureHandle;
set_param(block,'UserData',ud);

% end SetSBiterrFigure

%
%=============================================================================
% CreateSBiterrFigure
% Creates the figure window associated with this S-function Bit-Error Meter.
%=============================================================================
%
function figureHandle=CreateSBiterrFigure

%
% create the figure and the axes
%
a = allchild(0);
b = findobj(a, 'Name', get_param(gcbh,'Name'));
if isempty(b)
  figureHandle = figure(...
      'Units',        'points',...
      'Position',     [10 20 350 400],...
      'NumberTitle',  'off',...
      'Visible', 'off', ...      
      'Name',         get_param(gcbh,'Name'),...
      'Color',	   [1 1 1],...		   
      'IntegerHandle','off',...
      'DeleteFcn',    'sbiterr([],[],[],''DeleteFigure'')'...
      );
else
  figureHandle = b;
end;
set(0, 'CurrentFigure', figureHandle);

%
% store the block's handle in the figure's UserData
%
ud.Block = gcbh;

%
% squirrel the figure handle away in the current block, and put the
% various handles into the figure's UserData
%
SetSBiterrFigure(gcbh,figureHandle);
set(figureHandle,'HandleVisibility','callback','UserData',ud);

% end CreateSBiterrFigure

%
%=============================================================================
% SetBlockCallbacks
% This sets the callbacks of the block if it is not a reference.
%=============================================================================
%
function SetBlockCallbacks(block)

%
% the actual source of the block is the parent subsystem
%
block=get_param(block,'Parent');

%
% if the block isn't linked, issue a warning, and then set the callbacks
% for the block so that it has the proper operation
%
if strcmp(get_param(block,'LinkStatus'),'none'),
%  warnmsg=sprintf(['The Bit-Error Meter block ''%s'' should be replaced with a ' ...
%                   'new version from the com_sour block library'],...
%                   block);
%  warning(warnmsg);

  callbacks={
    'CopyFcn',       'sbiterr([],[],[],''CopyBlock'')' ;
    'DeleteFcn',     'sbiterr([],[],[],''DeleteBlock'')' ;
    'LoadFcn',       'sbiterr([],[],[],''LoadBlock'')' ;
    'StartFcn',      'sbiterr([],[],[],''Start'')' ;
    'StopFcn'        'sbiterr([],[],[],''Stop'')' ;
    'NameChangeFcn', 'sbiterr([],[],[],''NameChange'')' ;
  };

  for i=1:length(callbacks)
    if ~strcmp(get_param(block,callbacks{i,1}),callbacks{i,2})
      set_param(block,callbacks{i,1},callbacks{i,2});
    end
  end
end

% end SetBlockCallbacks

%%%%%%%%%%%%%%%%%%%%%%%%
%   End of SBITERR.M   %
%%%%%%%%%%%%%%%%%%%%%%%%


⌨️ 快捷键说明

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