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

📄 nnd14iir.m

📁 《神经网络设计》英文版的配套源代码
💻 M
📖 第 1 页 / 共 2 页
字号:

  % SAVE DATA
  set(inp_ptr,'userdata',inp);
  
  % UPDATA FUNCTION
  cmd = 'update';

%==================================================================
% Respond to transfer function menu.
%
% ME('freq')
%==================================================================

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

  % GET NEW TRANSFER FUNCTION NAME
  i = get(freq_menu,'value');
  if i == 1, freq = 1/16;
  elseif i == 2, freq = 1/14;
  elseif i == 3, freq = 1/12;
  elseif i == 4, freq = 1/10;
  elseif i == 5, freq = 1/8;
  end

  % SAVE DATA
  set(freq_ptr,'userdata',freq);
  
  % UPDATA FUNCTION
  cmd = 'update';

%==================================================================
% Respond to mouse down.
%
% ME('down')
%==================================================================

elseif strcmp(cmd,'down') & (fig) & (nargin == 1)

  handled = 0;
  for i=1:2

    maxval = 2;

    pt = get(meters(i),'currentpoint');
    x = pt(1);
    y = pt(3);

    if (abs(x) <= maxval*1.3) & (y >= -0.3 & y <= 1.3)
      handled = 1;

      % SET UP MOTION TRACKING IN METER
      set(fig,'WindowButtonMotionFcn',[me '(''m_motion'',' num2str(i) ')']);
      set(fig,'WindowButtonUpFcn',[me '(''m_up'',' num2str(i) ')']);
      feval(me,'m_motion',i);
    end
  end

  if (~handled)
    pt = get(func_axis,'currentpoint');
    x = pt(1);
    y = pt(3);
    ylim = get(func_axis,'ylim');
  end

%==================================================================
% Respond to motion in meter.
%
% ME('m_motion',meter_index)
%==================================================================

elseif strcmp(cmd,'m_motion') & (fig)
  
  maxval = 2;

  % GET CURRENT POINT
  pt = get(meters(arg1),'currentpoint');
  x = pt(1);
  x = round(x*10/maxval)*maxval/10;
  x = max(-maxval,min(maxval,x));

  % GET DATA
  mdgray = nnmdgray;
  values = get(values_ptr,'userdata');
 
  % MOVE INDICATOR
  xdata = [0 0.2 -0.2]*maxval+x;
  set(indicators(arg1),'facecolor',mdgray,'edgecolor',mdgray);
  set(indicators(arg1),'facecolor',nnwhite,'edgecolor',nndkblue,'xdata',xdata);

  % STORE DATA
  values(arg1) = x;
  set(values_ptr,'userdata',values);

%==================================================================
% Respond to mouse up in meter.
%
% ME('m_up',meter_index)
%==================================================================

elseif strcmp(cmd,'m_up') & (fig)
  
  % DISABLE TRACKING
  set(fig,'WindowButtonMotionFcn','');
  set(fig,'WindowButtonMotionFcn','');

  % RESET INDICATOR COLORS
  set(indicators(arg1),'facecolor',nnred,'edgecolor',nndkblue);

  % UPDATE FUNCTION
  cmd = 'update';

%==================================================================
% Respond to mouse up in function.
%
% ME('f_up')
%==================================================================

elseif strcmp(cmd,'f_up') & (fig)
  
  % DISABLE TRACKING
  set(fig,'WindowButtonMotionFcn','');
  set(fig,'WindowButtonMotionFcn','');

  % RESET P-LINE COLOR
  red = nnred;
  %set(p_line,'color',red)
  %set(a_line,'color',red)
  set(func_line,'color',nndkblue)

%==================================================================
% Randomize parameters.
%
% ME('random')
%==================================================================

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

  % GET VALUES
  values = get(values_ptr,'userdata');
  %p = values(8);
 
  % ALTER VALUES
  W1 = (rand(3,1)*2-1)*2;
  inp_ind = fix(rand*2)+1;
  set(inp_menu,'value',inp_ind)
  if inp_ind == 1
    inp = 'square';
  elseif inp_ind == 2
    inp = 'sine';
  end
  set(inp_ptr,'userdata',inp)

  freq_ind = fix(rand*5)+1;
  set(freq_menu,'value',freq_ind)
  if freq_ind == 1
    freq = 1/16;
  elseif freq_ind == 2
    freq = 1/14;
  elseif freq_ind == 3
    freq = 1/12;
  elseif freq_ind == 4
    freq = 1/10;
  elseif freq_ind == 5
    freq = 1/8;
  end
  set(freq_ptr,'userdata',freq)

  values = [W1(1) W1(2) W1(3)];

  % SAVE VALUES
  set(values_ptr,'userdata',values);

  % MOVE METERS
  cmd = 'move';

%==================================================================
% Randomize parameters.
%
% ME('reset')
%==================================================================

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

  % GET VALUES
  values = get(values_ptr,'userdata');
 
  % ALTER VALUES
  W1 = [1/2 -1/2];
  inp_ind = 1;
  set(inp_menu,'value',inp_ind)
  inp = 'square';
  set(inp_ptr,'userdata',inp)

  freq_ind = 3;
  set(freq_menu,'value',freq_ind)
  freq = 1/12;
  set(freq_ptr,'userdata',freq)

  values = [W1(1) W1(2)];

  % SAVE VALUES
  set(values_ptr,'userdata',values);

  % MOVE METERS
  cmd = 'move';

end

%==================================================================
% Move meters.
%
% ME('move')
%==================================================================

if strcmp(cmd,'move') & (fig)
  
  % GET DATA
  values = get(values_ptr,'userdata');

  % HILIGHT METERS
  mdgray = nnmdgray;
  red = nnred;
  white = nnwhite;
  dkblue = nndkblue;
  for i=1:2
    set(indicators(i),'facecolor',white);
  end
  nnpause(0.25)

  % MOVE METERS
  for i=1:2
    maxval = 2;
    xx = [0 0.2 -0.2]*maxval+values(i);
    set(indicators(i),'facecolor',mdgray,'edgecolor',mdgray);
    set(indicators(i),'facecolor',white,'edgecolor',dkblue,'xdata',xx);
  end
  nnpause(0.25)

  % UNHILIGHT METERS
  for i=1:2
    set(indicators(i),'facecolor',red);
  end

  % ALWAYS DO AN UPDATE AFTERWARDS
  cmd = 'update';
end

%==================================================================
% Update function.
%
% ME('update')
%==================================================================

if strcmp(cmd,'update') & (fig)

  % GET DATA
  inp = get(inp_ptr,'userdata');
  freq = get(freq_ptr,'userdata');
  values = get(values_ptr,'userdata');
  W1 = values([1:2])';
  if strcmp(inp,'square')
      if freq==1/16
          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];
      elseif freq==1/14
          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];
      elseif freq==1/12
          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];
      elseif freq==1/10
          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];
      elseif freq==1/8
          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];
      end
  else
      p = [sin((0:23)*2*pi*freq)];
  end
  ltyell = nnltyell;
  red = nnred;

  % NEW FUNCTION
  a0 = 0;
  a_1 = 0;
  t = 1:length(p);
  t1 = 0:length(p);
  %num = [W1(1) W1(2)];
  %den = [1];
  
  num = [W1(1)];
  den = [1 W1(2)];
  zi = [a0];
  A = filter(num,den,p,zi);
  
  % CALCULATE AXIS AND LINE LIMITS
  a_max = max([A 1]);
  a_min = min([A -1]);
  a_mid = (a_max+a_min)/2;
  a_dif = a_max-a_min;

  a_dif = a_dif + max(a_dif*0.1,0.1);
  a_max = a_mid+0.45*a_dif;
  a_min = a_mid-0.45*a_dif;
  a_edge = 0.05*a_dif;

  % HIDE LINES
  set(func_line,'color',ltyell);
  set(a_line,'color',ltyell);

  % RESIZE AXIS
  if get(autoscale,'value')==1
     set(func_axis,'ylim',[a_min-a_edge a_max+a_edge]);
  else
     set(func_axis,'ylim',[-6 6]);
  end
  hold on

  % REDRAW LINES
  set(a_line,'color',red,'ydata',p,'xdata',t)
  set(func_line,'color',nndkblue,'xdata',t1,'ydata',[a0 A])
  
  % STORE DATA
  set(values_ptr,'userdata',values);
end

⌨️ 快捷键说明

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