📄 fdutil.m
字号:
function varargout = fdutil(varargin)
%FDUTIL Utilities for Filter Design Modules.
% This function consists of local functions useful to several
% filter designer modules.
% Author: T. Krauss
% Copyright (c) 1988-98 by The MathWorks, Inc.
% $Revision: 1.7 $
if (nargout == 0)
feval(varargin{:});
else
[varargout{1:nargout}] = feval(varargin{:});
end
function f = changeFilterType(newtype,oldtype,f)
% changeFilterType
% Summary:
% Find new frequency vector when changing from one band configuration
% to another. This is used when the user selects the popup which says
% "make this bandpass filter into a lowpass filter!" (or from any
% of the 4 types to any of the others
% Inputs:
% newtype - integer, contains new filter type: 1 = lp, 2 = hp, 3 = bp, 4 = bs
% oldtype - integer, contains previous filter type
% if oldtype == newtype on entry, f is unchanged
% f - band edge frequency vector, either 2 or 4 elements in ascending order
% depending on oldtype. For bandpass and bandstop filters, will
% have 4 elements, for low and highpass, 2 elements.
% Assumed normalized so 1.0 == Nyquist
% Outputs:
% f - new frequency vector
f = f(:).';
if newtype~=oldtype
switch newtype
case 1 % to lowpass
if oldtype == 3 % from bandpass
f(1:2) = [];
elseif oldtype == 4 % from bandstop
f(3:4) = [];
end
case 2 % to highpass
if oldtype == 3 % from bandpass
f(3:4) = [];
elseif oldtype == 4 % from bandstop
f(1:2) = [];
end
case 3 % to bandpass
if oldtype == 1 % from lowpass
splitwidth = .15;
xd = [0 f(1)];
dxd = diff(xd);
xd = xd(1)+dxd/2 + [-dxd*splitwidth/2; dxd*splitwidth/2];
f = [ xd(:); f(:)];
elseif oldtype == 2 % from highpass
splitwidth = .15;
xd = [f(2) 1];
dxd = diff(xd);
xd = xd(1)+dxd/2 + [-dxd*splitwidth/2; dxd*splitwidth/2];
f = f(1:2);
f = [ f(:); xd(:)];
end
case 4 % to bandstop
if oldtype == 1 % from lowpass
splitwidth = .15;
xd = [f(2) 1];
dxd = diff(xd);
xd = xd(1)+dxd/2 + [-dxd*splitwidth/2; dxd*splitwidth/2];
f = f(1:2);
f = [ f(:); xd(:)];
elseif oldtype == 2 % from highpass
splitwidth = .15;
xd = [0 f(1)];
dxd = diff(xd);
xd = xd(1)+dxd/2 + [-dxd*splitwidth/2; dxd*splitwidth/2];
f = [ xd(:); f(:)];
end
end
end
f = f(:);
function hlabel = newlabel(h,label,pos,enclosingFrame,hlabel)
% Creates a new label for the specification or measurement with HG handle h
% Also sets positions of h and hlabel.
% Inputs:
% h - handle to original object
% label - string for label
% pos - userdefined position, can be either 1, 2 or 4 elements:
% length 1 - scalar specifying position in enclosingFrame (1 == top slot,
% 2 == next slot, etc)
% length 2 - [i1 i2] means this is a frame taking slots i1 through i2
% length 4 - regular HG position rect
% enclosingFrame - either ud.ht.specFrame or ud.ht.measFrame
% hlabel - already existing handle of label - optional - defaults to []
% Outputs:
% hlabel - HG handle to label - will be invisible if label is ''
%
if nargin < 5
hlabel = uicontrol('parent',get(h,'parent'),'style','text',...
'string',label,'tag',get(h,'tag'));
set(hlabel,'userdata',h) % user data contains handle of 'parent' object
else
set(hlabel,'string',label,'visible','on','userdata',h,'tag',get(h,'tag'))
end
[pos2,pos1] = specpos(pos,h,hlabel,enclosingFrame);
set(h,'position',pos2)
set(hlabel,'position',pos1)
% save a pointer to label's corresponding uicontrol in the
% label's userdata. This will be used for help clicks on
% the label (see fdhelpstr).
set(hlabel,'userdata',h)
function [pos2,pos1] = specpos(pos,h,hlabel,enclosingFrame)
% Inputs:
% pos - either integer, 2 element, or 4 element position vect
% h - handle of uicontrol
% hlabel - handle of uicontrol's label
% enclosingFrame - handle to frame encompassing objects
% Outputs:
% pos2 - position of main uicontrol
% pos1 - position of label uicontrol
fig = get(enclosingFrame,'parent');
ud = get(fig,'userdata');
sz = ud.sz;
% compute position:
if length(pos)==1 % position at appropriate place in spec area
sfp = get(enclosingFrame,'position');
pos = [sfp(1)+4 sfp(2)+sfp(4)-(sz.uh+sz.fus)*(pos+1)+sz.fus sfp(3)-8 sz.uh];
elseif length(pos)==2 % 2 element vector - position for
% frame object...
% [p1 p2] - label takes up p1, encloses fdspecs in p1+1 : p2
sfp = get(enclosingFrame,'position');
p1 = pos(1);
p2 = pos(2);
pos = [sfp(1)+2 sfp(2)+sfp(4)-(sz.uh+sz.fus)*(p2+1) sfp(3)-4 ...
(sz.uh+sz.fus)*(p2-p1)+sz.uh/2];
else
% use position as passed in by user
% pos = pos;
end
ext = get(hlabel,'extent');
label = get(hlabel,'string');
if ~strcmp(get(h,'style'),'frame')
if ~isempty(label)
pos1 = [pos(1) pos(2) ext(3)+2 pos(4)];
pos2 = [pos1(1)+pos1(3)+2 pos(2) pos(3)-(pos1(3)+2) pos(4)];
else
pos1 = [pos(1)-2 pos(2) 1 pos(4)];
pos2 = pos;
set(hlabel,'visible','off')
end
switch computer
case 'MAC2'
pos1Tweak = [0 3 0 -6];
switch get(h,'style')
case 'text'
pos2Tweak = [0 3 0 -6];
case 'popupmenu'
pos2Tweak = [0 1 0 -2];
otherwise
pos2Tweak = [0 0 0 0];
end
case 'PCWIN'
pos1Tweak = [0 0 0 0];
switch get(h,'style')
case 'text'
pos2Tweak = [0 0 0 0];
case 'edit'
pos2Tweak = [0 0 0 1];
case 'popupmenu'
pos2Tweak = [0 0 0 0];
otherwise
pos2Tweak = [0 0 0 0];
end
otherwise
pos1Tweak = [0 0 0 0];
pos2Tweak = [0 0 0 0];
end
else % it's a frame
if strcmp(computer,'MAC2')
lh = 12;
else
lh = ext(4); % label height
end
pos1 = [pos(1)+sz.lfs pos(2)+pos(4)-lh/2 ext(3) lh];
pos2 = pos;
set(hlabel,'horizontalalignment','center')
switch computer
case 'MAC2'
pos1Tweak = [0 0 0 0];
pos2Tweak = [0 0 0 0];
case 'PCWIN'
pos1Tweak = [0 0 0 0];
pos2Tweak = [0 0 0 0];
otherwise
pos1Tweak = [1 -3 2 0];
pos2Tweak = [0 0 0 0];
end
end
pos1 = pos1 + pos1Tweak;
pos2 = pos2 + pos2Tweak;
function str = formattedstring(obj)
% Return formatted string for specifications or measurement object
% Inputs:
% obj - structure with .h field
% .h is a HG handle whos userdata struct contains the following fields:
% .value - real number, value of object
% .format - format string, e.g. '%1.5g'
% Outputs:
% str - formatted string
objud = get(obj.h,'userdata');
if ~isreal(objud.value)
str = sprintf([objud.format '+' objud.format 'i'],...
real(objud.value),imag(objud.value));
else
str = sprintf(objud.format,objud.value);
end
function sendToBack(fig,h)
%sendToBack
% reorders children of figure fig so that handles in handle vector h
% are on the bottom
if isempty(h),
return
end
ch = allchild(fig);
ch = ch(:);
h = h(:);
ch1 = ch;
for i=1:length(h)
ch1(find(ch1==h(i))) = [];
end
ch1 = [ch1(:); h];
if ~isequal(ch,ch1) % avoid redraw if child order hasn't changed
set(fig,'children',ch1(:))
end
function [MinOrdCheckbox,bandpop,order,pbspecs,sbspecs,...
pbmeasures,sbmeasures,passframe,stopframe,...
passframe1,stopframe1,ax,Lresp,L1,L2,order1,L3_1,L3_2] = commonObjects
% finds or creates objects common to filtdes modules
% fdremez
% fdkaiser
% fdfirls
% fdbutter
% fdcheby1
% fdcheby2
% fdellip
% Deletes any objects not in output list
% TPK, 6/24/97
S = filtdes('findobj','fdspec');
if ~isempty(S)
s = struct(S); s = [s.h];
c = findobj(s,'tag','minordcheckbox');
if ~isempty(c)
mocb_ind = find(c==s);
else
mocb_ind = [];
end
else
mocb_ind = [];
end
if ~isempty(mocb_ind)
% find all the other objects
M = filtdes('findobj','fdmeas');
m = struct(M); m = [m.h];
order_ind = find(findobj(s,'tag','order')==s);
bandpop_ind = find(findobj(s,'tag','bandpop')==s);
passframe_ind = find(findobj(s,'tag','passframe')==s);
stopframe_ind = find(findobj(s,'tag','stopframe')==s);
passframe1_ind = find(findobj(m,'tag','passframe1')==m);
stopframe1_ind = find(findobj(m,'tag','stopframe1')==m);
pb1_ind = find(findobj(s,'tag','pb1')==s);
pb2_ind = find(findobj(s,'tag','pb2')==s);
pb3_ind = find(findobj(s,'tag','pb3')==s);
sb1_ind = find(findobj(s,'tag','sb1')==s);
sb2_ind = find(findobj(s,'tag','sb2')==s);
sb3_ind = find(findobj(s,'tag','sb3')==s);
order1_ind = find(findobj(m,'tag','order1')==m);
pbm1_ind = find(findobj(m,'tag','pbm1')==m);
pbm2_ind = find(findobj(m,'tag','pbm2')==m);
pbm3_ind = find(findobj(m,'tag','pbm3')==m);
sbm1_ind = find(findobj(m,'tag','sbm1')==m);
sbm2_ind = find(findobj(m,'tag','sbm2')==m);
sbm3_ind = find(findobj(m,'tag','sbm3')==m);
MinOrdCheckbox = S(mocb_ind);
order = S(order_ind);
bandpop = S(bandpop_ind);
passframe = S(passframe_ind);
stopframe = S(stopframe_ind);
passframe1 = M(passframe1_ind);
stopframe1 = M(stopframe1_ind);
pb1 = S(pb1_ind);
pb2 = S(pb2_ind);
pb3 = S(pb3_ind);
sb1 = S(sb1_ind);
sb2 = S(sb2_ind);
sb3 = S(sb3_ind);
order1 = M(order1_ind);
pbm1 = M(pbm1_ind);
pbm2 = M(pbm2_ind);
pbm3 = M(pbm3_ind);
sbm1 = M(sbm1_ind);
sbm2 = M(sbm2_ind);
sbm3 = M(sbm3_ind);
% need to delete other objects here that are not common
Sind = 1:length(S);
Sind([mocb_ind order_ind bandpop_ind passframe_ind ...
stopframe_ind pb1_ind pb2_ind pb3_ind sb1_ind sb2_ind sb3_ind]) = [];
delete(S(Sind))
A = filtdes('findobj','fdax');
a = struct(A); a = [a.h];
ax_ind = find(findobj(a,'tag','ax')==a);
ax = A(ax_ind);
Aind = 1:length(A);
Aind(ax_ind) = [];
delete(A(Aind)) % also deletes lines
L = filtdes('findobj','fdline');
l = struct(L); l = [l.h];
L1_ind = find(findobj(l,'tag','passband')==l); L1 = L(L1_ind);
L2_ind = find(findobj(l,'tag','stopband')==l); L2 = L(L2_ind);
Lresp_ind = find(findobj(l,'tag','response')==l); Lresp = L(Lresp_ind);
L3_1_ind = find(findobj(l,'tag','L3_1')==l); L3_1 = L(L3_1_ind);
L3_2_ind = find(findobj(l,'tag','L3_2')==l); L3_2 = L(L3_2_ind);
Lind = 1:length(L);
Lind([L1_ind L2_ind Lresp_ind L3_1_ind L3_2_ind]) = [];
delete(L(Lind)) % also deletes lines
Mind = 1:length(M);
Mind([passframe1_ind stopframe1_ind order1_ind pbm1_ind pbm2_ind pbm3_ind ...
sbm1_ind sbm2_ind sbm3_ind]) = [];
delete(M(Mind))
% make sure certain objects are visible:
makeVisList = {MinOrdCheckbox,bandpop,...
passframe,stopframe,...
passframe1,stopframe1,ax,Lresp,L1,L2};
for i=1:length(makeVisList)
set(makeVisList{i},'visible','on')
end
else % if radio1 not created, assume none of the others are either
% clear tool in this case
filtdes('clear')
passframe = fdspec('style','frame',...
'tag','passframe',...
'position',[4 7],'label','Passband',...
'help','fdobjhelp');
stopframe = fdspec('style','frame','position',[8 11],'label','Stopband',...
'tag','stopframe',...
'help','fdobjhelp');
MinOrdCheckbox = fdspec('style','checkbox','string','Minimum Order',...
'value',1,...
'tag','minordcheckbox','position',1,...
'help','fdobjhelp');
order = fdspec('style','edit','label','Order','tag','order','integer',1,...
'range',[0 Inf],'position',2,...
'help','fdobjhelp');
bandpop = fdspec('style','popupmenu',...
'string',{'lowpass' 'highpass' 'bandpass' 'bandstop'},...
'label','Type',...
'tag','bandpop','position',3,...
'help','fdobjhelp');
passframe1 = fdmeas('style','frame','position',[4 7],'label','Passband',...
'tag','passframe1',...
'help','fdobjhelp');
stopframe1 = fdmeas('style','frame','position',[8 11],'label','Stopband',...
'tag','stopframe1',...
'help','fdobjhelp');
order1 = fdmeas('style','text','label','Order','tag','order1',...
'position',2,'integer',1,...
'range',[0 Inf],...
'help','fdobjhelp');
fstr = '%1.4g';
pb1 = fdspec('style','edit','position',5,'tag','pb1','format',fstr,...
'help','fdobjhelp');
pb2 = fdspec('style','edit','position',6,'tag','pb2','format',fstr,...
'help','fdobjhelp');
pb3 = fdspec('style','edit','position',7,'tag','pb3','format',fstr,...
'help','fdobjhelp');
sb1 = fdspec('style','edit','position',9,'tag','sb1','format',fstr,...
'help','fdobjhelp');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -