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

📄 sb2slsc.m

📁 数字通信第四版原书的例程
💻 M
📖 第 1 页 / 共 2 页
字号:
function sb2slsc(blkname,in,fl,cod,timer)
%SB2SLSC converts general signal source blocks to SIMULINK.
%	SB2SLSC(BLKNAME,IN,FL,COD,TIMER) converts a SystemBuild block
%       to a SIMULINK block.  BLKNAME is a string containing the name of
%       the block. The parameters are set up for this block based on the
%       SystemBuild file coding integer IN and real number FL.
%
%       COD is a three dimensional vector. The first element indicates
%       whether it is a continuous (0) or discrete (1) time system.
%       The second element indicates whether it does not need (0) or
%       does need (1) a mask. The third element indicates the
%       orientation of the block.
%
%       TIMER is designed for discrete time only. The first element of
%       TIMER is the sampling time. The second element is the initial time.

% Wes Wang 10/20/92 -- 10/22/92
% Copyright (c) 1990-93 by The MathWorks, Inc.
% $Revision: 1.11 $  $Date: 1993/06/09 22:09:40 $

% in = [8, code1 code2, input, output, state,....
% This function processes all of the blocks with code1 == 10
% code2 = 1: general waveform
% code2 = 2: pulse training
% code2 = 3: square waveform
% code2 = 4: ramp
% code2 = 5: step
% code2 = 6: sine wave
% code2 = 7: noise
% use "repeat sequence" for code2=1
% use "pulse generator" for code2=2
% use "square wave" for code2=3 when start_time=0 and 1/freq=2*width use Sig_Gen.
% use "ramp" for code2=4
% use "step Fcn" for code2=5
% use "sine wave" for code2 = 6
% use "Signal Gen" for code2 = 7 when it is a uniform noise
%     "White Noise" for code2=7 when it is a normal noise
%     forget the one with Ornstein-Unlenbeck distribution

if in(3) == 1
  % general waveform
  % It always uses the new system no matter how many outputs it has.
  x0=fl(1:in(5))';  % initial condition
  temp = in(in(17)+3);
  input = fl(in(5)+1:in(5)+temp)';
  for i =1:in(5)
    outpt=[outpt; fl(in(5)+i*temp+1:in(5)+(i+1)*temp)'];
  end;
  set_param(blkname,'Location',[264,406,623,721])
  add_block('built-in/Clock',[blkname '/Clock'])
  set_param([blkname '/Clock'],...
		'position',[45,65,65,85])
  for i=1:in(5) % 
    set_param([blkname '/output' num2str(i)],...
		'Port', num2str(i),...
		'position',[285,65*i,305,65*i+20])
    add_block('built-in/Look Up Table',...
		[blkname '/Lk_Up_T' num2str(i)]);
    set_param([blkname '/Lk_Up_T' num2str(i)],...
		'Input_Values','t',...
		'Output_Values',['y(' num2str(i) ',:)'],...
		'position',[210,65*i-2,250,65*i+22])
    add_block('built-in/Fcn',[blkname '/Fcn' num2str(i)])
    set_param([blkname '/Fcn' num2str(i)],...
		'Expr',['rem((u[1]-stt(' num2str(i) ')),period)'],...
		'position',[110,65*i,150,65*i+20])
    autoline(blkname,'Clock/1',['Fcn' num2str(i) '/1']);
    autoline(blkname,['Fcn' num2str(i) '/1'],['Lk_Up_T' num2str(i) '/1']);
    autoline(blkname,['Lk_Up_T' num2str(i) '/1'],['output' num2str(i) '/1']);
  end;
  set_param(blkname,'Mask Display',...
   'plot([0,st],[0,0],[t+st,t+period+st,t+st+2*period],[0 yy,yy,yy])',...
   'Mask Type','Repeating table')
   set_param(blkname,'Mask Dialogue',...
	'Repeating table. Enter the signal starting time. Enter Time values(relative to start time) and output  values for the first cycle.|Time values:|Output values:|Start time:',...
	'Mask Translate',...
	'stt=@3;period=max(@1)-min(@1);t=@1;y=@2;st=stt(1);yy=y(1,:);')
  set_param(blkname,'Mask Help',...
   'Repeats the cycle given in the table. The time values should be monotonically increase. The output signal is zero before the start time.',...
   'Mask Entries',[mat2str(input) '\/' mat2str(outpt) '\/' mat2str(x0) '\/']);
elseif in(3) == 2
  %pulse training
  x0 = fl(1:in(5))';
  mag = fl(in(5)+1:in(5)*2)';
  wid = fl(in(5)*2+1:in(5)*3)';
  per = 1 ./ fl(in(5)*3+1:in(5)*4)';
  set_param(blkname,'Location',[30,59,326,307])
  add_block('built-in/Clock',[blkname '/Clock'])
  set_param([blkname '/Clock'],'position',[55,65,75,85])
  for i=1:in(5),
    add_block('built-in/Fcn',[blkname '/Fcn' num2str(i)])
    tp=num2str(i);
    temp = ['ht(' tp ') * ((( rem((u[1]-stt(' tp ')),Ts(' tp ')) <= duration(' tp];
    temp = [temp ')) - (u[1] < stt(' tp '))) > 0)'];
    set_param([blkname '/Fcn' num2str(i)],'Expr',temp,...        
	'position',[130,65*i,170,65*i+20]);
    set_param([blkname '/output' tp],...
	'Port', tp,...
	'position',[210,65*i,230,65*i+20])
    autoline(blkname,'Clock/1',['Fcn' tp '/1']);
    autoline(blkname,['Fcn' tp '/1'],['output' tp '/1']);
    add_block('built-in/Discrete Transfer Fcn',[blkname '/rising edge sharper' tp])
    set_param([blkname '/rising edge sharper' tp],...
	'Denominator','[1]',...
	'Sample time',['[Ts(' tp '),stt(' tp ')]'],...
	'position',[325,65*i,370,65*i+30])
    add_block('built-in/Discrete Transfer Fcn',[blkname '/cutting edge sharper' tp])
    set_param([blkname '/cutting edge sharper' num2str(i)],...
	'Denominator','[1]',...
	'Sample time',['[Ts(' tp '),stt(' tp ')+duration(' tp ')]'],...
	'position',[385,65*i,430,65*i+30])
  end;
  set_param(blkname,'Mask Display',...
    'plot(0,0,100,100,[90,75,75,60,60,35,35,20,20,10],[20,20,80,80,19,20,80,80,20,20])',...
    'Mask Type','Pulse generator')
  set_param(blkname,'Mask Dialogue',...
    'Pulse generator.|Pulse period (secs):|Pulse width:|Pulse height:|Pulse start time:',...
    'Mask Translate','Ts = @1; duration = @2; ht = @3; stt = @4;')
  temp = 'Pulse generator which ensures that pulse\ntransitions are hit.';
  temp = [temp ' Uses clock, Fcn and ZOH block. Unmask to see how it works.'];
  set_param(blkname,'Mask Help',temp,...
    'Mask Entries',[mat2str(per) '\/' mat2str(wid) '\/' mat2str(mag) '\/' mat2str(x0) '\/'])
elseif in(3) == 3
  %square waveform
  x0 = fl(1:in(5))';
  mag = fl(in(5)+1:in(5)*2)';
  wid = fl(in(5)*2+1:in(5)*3)';
  per = 1 ./ fl(in(5)*3+1:in(5)*4)';
  if in(5) == 1 & x0 == 0 & per./wid == 2
    % we may use signal Gen here
    delete_block(blkname);
    add_block('built-in/Signal Generator',blkname);
    set_param(blkname, 'Peak',num2str(mag),...
        'Peak Range',num2str(mag*5),'Freq',num2str(1/per),...
	'Freq Range',num2str(5/per),'Wave','Sqr',...
	'Units','Rads');
  else
    % regular procedure
    set_param(blkname,'Location',[30,59,326,307])
    add_block('built-in/Clock',[blkname '/Clock'])
    set_param([blkname '/Clock'],'position',[55,65,75,85])
    for i=1:in(5),
      add_block('built-in/Fcn',[blkname '/Fcn' num2str(i)])
      tp=num2str(i);
      set_param([blkname '/Fcn' num2str(i)],'Expr',...
        ['2*ht(' tp ')*((rem((u[1]-stt(' tp ')),Ts(' tp '))<=duration(' tp '))-0.5)*(u[1]>=stt(' tp '))'],...
	'position',[130,65*i,170,65*i+20]);
      set_param([blkname '/output' tp],...
	'Port', tp,...
	'position',[210,65*i,230,65*i+20])
      autoline(blkname,'Clock/1',['Fcn' tp '/1']);
      autoline(blkname,['Fcn' tp '/1'],['output' tp '/1']);
      add_block('built-in/Discrete Transfer Fcn',[blkname '/rising edge sharper' tp])
      set_param([blkname '/rising edge sharper' tp],...
	'Denominator','[1]',...
	'Sample time',['[Ts(' tp '),stt(' tp ')]'],...
	'position',[325,65*i,370,65*i+30])
      add_block('built-in/Discrete Transfer Fcn',[blkname '/cutting edge sharper' tp])
      set_param([blkname '/cutting edge sharper' num2str(i)],...
	'Denominator','[1]',...
	'Sample time',['[Ts(' tp '),stt(' tp ')+duration(' tp ')]'],...
	'position',[385,65*i,430,65*i+30])
    end;
    temp = 'plot([0,2*t1+t3],[0 0],[0,t3,t3,t2+t3,t2+t3,t1+t3,t1+t3,t2+t1+t3,t2+t1+t3,2*t1+t3],[0 0 z z -z -z z z -z -z])';
    set_param(blkname,'Mask Display',temp,...
     'Mask Type','Pulse generator')
    set_param(blkname,'Mask Dialogue',...
     'Pulse generator.|Pulse period (secs):|Pulse width:|Pulse height:|Pulse start time:',...
     'Mask Translate',...
     'Ts=@1; duration=@2; ht=@3; stt=@4; t1=Ts(1); t2=duration(1); t3=stt(1);z=ht(1);')
    temp = 'Pulse generator which ensures pulse transitions are hit.';
    temp = [temp ' Uses clock, fcn and ZOH block. Unmask to see how it works.'];
    set_param(blkname,'Mask Help',temp,...
     'Mask Entries',[mat2str(per) '\/' mat2str(wid) '\/' mat2str(mag) '\/' mat2str(x0) '\/'])
  end
elseif in(3) == 4
  %ramp
  x0=fl(1:in(5))';
  sl=fl(in(5)+1:in(5)*2)';
  sa=fl(in(5)*2+1:in(5)*3)';
  set_param(blkname,'Location',[217,241,565,376])
  add_block('built-in/Clock',[blkname '/Clock'])
  set_param([blkname '/Clock'],...
		'position',[55,65,75,85])
  for i=1:in(5)
    tp = num2str(i);
    set_param([blkname,'/output' tp],...
	'Port',tp,'position',[295,65*i,315,65*i+20])
    add_block('built-in/Fcn',[blkname '/RMP' tp])
    set_param([blkname '/RMP' tp],...
	'Expr',['sl(' tp ')*(u[1]-st(' tp '))*(u[1]>=st(' tp '))'],...
	'position',[90,65*i,155,65*i+20])
    add_block('built-in/Fcn',[blkname,'/LMT' tp])
    set_param([blkname,'/LMT',tp],...
	'Expr',['u[1]*(u[1]<=sa(' tp '))+sa(' tp ')*(u[1]>sa(' tp '))'],...
	'position',[190,65*i,255,65*i+20])
    autoline(blkname,'Clock/1',['RMP' tp '/1']);
    autoline(blkname,['RMP' tp '/1'],['LMT' tp '/1']);
    autoline(blkname,['LMT' tp '/1'],['output' tp '/1']);
  end;

⌨️ 快捷键说明

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