📄 filtview.m
字号:
ud.pointer = 0;
set(fig,'userdata',ud);
fvmotion(ud.toolnum)
else
set(ud.tabfig,'visible','on')
figure(ud.tabfig)
end
%------------------------------------------------------------------------
% filtview('mdown')
% mouse down event on one of the lines
%
case 'mdown'
[l,fig] = gcbo;
ud = get(fig,'userdata');
oldFocusIndx = ud.focusIndex;
if ud.pointer == 2 % help mode
fvhelp('line')
return
end
if ~justzoom(fig)
ax = get(l,'parent');
if ax==ud.ht.a(5) | ax==ud.ht.a(6)
erasemode = 'xor';
else
erasemode = 'background';
end
xlim = get(ax,'xlim');
ylim = get(ax,'ylim');
% Determine which line from which filter was selected
for i = 1:length(ud.lines)
allLines = struct2cell(ud.lines(i));
allLines = [allLines{:}];
if any(allLines==l)
ud.focusIndex = i;
break
end
end
set(fig,'userdata',ud)
% Setting XY limits here causes redrawing of the plot when you
% click on the line - try to avoid this in the future
set(ax,'ylimmode','auto','xlimmode','auto')
bounds.xlim = get(ax,'xlim');
bounds.ylim = get(ax,'ylim');
set(ax,'ylim',ylim,'xlim',xlim)
if ud.prefs.tool.ruler & (ax == ud.mainaxes)
invis = [ud.ruler.lines ud.ruler.markers];
else
invis = [];
end
limchange = panfcn('erasemode',erasemode,'bounds',bounds,...
'invisible',invis,'immediate',0);
plotIndex = find(ax == ud.ht.a);
if limchange
ud = filtview('setudlimits',ud,ud.ht.a,plotIndex);
set(fig,'userdata',ud);
end
if ud.prefs.tool.ruler & (ax == ud.mainaxes) & ...
(oldFocusIndx==ud.focusIndex) & flisequal(fig,ud.focusline,l)
% just dragging the line (where rulers are focused) around
ruler('newlimits',fig,plotIndex)
ruler('showlines',fig)
elseif ud.prefs.tool.ruler % Move rulers to new line
% Line chosen in new axes, hence, make new axes the mainaxes
if (ax ~= ud.mainaxes)
ud.mainaxes = ax;
set(fig,'userdata',ud)
end
ud = get(fig,'userdata');
realFilterFlag = (isreal(ud.filt(ud.focusIndex).tf.num) &...
isreal(ud.filt(ud.focusIndex).tf.den));
rulerPopVal = plotIndex;
% Make sure that ruler popup is updated correctly when changing
% from a real filter to a complex filter and vice versa.
realDataFlag = realdataFlag(l,ud.lines,ud.focusIndex);
if ~realFilterFlag
if realDataFlag % the real part was chosen
if (plotIndex == 6)
rulerPopVal = plotIndex + 1;
end
else % the imaginary part was chosen
switch plotIndex
case 5, rulerPopVal = 6;
case 6, rulerPopVal = 8;
end
end
end
% Don't set the string of the ruler popup if it hasn't changed;
% in case we're viewing only real or complex filters
oldRealFilterFlag = (isreal(ud.filt(oldFocusIndx).tf.num) &...
isreal(ud.filt(oldFocusIndx).tf.den));
if (oldRealFilterFlag ~= realFilterFlag)
newPlottitles = filtview('plotTitles',realFilterFlag);
updateRulrPopupList(fig,newPlottitles,ud.ht.a,...
ud.mainaxes,realFilterFlag)
end
str = ruler('getpopup',fig);
ruler('setpopup',fig,str,rulerPopVal)
ud.focusline = setFocusLine(ud.mainaxes,ud.lines,...
plotIndex,ud.focusIndex,realDataFlag);
set(fig,'userdata',ud)
ud = get(fig,'userdata');
ud = filtview('setudlimits',ud,ud.ht.a,plotIndex);
set(fig,'userdata',ud)
ruler('newaxes',fig,plotIndex,ud.mainaxes)
noTrackZeroPole(fig,ud)
else
realDataFlag = realdataFlag(l,ud.lines,ud.focusIndex);
plotIndex = find(ax == ud.ht.a);
ud.focusline = setFocusLine(ud.mainaxes,ud.lines,...
plotIndex,ud.focusIndex,realDataFlag);
set(fig,'userdata',ud)
end
if ax == ud.ht.a(4) & limchange
xlim = get(ud.ht.a(4),'xlim');
ylim = get(ud.ht.a(4),'ylim');
set(get(ud.ht.a(4),'xlabel'),'userdata',[xlim ylim]);
end
end
ud = get(fig,'userdata');
bringToFront(fig,ud.focusIndex)
sptlegend('setvalue',ud.focusline,ud.focusIndex,1,fig)
set(ud.legend.legendline,'linestyle', ...
ud.filt(ud.focusIndex).lineinfo.linestyle)
%------------------------------------------------------------------------
% enable = filtview('selection',action,msg,SPTfig)
% respond to selection change in SPTool
% possible actions are
% 'view'
% Button is enabled when
% a) there is a filter selected
%
case 'selection'
msg = varargin{3};
SPTfig = varargin{4};
fig = findobj('type','figure','tag','filtview');
% get all filters (f) and the indexes (ind) of the selected filters
[f,ind] = sptool('Filters',1,SPTfig);
if isempty(f(ind))
varargout{1} = 'off';
else
varargout{1} = 'on';
end
if ~isempty(fig) % update filter viewer
ud = get(fig,'userdata');
switch msg
case 'label'
if ~isempty(ud.filt)
oldFiltLabels = {ud.filt.label};
newFiltLabels = {f(ind).label};
% make sure FILTER (not signal or spectrum) has changed
% its label
if ~isequal(oldFiltLabels,newFiltLabels)
sptlegend('setstring',newFiltLabels,{},fig,1)
for i=1:length(ud.filt)
ud.filt(i).label = f(ind(i)).label;
end
set(fig,'userdata',ud)
[FsStr filtLabelStr] = filtFsLabelStrs(ud.prefs,ud.ht,ud.filt);
set(ud.ht.filterLabel,'string',filtLabelStr)
end
end
return
case 'Fs'
if any([ud.filt.Fs] ~= [f(ind).Fs]) % Filter's Fs has changed
filtIndx = find([ud.filt.Fs] ~= [f(ind).Fs]);
oldFs = ud.filt(filtIndx).Fs;
newFs = f(ind(filtIndx)).Fs;
ud.filt(filtIndx).Fs = newFs;
ud.filt(filtIndx).f = ud.filt(filtIndx).f*(newFs/oldFs);
ud.filt(filtIndx).t = ud.filt(filtIndx).t/(newFs/oldFs);
oldMaxFs = ud.prefs.Fs;
newMaxFs = sprintf('%.9g',max([f(ind).Fs]));
if ~strcmp(newMaxFs, oldMaxFs)
ud.prefs.Fs = newMaxFs;
[FsStr filtLabelStr]=filtFsLabelStrs(ud.prefs,ud.ht,ud.filt);
set(ud.ht.Fsedit,'string',FsStr)
axesScale = str2num(newMaxFs)/str2num(oldMaxFs);
for i = 1:3
oldXlim = get(ud.ht.a(i),'xlim');
set(ud.ht.a(i),'xlim',oldXlim*axesScale)
end
for i = 5:6
oldXlim = get(ud.ht.a(i),'xlim');
set(ud.ht.a(i),'xlim',oldXlim/axesScale)
end
end
set(fig,'userdata',ud)
h = struct2cell(ud.lines(filtIndx)); % Handles to lines
h = [h{:}];
for i = 1:3
hi = findobj(h,'parent',ud.ht.a(i));
for j = 1:length(hi)
set(hi(j),'xdata',get(hi(j),'xdata')*newFs/oldFs)
end
end
for i = 5:6
hi = findobj(h,'parent',ud.ht.a(i));
for j = 1:length(hi)
set(hi(j),'xdata',get(hi(j),'xdata')*oldFs/newFs)
end
end
if (filtIndx == ud.focusIndex) | ~strcmp(newMaxFs,oldMaxFs)
% If on mainaxes fix ruler position
plotIndex = find(ud.mainaxes == ud.ht.a);
ruler('newlimits',fig,plotIndex)
ruler('newsig',fig,plotIndex)
end
return
end % Filter's Fs has changed
end
if ~isequal(f(ind),ud.filt)
need_update = 1:length(ind);
if isempty(ind) % No filters in SPTool
set(ud.ht.Fsedit,'string','')
set(ud.ht.filterLabel,'string',['Filter: <none>'])
ud.filt = [];
for n = 1:length(ud.lines)
h = struct2cell(ud.lines(n));
h = [h{:}];
delete(h)
end
ud.lines = [];
if ud.prefs.tool.ruler
ud.focusline = [];
ud.focusIndex = [];
set(fig,'userdata',ud)
ruler('newsig',fig) % sets the ruler values
ud = get(fig,'userdata');
end
else % New filter selected/created
if ~isempty(ud.filt)
% Find filters which need freq. response computed
% (don't include filters that were previously selected
% whose freq. response haven't changed)
newFiltSelection = f(ind);
[need_update,ud.lines,ud.focusIndex] = ...
redundantFilters(newFiltSelection,ud.filt,...
ud.lines,ud.focusIndex);
else
% Selecting a filter after un-selecting all filters
ud.lines = emptyLinesStruct;
ud.lines(length(f(ind))) = ud.lines(1);
ud.focusIndex = 1;
end
ud.filt = f(ind);
plotIndex = find(ud.mainaxes == ud.ht.a);
ud.prefs.Fs = sprintf('%.9g',max([f(ind).Fs]));
[FsStr filtLabelStr] = filtFsLabelStrs(ud.prefs,ud.ht,ud.filt);
set(ud.ht.filterLabel,'string',filtLabelStr)
set(ud.ht.Fsedit,'string',FsStr)
for i=1:length(ud.filt) % Loop through the selected filters
% delete complex imp/step lines if filter is real, in case
% we are changing from a complex to a real filter
realFilterFlag = (isreal(ud.filt(i).tf.num) & ...
isreal(ud.filt(i).tf.den));
if realFilterFlag
if ~isempty(ud.lines(i).impc)
delete([ud.lines(i).impc ud.lines(i).impstemc])
ud.lines(i).impc = [];
ud.lines(i).impstemc = [];
end
if ~isempty(ud.lines(i).stepc)
delete([ud.lines(i).stepc ud.lines(i).stepstemc])
ud.lines(i).stepc = [];
ud.lines(i).stepstemc = [];
end
end
end % looping through selected filters
end % new filter(s) selected/created
set(fig,'userdata',ud)
% Make sure that ruler popup is updated correctly when changing
% from a real filter to a complex filter and vice versa.
if ud.prefs.tool.ruler & ~isempty(ud.filt(ud.focusIndex))
realFilterFlag = (isreal(ud.filt(ud.focusIndex).tf.num) &...
isreal(ud.filt(ud.focusIndex).tf.den));
currentPopupVal = get(ud.ruler.hand.rulerpopup,'value');
newPlottitles = filtview('plotTitles',realFilterFlag);
newPopupVal = cmplxFiltPopupVal(currentPopupVal, ...
newPlottitles, ud.prefs.plottitles);
ud.prefs.plottitles = newPlottitles;
set(fig,'userdata',ud)
updateRulrPopupList(fig,newPlottitles,ud.ht.a,...
ud.mainaxes,realFilterFlag)
str = ruler('getpopup',fig);
ruler('setpopup',fig,str,newPopupVal)
end
% Set line color and style for each new filter selected
ud = get(fig,'userdata');
for i = 1:length(ud.filt) % loop through selected filters
if isempty(ud.filt(i).lineinfo)
% assign next available line color and style
[ud.filt(i).lineinfo,ud.colorCount] = ...
nextcolor(ud.colororder,ud.linestyleorder, ...
ud.colorCount);
% poke back into SPTool
if nargin > 3
sptool('import',ud.filt(i),0,varargin{4})
else
sptool('import',ud.filt(i))
end
end % if-empty lineinfo
end % loop through selected filters
set(fig,'userdata',ud);
% Don't allow rulers to affect maximum axes limits computations
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -