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

📄 nnd14iir.m

📁 《神经网络设计》英文版的配套源代码
💻 M
📖 第 1 页 / 共 2 页
字号:
function [ret1,ret2,ret3,ret4,ret5]=nnd14iir(cmd,arg1,arg2,arg3,arg4,arg5)
%NND14IIR Finite Impulse Response Network
%
%  This demonstration requires either the MININNET functions
%  on the NND disk or the Neural Network Toolbox.
%
%  NND14IIR
%  Opens demonstration with default values.
%
%  NND14IIR('random')
%  Sets network parameters to randomly chosen values.
%

% Copyright 1994-2002 PWS Publishing Company and The MathWorks, Inc.
% $Revision: 1.0 $

%==================================================================

% CONSTANTS
me = 'nnd14iir';

% DEFAULTS
if nargin == 0, cmd = ''; else cmd = lower(cmd); end

% FIND WINDOW IF IT EXISTS
fig = nndfgflg(me);
if length(get(fig,'children')) == 0, fig = 0; end
  
% GET WINDOW DATA IF IT EXISTS
if fig
  H = get(fig,'userdata');
  fig_axis = H(1);            % window axis
  desc_text = H(2);           % handle to first line of text sequence
  meters = H(3:4);            % parameter axes
  indicators = H(5:6);        % paramter indicators
  freq_menu = H(7);           % frequency of input function
  inp_menu = H(8);            % Type of input function
  func_axis = H(9);          % network function axis
  func_line = H(10);          % network function line
  a_line = H(11);             % horizontal output line
  values_ptr = H(12);         % Network parameter, input & output values
  inp_ptr = H(13);             % 2nd layer transfer functio name
  freq_ptr = H(14);             % 2nd layer transfer functio name
  autoscale = H(15);          % Indication for Autoscaling
end

%==================================================================
% Activate the window.
%
% ME() or ME('')
%==================================================================

if strcmp(cmd,'')
  if fig
    figure(fig)
    set(fig,'visible','on')
  else
    feval(me,'init')
  end

%==================================================================
% Close the window.
%
% ME() or ME('')
%==================================================================

elseif strcmp(cmd,'close') & (fig)
  delete(fig)

%==================================================================
% Initialize the window.
%
% ME('init')
%==================================================================

elseif strcmp(cmd,'init') & (~fig)

  % CHECK FOR NNT
  % ODJ 12/23/07 Check for NN Toolbox removed
  %if ~nnfexist(me), return, end

  % CONSTANTS
  W1 = [1/2; -1/2];
  inp = 'square';
  freq=1/12;
  p = 0;
  values = [W1(1) W1(2)];

  % NEW DEMO FIGURE
  fig = nndemof2(me,'DESIGN','IIR Network','','Chapter 14');
  set(fig, ...
    'windowbuttondownfcn',nncallbk(me,'down'), ...
    'BackingStore','off',...
    'nextplot','add');
  H = get(fig,'userdata');
  fig_axis = H(1);
  desc_text = H(2);

  % ICON
  nndicon(14,458,363,'shadow')

  % NETWORK POSITIONS
  x1 = 40;     % input
  x2 = x1+90;  % 1st layer sum
  x3 = x2+40;  % 1st layer transfer function
  x4 = x3+100; % 2nd layer sum
  x5 = x4+40;  % 2nd layer transfer function
  x6 = x5+50;  % output
  y1 = 265;    % top neuron
  y2 = y1-20;  % input & output neuron
  y3 = y1-40;  % bottom neuron
  sz = 15;     % size of icons
  wx = 50;     % weight vertical offset (from 1st layer)
  wy = 55;     % weight horizontal offset (from middle)

  % NETWORK INPUT
  nndtext(x1-10,y2+110,'p');
  plot([x1 x2+60 x4-14],[y2+110 y2+110 y2+87],'linewidth',2,'color',nnred);
  plot([x3-80 x3-80 x5+sz+15 x5+sz+15],[y2+65 y1 y1 y2+87],'linewidth',2,'color',nnred);

  % TOP NEURON
  %nndsicon('delay',x3-80,y1+70,sz)

  % BOTTOM NEURON
  nndsicon('delay',x3-80,y1+25,sz)

  % OUTPUT NEURON
  plot([x3-80 x2+60 x4-14],[y2+65 y2+65 y2+87],'linewidth',2,'color',nnred);
  plot([x4 x6],[y2+87 y2+87],'linewidth',2,'color',nnred);
  plot([x6-10 x6 x6-10],[y2+80 y2+87 y2+94],'linewidth',2,'color',nnred);
  nndsicon('sum',x4,y2+87,sz)
  nndsicon('purelin',x5,y2+87,sz);
  nndtext(x3+wx,y2+wy+36,'iW(0)');
  nndtext(x3+wx,y2+52,'lW(1)');
  %nndtext(x3+wx,y2-wy+73,'iW(2)');
  nndtext(x5+sz+5,y2+95,'a(t)','left');

  % PARAMETER POSITIONS
  xx = 120; %20 + [0:3]*90;
  yy = [330 285 240];

  % PARAMETER METERS & INDICATORS
  meters = [];
  indicators = [];
  for i=1:2
      pn = i;
      val = values(pn);
      maxval = 2;
      maxstr = num2str(maxval);
      ax = nnsfo('a2','','','');
      set(ax,...
          'units','points',...
          'position',[xx yy(i) 70 20],...
          'color',nnmdgray,...
          'ylim',[-0.3 1.3],...
          'ytick',[],...
          'xlim',[-1.3 1.3]*maxval,...
          'xtick',[-1 -0.5 0 0.5 1]*maxval,...
          'xticklabel',str2mat(['-' maxstr],'','0','',maxstr));
      ind = fill([0 0.2 -0.2]*maxval+val,[0 1 1],nnred,...
          'edgecolor',nndkblue,...
          'erasemode','none');
      meters = [meters ax];
      indicators = [indicators ind];
  end

  % TRANSFER FUNCTION POPUP MENU
  inp_menu = uicontrol(...
    'units','points',...
    'position',[10 yy(1)-10 50 20],...
    'style','popupmenu',...
    'string','square|sine',...
    'callback',[me '(''inp'')']);
  set(inp_menu,'value',1);

  freq_menu = uicontrol(...
    'units','points',...
    'position',[10 yy(1)-40 50 20],...
    'style','popupmenu',...
    'string','1/16|1/14|1/12|1/10|1/8',...
    'callback',[me '(''freq'')']);
  set(freq_menu,'value',3);

  % PARAMETER LINES
  xx = xx + 0.5;
  y = yy(1)+10;
  x = xx(1)+70;
  plot([0 5 5]+x,[0 0 35]+y,'color',nndkgray);
  y = yy(2)+10;
  plot([0 5 5]+x,[0 0 35]+y,'color',nndkgray);
  y = yy(3)+10;
  plot([0 5 5]+x,[0 0 35]+y,'color',nndkgray);

  % NETWORK FUNCTION
  a0 = 0;
  a_1 = 0;
  p = [1 1 1 1 1 1 -1 -1 -1 -1 -1 -1 1 1 1 1 1 1 -1 -1 -1 -1 -1 -1];
  w110 = 1/2;
  w111 = -1/2;

  t = 1:length(p);
  t1 = 0:length(p);
  %num = [w110 w111];
  %den = [1];
  num = [w110];
  den = [1 w111];
  zi = [a0];
  A = filter(num,den,p,zi);

  a_max = max(A);
  a_min = min(A);
  a_edge = (a_max-a_min)*0.1;

  % FUNCTION AXIS
  y = 20;
  x = 40;
  func_axis = nnsfo('a2','','','');
  set(func_axis, ...
    'units','points',...
    'position',[x y 320 200],...
    'color',nnltyell,...
    'xlim',[0 25],...
    'ylim',[-6 6])
  %  'ylim',[a_min a_max]+[-a_edge a_edge])
  p_line = plot([0 25],[0 0],'--',...
    'color',nnred,...
    'erasemode','none');
  a_line = plot(t,p,'o',...
    'color',nnred,...
    'erasemode','none');
  func_line = plot(t1,[a0 A],...
    '.k','color',nndkblue,...
    'erasemode','none',...
    'linewidth',2);

  % BUTTONS
  drawnow % Let everything else appear before buttons 
  uicontrol(...
    'units','points',...
    'position',[400 145 60 20],...
    'string','Random',...
    'callback',[me '(''random'')'])
  uicontrol(...
    'units','points',...
    'position',[400 115 60 20],...
    'string','Reset',...
    'callback',[me '(''reset'')'])
  uicontrol(...
    'units','points',...
    'position',[400 85 60 20],...
    'string','Contents',...
    'callback','nndtoc')
  uicontrol(...
    'units','points',...
    'position',[400 55 60 20],...
    'string','Close',...
    'callback',[me '(''close'')'])

  % DATA POINTERS
  value_ptr = uicontrol('visible','off','userdata',values);
  inp_ptr = uicontrol('visible','off','userdata',inp);
  freq_ptr = uicontrol('visible','off','userdata',freq);

  callbk = [me '(''update'')'];
  autoscale = uicontrol(...
    'units','points',...
    'position',[260 230 100 20],...
    'style','check',...
    'string','Auto Scale Plot',...
    'backg',nnltgray,...
    'callback',callbk,...
    'value',0);

  % SAVE WINDOW DATA AND LOCK
  H = [fig_axis desc_text meters indicators  freq_menu inp_menu ...
    func_axis func_line a_line value_ptr inp_ptr freq_ptr autoscale];

  set(fig,'userdata',H,'nextplot','new')

  % INSTRUCTION TEXT
  feval(me,'instr');

  % LOCK WINDOW
  set(fig,'nextplot','new','color',nnltgray);

  nnchkfs;

%==================================================================
% Display the instructions.
%
% ME('instr')
%==================================================================

elseif strcmp(cmd,'instr') & (fig)
  nnsettxt(desc_text,...
    'Select the input and',...
    'frequency to the IIR',...
    'network.',...
    '',...
    'Alter network weights by',...
    'dragging the triangular',...
    'shaped indicators.',...
    '',...
    'Click on [Random] to',...
    'set each parameter',...
    'to a random value.',...
    '',...
    'Click on [Reset] to',...
    'initialize parameters.')
    
%==================================================================
% Respond to transfer function menu.
%
% ME('inp')
%==================================================================

elseif strcmp(cmd,'inp') & (fig)

  % GET NEW TRANSFER FUNCTION NAME
  i = get(inp_menu,'value');
  if i == 1, inp = 'square';
  elseif i == 2, inp = 'sine';
  end

⌨️ 快捷键说明

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