📄 nnd14dynd.m
字号:
'',...
'Select the input and',...
'frequency to the IIR',...
'network.',...
'',...
'Alter network weights by',...
'dragging the triangular',...
'shaped indicators.')
%==================================================================
% 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
% 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;
blue = get(a_line,'color');
% 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
set(func_axis,'ylim',[a_min-a_edge a_max+a_edge]);
hold on
% REDRAW LINES
set(func_line,'color',nndkblue,'xdata',t1,'ydata',[a0 A])
lw111 = W1(2);
iw11 = W1(1)+.1;
num = [iw11];
den = [1 lw111];
a1 = filter(num,den,p,zi);
set(a_line,'color',blue,'ydata',[a0 a1],'xdata',t1)
a_max = max([A a1]);
a_min = min([A a1]);
a_edge = (a_max-a_min)*0.1;
set(func_axis, ...
'xlim',[0 25],...
'ylim',[a_min a_max]+[-a_edge a_edge])
da_diw_0 = 0;
da_diw = filter(1,den,p,da_diw_0);
set(a_line2,'xdata',t1,'ydata',[da_diw_0 da_diw]);
set(func_line2,'xdata',t,'ydata',p);
a_max = max([p da_diw]);
a_min = min([p da_diw]);
a_edge = (a_max-a_min)*0.1;
set(func_axis2, ...
'xlim',[0 25],...
'ylim',[a_min a_max]+[-a_edge a_edge])
da_dlw_0 = 0;
ad = [a0 A(1:end-1)];
da_dlw = filter(1,den,ad,da_dlw_0);
set(a_line3,'xdata',t1,'ydata',[da_dlw_0 da_dlw]);
set(func_line3,'xdata',t,'ydata',ad);
a_max = max([p da_dlw]);
a_min = min([p da_dlw]);
a_edge = (a_max-a_min)*0.1;
set(func_axis3, ...
'xlim',[0 25],...
'ylim',[a_min a_max]+[-a_edge a_edge])
set(func_line4,'xdata',t1,'ydata',[a0 A]);
lw111 = W1(2)+.1;
iw11 = W1(1);
num = [iw11];
den = [1 lw111];
a1 = filter(num,den,p,zi);
set(a_line4,'xdata',t1,'ydata',[a0 a1]);
a_max = max([A a1]);
a_min = min([A a1]);
a_edge = (a_max-a_min)*0.1;
set(func_axis4, ...
'xlim',[0 25],...
'ylim',[a_min a_max]+[-a_edge a_edge])
% STORE DATA
set(values_ptr,'userdata',values);
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -