📄 spectview.m
字号:
% resize flag
rbrowse = 0;
% enable / disable ruler
if ud.prefs.tool.ruler~=newprefs.tool.ruler
if newprefs.tool.ruler
% turn ruler on
rulerPrefs = sptool('getprefs','ruler');
typeStr = {'vertical','horizontal','track','slope'};
ud.prefs.ruler.type = typeStr{rulerPrefs.initialType};
set(fig,'userdata',ud)
ruler('init',fig)
ud = get(fig,'userdata');
ud.ruler.evenlySpaced = 0;
set(fig,'userdata',ud)
ruler('showlines',fig)
ruler('newlimits',fig)
ruler('newsig',fig)
else
ruler('close',fig)
end
ud = get(fig,'userdata');
rbrowse = 1;
end
% resize objects if necessary:
if rbrowse,
spresize(0,fig)
if newprefs.tool.ruler
ruler('resizebtns',fig)
end
end
switch p.magscale
case 1 % 'db'
spectview('magscale','db',fig,0)
case 2 % 'linear'
spectview('magscale','lin',fig,0)
end
switch p.freqscale
case 1 % linear
spectview('freqscale','lin',fig,0)
case 2 % log
spectview('freqscale','log',fig,0)
end
switch p.freqrange
case 1 % half
spectview('freqrange','half',fig,0)
case 2 % whole
spectview('freqrange','whole',fig,0)
case 3 % neg
spectview('freqrange','neg',fig,0)
end
end
ud.prefs = newprefs;
set(fig,'userdata',ud)
end
otherwise
% string not recognized
disp(sprintf('spectview: %s',varargin{1}))
end
function changeParamType(type,val,label,popupString,labelHand,uicontrolHand)
%Changes type (if necessary) of uicontrolHand ...
% also changes visibility of label, and position, if necessary
% and also, the value of the uicontrol
%Inputs:
% type - string; may be 'edit' 'popupmenu' 'checkbox' 'radiobutton'
% val - string or integer; used to set the uicontrol's value
% label - string; ignored in case type == 'checkbox' or 'radiobutton'
% popupString - cell array of strings; in case type == 'popupmenu',
% the uicontrol's string will be set to this
% labelHand - handle to label
% uicontrolHand - handle to uicontrol
set(uicontrolHand,'visible','on')
if ~strcmp(type,get(uicontrolHand,'type')) % need to change type
uibgcolor = get(0,'defaultuicontrolbackgroundcolor');
set(uicontrolHand,'style',type)
switch type
case 'edit'
if isempty(label)
set(uicontrolHand,'visible','off')
end
set(uicontrolHand,'backgroundcolor','w',...
'horizontalalignment','left',...
'string',val)
set(labelHand,'visible','on','string',label)
case {'checkbox','radiobutton'}
set(uicontrolHand,'backgroundcolor',uibgcolor,...
'horizontalalignment','center',...
'string',label,...
'min',0,'max',1,...
'value',val)
set(labelHand,'visible','off')
case 'popupmenu'
set(uicontrolHand,'backgroundcolor',uibgcolor,...
'horizontalalignment','center',...
'string',popupString,...
'min',1,'max',length(popupString),...
'value',val)
set(labelHand,'visible','on','string',label)
otherwise
set(uicontrolHand,'backgroundcolor',uibgcolor,...
'horizontalalignment','center')
set(labelHand,'visible','on','string',label)
end
spresize('paramPosition',uicontrolHand)
else % don't need to change type or position, but still need to
% change values and strings
switch type
case 'edit'
if isempty(label)
set(uicontrolHand,'visible','off')
end
set(uicontrolHand,'string',val)
set(labelHand,'visible','on','string',label)
case {'checkbox','radiobutton'}
set(uicontrolHand,'value',val,'string',label)
case 'popupmenu'
set(uicontrolHand,'string',popupString,'value',val)
set(labelHand,'visible','on','string',label)
otherwise
set(labelHand,'visible','on','string',label)
end
end
function yd = spmagfcn(yd,magscale);
% Converts yd to dB if magscale == 1
if magscale == 1
yd = 10*log10(yd);
end
function label = uniqueDefaultLabel(labelList,defaultLabel)
% Inputs:
% labelList - list of strings
% defaultLabel - string; such as 'sig','filt'
% Output:
% label - unique identifier such as 'sig1', 'sig2'
i=1;
label = [defaultLabel sprintf('%.9g',i)];
while ~isempty(findcstr(labelList,label))
i=i+1;
label = [defaultLabel sprintf('%.9g',i)];
end
function [errstr,spect] = computeSpectrum(methods,spect);
%computeSpectrum
% Attempts to compute Power Spectrum based on input spect structure
% Inputs:
% methods - structure array; as returned from spregistry
% spect - spectrum structure
% Outputs:
% errstr - empty if no error; otherwise contains string indicating
% what went wrong
% spect - updated spectrum structure; spect.f,spect.P, and possibly
% spect.confid.Pc are changed
errstr = '';
methodName = spect.specs.methodName{spect.specs.methodNum};
ToolMethodNum = findcstr({methods.methodName},methodName);
valueArray = spect.specs.valueArrays{spect.specs.methodNum};
labels = methods(ToolMethodNum).label;
for i=1:length(valueArray)
for j=methods(ToolMethodNum).subordinates{i}
labels{j} = labels{j}{valueArray{i}};
end
end
for i=1:length(valueArray)
% evaluate strings
if isstr(valueArray{i}) & ~isempty(labels{i})
[valueArray{i},err] = getWorkspaceVariable(valueArray{i});
if err==1
errstr = sprintf('Sorry, couldn''t evaluate ''%s''.',labels{i});
return
elseif err == 2
errstr = ...
sprintf('Sorry, you must specify a value for ''%s''.',labels{i});
return
end
end
end
sigStruc = sptool('Signals');
sigInd = findcstr({sigStruc.label},spect.signalLabel);
sigdata = sigStruc(sigInd).data;
if spect.confid.enable & methods(ToolMethodNum).confidenceFlag
[confidenceLevel,err] = getWorkspaceVariable(spect.confid.level);
if err==1
errstr = 'Sorry, couldn''t evaluate the Confidence Level.';
return
elseif err == 2
errstr = 'Sorry, you must specify a Confidence Level.';
return
end
[errstr,spect.P,spect.f,spect.confid.Pc] = ...
feval(methods(ToolMethodNum).computeFcn,sigdata,spect.Fs,...
valueArray,confidenceLevel);
else
[errstr,spect.P,spect.f] = ...
feval(methods(ToolMethodNum).computeFcn,sigdata,spect.Fs,...
valueArray);
end
function varargout = getWorkspaceVariable(varargin)
%getWorkspaceVariable
% [var,err] = getWorkspaceVariable(varName)
% Returns the var 'varName' in the workspace.
% err = 2 if the string is empty,
% 1 if there is an error in evaluating the string,
% 0 if OK
if isempty(varargin{1})
varargout{1} = [];
varargout{2} = 2;
return
end
err = 0;
varargout{1} = evalin('base',varargin{1},'''ARBITRARY_STRING''');
if isequal(varargout{1},'ARBITRARY_STRING')
err = 1;
end
if err
varargout{1} = [];
end
varargout{2}=err;
function inheritList = newInheritString(inheritPopup,labelList,maxPopupEntries)
%newInheritString
% Sets popup string to the given labelList
% Inputs:
% inheritPopup - handle to popupmenu
% labelList - cell array of strings
% maxPopupEntries - maximum number of entries in a popupmenu
% On output:
% String will be
% {'Inherit from' label1 label2 ... labelN} if N<=maxPopupEntries-1
% and inheritList will contain []
% OR
% {'Inherit from' label1 label2 ... labelM 'More...'} if N>maxPopupEntries-1
% and inheritList will contain labelList
% where M = maxPopupEntries-2
N = length(labelList);
if N>maxPopupEntries-1
set(inheritPopup,'string',{'Inherit from' labelList{1:maxPopupEntries-2} ...
'More...'})
inheritList = labelList;
else
set(inheritPopup,'string',{'Inherit from' labelList{:}})
inheritList = [];
end
function bringToFront(fig,h)
%bringToFront
% reorders children of ud.mainaxes so that
% the objects with handles in h are just above all the objects
% except for the ruler lines
ud = get(fig,'userdata');
ch = get(ud.mainaxes,'children');
ch = ch(:);
if ud.prefs.tool.ruler
% make sure ruler lines are on top of stacking order
h = [ud.ruler.lines(:); ud.ruler.markers(:); h(:)];
else
h = h(:);
end
ch1 = ch;
for i=1:length(h)
ch1(find(ch1==h(i))) = [];
end
ch1 = [h; ch1(:)];
if ~isequal(ch,ch1) % avoid redraw if child order hasn't changed
set(ud.mainaxes,'children',ch1(:))
end
function c = confidPatchColor(c)
%confidPatchColor
% c = confidPatchColor(c) returns the color (an rgb triple) for a
% confidence interval corresponding
% to a line of color c.
c = .5*c;
function spzoomout(ud,xflag,rulerFlag)
% reset limits of mainaxes, and set Full View limits (ud.limits field)
% Inputs:
% ud - userdata struct
% xflag - 1 ==> zoom out in x
% 0 ==> keep xlimits the same
% rulerFlag (optional) - 1 ==> update rulers (default)
% 0 ==> don't update rulers
% CAUTION: Sets figure userdata !!!!!
if nargin < 3
rulerFlag = 1;
end
fig = get(ud.mainaxes,'parent');
% turn off rulers for limits calculation:
if ud.prefs.tool.ruler
h = [ud.ruler.lines(:); ud.ruler.markers(:)];
set(h,'visible','off')
end
% zoom out
set(ud.mainaxes,'ylimmode','auto')
if isempty(ud.spect)
xlim = get(ud.mainaxes,'xlim');
ylim = get(ud.mainaxes,'ylim');
elseif xflag % FULL VIEW
Fs = maxFs(ud.spect);
checks = get(ud.hand.freqrangeMenu,'checked');
checkInd = findcstr(checks,'on');
xlim = xRange(checkInd,Fs);
ud.limits.xlim = xlim;
set(ud.mainaxes,'xlim',xlim)
ylim = get(ud.mainaxes,'ylim');
ud.limits.ylim = ylim;
else % only zoom out Y, but update ud.limits to FULL VIEW
xlim = get(ud.mainaxes,'xlim');
Fs = maxFs(ud.spect);
checks = get(ud.hand.freqrangeMenu,'checked');
checkInd = findcstr(checks,'on');
ud.limits.xlim = xRange(checkInd,Fs);
set(ud.mainaxes,'xlim',ud.limits.xlim);
ud.limits.ylim = get(ud.mainaxes,'ylim');
set(ud.mainaxes,'xlim',xlim)
ylim = get(ud.mainaxes,'ylim');
end
scaleChecks = get(ud.hand.freqscaleMenu,'checked');
scaleCheckInd = findcstr(scaleChecks,'on');
if scaleCheckInd == 1 % linear scale
xlim = inbounds(xlim,ud.limits.xlim);
else % log scale
xlim = inbounds(xlim,ud.limits.xlim,1);
if ~isempty(get(ud.lines(1).h,'xdata'))
% Make sure that x-axes lower limit is
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -