0001 function pan2param(varargin)
0002
0003
0004
0005
0006
0007
0008 global params selBlocks objName paramEnabled LTPDAinvar noParamsReq functionName paramSets
0009
0010
0011 currPanel = varargin{1};
0012 panelDimens = get(currPanel, 'Position');
0013 backColor = get(currPanel, 'BackgroundColor');
0014 selBlocks = 0;
0015
0016 alltimers = timerfindall;
0017 stop(alltimers(1));
0018 set(alltimers(1),'TimerFcn',@ContinuousParamCheck,'Period',0.3);
0019 start(alltimers(1));
0020
0021
0022
0023
0024 function buildplistFigureParam()
0025
0026 clear params paramEnabled functionName paramSets objName
0027 panelDimens = getappdata(0, 'ltpda_currPanelDimens');
0028 delete(findobj(gcf,'Parent',currPanel))
0029
0030 paramcommand = get_param(gcbh,'Description');
0031 noParamsReq=0;
0032 if isempty(paramcommand)
0033 paramcommand = RetrievePlist();
0034 selBlocks = gcbsh;
0035 for kk=1:length(selBlocks)
0036 set_param(selBlocks(kk),'Description',paramcommand);
0037 end
0038 end
0039
0040 eval(paramcommand)
0041
0042 if ~exist('paramEnabled','var') && isempty(find(params,'Sets')) && noParamsReq==0
0043 paramEnabled = zeros(1,nparams(params));
0044 end
0045 if exist('functionName','var') && ~isempty(functionName)
0046 setappdata(0,'ltpda_currFunctionName',functionName);
0047
0048 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','center','Position',[40 panelDimens(4)-40 100 14],'FontSize',7,'String','Function name:','TooltipString','Function name','Visible','on','Style','text');
0049
0050 uicontrol('Parent',currPanel,'Units','pixels','BackgroundColor',backColor,'HorizontalAlignment','center','Position',[150 panelDimens(4)-40 100 16],'FontSize',7,'String', functionName,'TooltipString','Name of the function','Visible','on','Callback',@functionNameSet,'Style','edit');
0051 panelDimens = getappdata(0, 'ltpda_currPanelDimens');
0052 panelDimens(4) = panelDimens(4)-40;
0053 else
0054 childpath = find_system(gcbh,'LookUnderMasks','all','BlockType','M-S-Function');
0055 setappdata(0,'ltpda_currFunctionName',get_param(childpath,'Tag'));
0056 end
0057
0058 y=nparams(params);
0059
0060 if y==0 && ~exist('paramSets','var') && noParamsReq==0
0061 paramcommand=[paramcommand,'noParamsReq=1;'];
0062 selBlocks = gcbsh;
0063 for kk=1:length(selBlocks)
0064 set_param(selBlocks(kk),'Description',paramcommand);
0065 end
0066 buildplistFigureParam()
0067 end
0068
0069
0070 uicontrol('Parent',currPanel,'Units','pixels','HorizontalAlignment','center','Position',[panelDimens(3)-70 10 60 16],'FontAngle','italic','FontSize',8,'String','?','TooltipString','Open the Help associated to this function','Visible','on','Callback',@HelpButtonCallback,'Style','pushbutton');
0071
0072 uicontrol('Parent',currPanel,'Units','pixels','HorizontalAlignment','center','Position',[20 10 120 16],'FontAngle','italic','FontSize',7,'String','Reset Parameters','TooltipString','Reset the parameters for this block','Visible','on','Callback',@ResetButtonCallback,'Style','pushbutton');
0073
0074 probe = get_param(gcbh,'UserData');
0075 if ~isempty(probe) && isa(probe,'char') && strcmp(probe,'probe')
0076 keepRes = 1;
0077 else
0078 keepRes = 0;
0079 end
0080 uicontrol('Parent',currPanel,'Units','pixels','BackgroundColor',backColor,'HorizontalAlignment','left','Position',[panelDimens(3)-300 10 150 16],'FontAngle','italic','FontSize',8,'String','Keep local result','TooltipString','Do not delete the result of this block at the end of the calculation','Visible','on','Callback',@KeepResultCallback,'Value',keepRes,'Style','checkbox');
0081
0082 setName = get(gcbh,'UserData');
0083 if isempty(setName), setName = 0; end
0084 uicontrol('Parent',currPanel,'Units','pixels','BackgroundColor',backColor,'HorizontalAlignment','left','Position',[panelDimens(3)-500 10 150 16],'FontAngle','italic','FontSize',8,'String','Set name','TooltipString','Set the signal name equal to the block name','Visible','on','Callback',@SetNameCallback,'Value',setName,'Style','checkbox');
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100 if noParamsReq==1
0101
0102 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','center','Position',[150 7 120 16],'String','No parameters required','Visible','on','Style','text');
0103 end
0104
0105
0106
0107 if exist('paramSets','var') && ~isempty(paramSets)
0108 sets = find(paramSets,'sets');
0109 currSet = find(paramSets,'currSet');
0110
0111 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','center','Position',[(panelDimens(4)-300)/2 panelDimens(4)-44 150 20],'String','Possible params sets:','Visible','on','Style','text');
0112
0113 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','center','Position',[(panelDimens(4)-300)/2+150 panelDimens(4)-40 250 20],'String',sets,'Value',currSet,'Visible','on','UserData',sets,'Callback',@SetsUpdate,'Style','popup');
0114 panelDimens(4) = panelDimens(4)-40;
0115 end
0116
0117
0118
0119
0120 totalGaps=0;
0121 for ii=1:y
0122 paramkeys{ii} = params.params(ii).key;
0123 paramvals{ii} = params.params(ii).val;
0124 switch class(paramvals{ii})
0125 case 'pzmodel'
0126 if numel(get(paramvals{ii},'poles'))>1 || numel(get(paramvals{ii},'zeros'))>1
0127 totalGaps=totalGaps+1;
0128 end
0129 case 'miir'
0130 if ~isempty(find(paramvals{ii}.plist,'pzmodel'))
0131 totalGaps=totalGaps+1;
0132 if numel(get(find(paramvals{ii}.plist,'pzmodel'),'poles'))>1 || numel(get(find(paramvals{ii}.plist,'pzmodel'),'zeros'))>1
0133 totalGaps=totalGaps+1;
0134 end
0135 end
0136 case {'pole','zero'}
0137 if numel(paramvals{ii})>1
0138 totalGaps=totalGaps+1;
0139 end
0140 end
0141 end
0142 currGap = 0;
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154 for ii=1:y
0155 paramkeys{ii}=get(params.params(ii),'key');
0156 paramvals{ii}=get(params.params(ii),'val');
0157 addedPar = 0;
0158
0159 objName{ii,1} = uicontrol('Parent',currPanel,'Units','pixels','Position',[10,panelDimens(4)-24*(ii+1+currGap),14,14],'Value',paramEnabled(ii),'Visible','on','Enable','on','Callback', @EnableSetCallback,'Tag',paramkeys{ii},'UserData',ii,'Style','checkbox');
0160
0161 try
0162 if strcmpi(paramkeys{ii}(1:7),'addPar_')
0163 uicontrol('Parent',currPanel,'Units','pixels','Position',[panelDimens(3)-30 panelDimens(4)-24*(ii+1+currGap) 20 20],'String','-','Visible','on','Enable','on','UserData',ii,'Callback', @RemParamCallback,'Style','pushbutton');
0164 addedPar = 1;
0165 paramkeys{ii}(1:7) = [];
0166 end
0167 catch end
0168
0169 switch class(paramvals{ii})
0170
0171
0172 case {'double'}
0173
0174
0175 objName{ii,2} = uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','center','Position',[40 panelDimens(4)-6-24*(ii+1+currGap) 70 20],'String','Name:','FontName','Times New Roman','FontSize',8,'FontWeight','normal','Visible','on','Style','text');
0176
0177 objName{ii,3} = uicontrol('Parent',currPanel,'Units','pixels','Position',[120 panelDimens(4)-24*(ii+1+currGap) 60 20],'String',paramkeys{ii},'Visible','on','Enable','off','UserData',ii,'Callback',@editNameCallback,'Style','edit');
0178 if ~noParamsReq && ~addedPar
0179 set(objName{ii,2},'Visible','off');
0180 set(objName{ii,3},'Style','text','BackgroundColor',backColor,'Position',[50 panelDimens(4)-5-24*(ii+1+currGap) 120 20]);
0181 end
0182
0183
0184 objName{ii,4} = uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[205 panelDimens(4)-6-24*(ii+1+currGap) 40 20],'String','Value:','FontName','Times New Roman','FontSize',8,'FontWeight','normal','Visible','on','Style','text');
0185
0186 data = mat2str(paramvals{ii});
0187 objName{ii,5} = uicontrol('Parent',currPanel,'Units','pixels','Position',[250 panelDimens(4)-24*(ii+1+currGap) 130 20],'String',data,'Visible','on','Enable','off','UserData',ii,'Callback',@editValueCallback,'Style','edit');
0188 objName{ii,6} = uicontrol('TooltipString','Retrieve from Simulink','Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[400 panelDimens(4)-24*(ii+1+currGap) 20 20],'Max',1,'Min',0,'Value',0,'Visible','on','Tag',num2str(ii),'UserData',[],'Callback',@fromSimulinkCallback,'Style','checkbox');
0189
0190
0191 if strcmp(paramvals{ii},'-->')
0192 set(objName{ii,4},'Visible','off');
0193 set(objName{ii,5},'Visible','off');
0194 if addedPar, set(objName{ii,6},'Visible','off'); else set(objName{ii,6},'Value',1); end
0195 objName{ii,8} = uicontrol('TooltipString','Retrieve from Simulink','Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[400 panelDimens(4)-6-24*(ii+1+currGap) 150 20],'String','From Simulink environment','FontName','Times New Roman','FontSize',8,'FontWeight','normal','Visible','on','Style','text');
0196 end
0197
0198
0199 case {'char'}
0200
0201
0202 objName{ii,2} = uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','center','Position',[40 panelDimens(4)-6-24*(ii+1+currGap) 70 20],'String','Name:','FontName','Times New Roman','FontSize',8,'FontWeight','normal','Visible','on','Style','text');
0203
0204 objName{ii,3} = uicontrol('Parent',currPanel,'Units','pixels','Position',[120 panelDimens(4)-24*(ii+1+currGap) 60 20],'String',paramkeys{ii},'Visible','on','Enable','off','UserData',ii,'Callback',@editNameCallback,'Style','edit');
0205 if ~noParamsReq && ~addedPar
0206 set(objName{ii,2},'Visible','off');
0207 set(objName{ii,3},'Style','text','BackgroundColor',backColor,'Position',[50 panelDimens(4)-5-24*(ii+1+currGap) 120 20]);
0208 end
0209
0210
0211 objName{ii,4} = uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[205 panelDimens(4)-6-24*(ii+1+currGap) 40 20],'String','Value:','FontName','Times New Roman','FontSize',8,'FontWeight','normal','Visible','on','Style','text');
0212
0213 objName{ii,5} = uicontrol('Parent',currPanel,'Units','pixels','Position',[250 panelDimens(4)-24*(ii+1+currGap) 130 20],'String',['''',paramvals{ii},''''],'Visible','on','Enable','off','UserData',ii,'Callback',@editValueCallback,'Style','edit');
0214 objName{ii,6} = uicontrol('TooltipString','Retrieve from Simulink','Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[400 panelDimens(4)-24*(ii+1+currGap) 20 20],'Max',1,'Min',0,'Value',0,'Visible','on','Tag',num2str(ii),'UserData',[],'Callback',@fromSimulinkCallback,'Style','checkbox');
0215
0216
0217 if strcmp(paramvals{ii},'-->')
0218 set(objName{ii,4},'Visible','off');
0219 set(objName{ii,5},'Visible','off');
0220 if addedPar, set(objName{ii,6},'Visible','off'); else set(objName{ii,6},'Value',1); end
0221 objName{ii,8} = uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[400 panelDimens(4)-6-24*(ii+1+currGap) 150 20],'String','From Simulink environment','FontName','Times New Roman','FontSize',8,'FontWeight','normal','Visible','on','Style','text');
0222 end
0223
0224
0225 if strcmpi(paramkeys{ii},'filename')
0226 set(objName{ii,6},'Position',[690 panelDimens(4)-24*(ii+1+currGap) 20 20]);
0227 set(objName{ii,5},'Position',[250 panelDimens(4)-24*(ii+1+currGap) 300 20]);
0228 objName{ii,7} = uicontrol('Parent',currPanel,'Units','pixels','Position',[570 panelDimens(4)-24*(ii+1+currGap) 100 20],'String','Browse','Visible','on','Enable','on','UserData',objName{ii,5},'Callback',@browseCallback,'Style','pushbutton');
0229 end
0230
0231
0232 case 'specwin'
0233
0234 selectWind = paramvals{ii}.name;
0235 listWindows = ['Kaiser',specwin('Types')];
0236 selectWindValue = strmatch(selectWind,listWindows,'exact');
0237
0238 objName{ii,2} = uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','center','Position',[40 panelDimens(4)-24*(ii+1+currGap)-5 50 20],'String','Window:','FontName','Times New Roman','FontSize',8,'FontWeight','normal','Visible','on','Style','text');
0239
0240 objName{ii,3} = uicontrol('Parent',currPanel,'Units','pixels','Position',[100 panelDimens(4)-24*(ii+1+currGap) 80 20],'String',listWindows,'TooltipString','Window names','Value',selectWindValue,'Visible','on','Enable','off','Tag',paramkeys{ii},'UserData',ii,'Callback', @WindListCallback,'Style','popupmenu');
0241
0242 objName{ii,4} = uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[205 panelDimens(4)-24*(ii+1+currGap)-5 50 20],'String','Length:','FontName','Times New Roman','FontSize',8,'FontWeight','normal','Visible','on','Style','text');
0243
0244 currLength = num2str(length(get(get(params.params(ii),'val'),'win')));
0245 objName{ii,5} = uicontrol('Parent',currPanel,'Units','pixels','Position',[250 panelDimens(4)-24*(ii+1+currGap) 60 20],'String',num2str(currLength),'TooltipString','Window Length','Visible','on','Enable','off','UserData',ii,'Callback', @WindlengthCallback,'Style','edit');
0246 if strcmp(selectWind,'Kaiser')
0247
0248 objName{ii,6} = uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[320 panelDimens(4)-24*(ii+1+currGap)-5 50 20],'String','PSL:','FontName','Times New Roman','FontSize',8,'FontWeight','normal','Visible','on','Style','text');
0249
0250 currPSL = get(get(params.params(ii),'val'),'psll');
0251 objName{ii,7} = uicontrol('Parent',currPanel,'Units','pixels','Position',[350 panelDimens(4)-24*(ii+1+currGap) 60 20],'String',num2str(currPSL),'TooltipString','Peak Sidelobe','Visible','on','Enable','off','UserData',ii,'Callback',@WindPSLCallback,'Style','edit');
0252 end
0253
0254
0255 case 'pzmodel'
0256
0257 clear pzObj currPoles poleFreqs poleQs poleFQs currZeros zeroFreqs zeroQs zeroFQs
0258 pzObj = get(params.params(ii),'val');
0259 currPoles = get(pzObj,'poles');
0260 currZeros = get(pzObj,'zeros');
0261
0262 objName{ii,2} = uicontrol('Parent',currPanel,'HorizontalAlignment','left','Position',[50 panelDimens(4)-24*(ii+1+currGap) 50 20],'String','Load','FontName','Times New Roman','FontSize',8,'FontWeight','normal','Visible','on','UserData',ii,'Callback',@pzmodelLoad,'Style','pushbutton');
0263
0264 objName{ii,3} = uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[120 panelDimens(4)-24*(ii+1+currGap)-7 40 20],'String','Gain:','FontName','Times New Roman','FontSize',8,'FontWeight','normal','Visible','on','Style','text');
0265
0266 currGain = pzObj.gain;
0267 objName{ii,4} = uicontrol('Parent',currPanel,'Units','pixels','Position',[155 panelDimens(4)-24*(ii+1+currGap) 60 20],'String',num2str(currGain),'Visible','on','Enable','on','UserData',ii,'Callback',@pzmodelGainEdit,'Style','edit');
0268
0269 objName{ii,5} = uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[240 panelDimens(4)-24*(ii+1+currGap)-7 40 20],'String','Poles:','FontName','Times New Roman','FontSize',8,'FontWeight','normal','Visible','on','Style','text');
0270
0271 for kk=1:numel(currPoles)
0272 poleFreqs(kk,1) = get(currPoles(kk),'f');
0273 poleQs(kk,1) = get(currPoles(kk),'q');
0274 if ~isnan(poleQs(kk,1))
0275 poleFQs{kk,1}=strcat(num2str(poleFreqs(kk,1)),',',num2str(poleQs(kk,1)));
0276 else
0277 poleFQs{kk,1}=num2str(poleFreqs(kk,1));
0278 end
0279 end
0280 if numel(currPoles)>1 || numel(currZeros)>1
0281 currGap=currGap+1;
0282 end
0283 poleFQs=char(poleFQs);
0284 objName{ii,6} = uicontrol('Parent',currPanel,'Units','pixels','Position',[275 panelDimens(4)-24*(ii-1+currGap)-47 60 20+(max(numel(currPoles),numel(currZeros))>1)*24],'Max',2,'String',poleFQs,'TooltipString','Insert ''freq'' or ''freq,q'' on multiple lines','Visible','on','Enable','on','UserData',ii,'Callback',@pzmodelPoleEdit,'Style','edit');
0285
0286 objName{ii,7} = uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[355 panelDimens(4)-24*(ii+currGap)-7 40 20],'String','Zeros:','FontName','Times New Roman','FontSize',8,'FontWeight','normal','Visible','on','Style','text');
0287
0288 for kk=1:numel(currZeros)
0289 zeroFreqs(kk,1) = get(currZeros(kk),'f');
0290 zeroQs(kk,1) = get(currZeros(kk),'q');
0291 if ~isnan(zeroQs(kk,1))
0292 zeroFQs{kk,1}=strcat(num2str(zeroFreqs(kk,1)),',',num2str(zeroQs(kk,1)));
0293 else
0294 zeroFQs{kk,1}=num2str(zeroFreqs(kk,1));
0295 end
0296 end
0297 zeroFQs=char(zeroFQs);
0298 objName{ii,8} = uicontrol('Parent',currPanel,'Units','pixels','Position',[390 panelDimens(4)-24*(ii-1+currGap)-47 60 20+(max(numel(currPoles),numel(currZeros))>1)*24],'Max',2,'String',zeroFQs,'TooltipString','Insert ''freq'' or ''freq,q'' on multiple lines','Visible','on','Enable','on','UserData',ii,'Callback',@pzmodelZeroEdit,'Style','edit');
0299
0300
0301 case 'miir'
0302
0303 miirObj = get(params.params(ii),'val');
0304 miirPlist = miirObj.plist;
0305 try
0306 currMiirType = find(miirPlist,'type');
0307 currMiirType = strmatch(currMiirType,{'highpass','lowpass','bandpass','bandreject','pzmodel'});
0308 catch
0309 currMiirType = 5;
0310 end
0311
0312 objName{ii,2} = uicontrol('Parent',currPanel,'HorizontalAlignment','left','Position',[50 panelDimens(4)-24*(ii+1+currGap) 50 20],'String','Load','FontName','Times New Roman','FontSize',8,'FontWeight','normal','Visible','on','UserData',ii,'Callback',@miirLoad,'Style','pushbutton');
0313
0314 objName{ii,3} = uicontrol('Parent',currPanel,'Units','pixels','Position',[120 panelDimens(4)-24*(ii+1+currGap) 80 20],'String',{'highpass','lowpass','bandpass','bandreject','pzmodel'},'Value',currMiirType,'TooltipString','Select the type of filter','Visible','on','Enable','on','UserData',ii,'Callback',@miirTypeEdit,'Style','popupmenu');
0315
0316 objName{ii,4} = uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[220 panelDimens(4)-24*(ii+1+currGap)-7 40 20],'String','Gain:','FontName','Times New Roman','FontSize',8,'FontWeight','normal','Visible','on','Style','text');
0317
0318 currGain = num2str(find(miirPlist,'gain'));
0319 if isempty(currGain), currGain = 'NA'; end
0320 objName{ii,5} = uicontrol('Parent',currPanel,'Units','pixels','Position',[250 panelDimens(4)-24*(ii+1+currGap) 50 20],'String',currGain,'Visible','on','Enable','on','UserData',ii,'Tag','gain','Callback',@miirEdit,'Style','edit');
0321
0322 objName{ii,6} = uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[320 panelDimens(4)-24*(ii+1+currGap)-7 20 20],'String','fs:','FontName','Times New Roman','FontSize',8,'FontWeight','normal','Visible','on','Style','text');
0323
0324 fs = num2str(find(miirPlist,'fs'));
0325 if isempty(fs), fs = 'NA'; end
0326 objName{ii,7} = uicontrol('Parent',currPanel,'Units','pixels','Position',[340 panelDimens(4)-24*(ii+1+currGap) 50 20],'String',fs,'TooltipString','Sample frequency to design for','Visible','on','Enable','on','UserData',ii,'Tag','fs','Callback',@miirEdit,'Style','edit');
0327
0328 objName{ii,8} = uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[400 panelDimens(4)-24*(ii+1+currGap)-7 40 20],'String','Order:','FontName','Times New Roman','FontSize',8,'FontWeight','normal','Visible','on','Style','text');
0329
0330 miirOrder = num2str(find(miirPlist,'order'));
0331 if isempty(miirOrder), miirOrder = 'NA'; end
0332 objName{ii,9} = uicontrol('Parent',currPanel,'Units','pixels','Position',[440 panelDimens(4)-24*(ii+1+currGap) 50 20],'String',miirOrder,'TooltipString','Order of filter','Visible','on','Enable','on','UserData',ii,'Tag','order','Callback',@miirEdit,'Style','edit');
0333
0334 objName{ii,10} = uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[500 panelDimens(4)-24*(ii+1+currGap)-7 20 20],'String','fc:','FontName','Times New Roman','FontSize',8,'FontWeight','normal','Visible','on','Style','text');
0335
0336 miirFc = find(miirPlist,'fc');
0337 if numel(miirFc)>1, miirFc = strcat(num2str(miirFc(1)),',',num2str(miirFc(2)));
0338 else miirFc = num2str(miirFc);
0339 end
0340 if isempty(miirFc), miirFc = 'NA'; end
0341 objName{ii,11} = uicontrol('Parent',currPanel,'Units','pixels','Position',[520 panelDimens(4)-24*(ii+1+currGap) 50 20],'String',miirFc,'TooltipString','Corner frequencies: a two element vector for bandpass and bandreject filters (cannot be >fs/2)','Visible','on','Enable','on','UserData',ii,'Tag','fc','Callback',@miirEdit,'Style','edit');
0342
0343 objName{ii,12} = uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[580 panelDimens(4)-24*(ii+1+currGap)-7 40 20],'String','Ripple:','FontName','Times New Roman','FontSize',8,'FontWeight','normal','Visible','on','Style','text');
0344 miirRipple = find(miirPlist,'ripple');
0345
0346 if isempty(miirRipple), miirRipple = 'NA'; end
0347 objName{ii,13} = uicontrol('Parent',currPanel,'Units','pixels','Position',[620 panelDimens(4)-24*(ii+1+currGap) 50 20],'String',num2str(miirRipple),'TooltipString','Specify pass/stop-band ripple for bandpass and bandreject filters','Visible','on','Enable','on','UserData',ii,'Tag','ripple','Callback',@miirEdit,'Style','edit');
0348
0349
0350 if currMiirType == 5
0351 currGap=currGap+1;
0352
0353 clear pzObj currPoles poleFreqs poleQs poleFQs currZeros zeroFreqs zeroQs zeroFQs
0354 pzObj = find(miirPlist,'pzmodel');
0355 currPoles = get(pzObj,'poles');
0356 currZeros = get(pzObj,'zeros');
0357
0358 objName{ii,14} = uicontrol('Parent',currPanel,'HorizontalAlignment','left','Position',[130 panelDimens(4)-24*(ii+1+currGap) 50 20],'String','Load','FontName','Times New Roman','FontSize',8,'FontWeight','normal','Visible','on','UserData',ii,'Callback',@pzmodelLoad,'Style','pushbutton');
0359
0360 objName{ii,15} = uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[190 panelDimens(4)-24*(ii+1+currGap)-2 40 20],'String','Gain:','FontName','Times New Roman','FontSize',8,'FontWeight','normal','Visible','on','Style','text');
0361
0362 currGain = pzObj.gain;
0363 objName{ii,14} = uicontrol('Parent',currPanel,'Units','pixels','Position',[225 panelDimens(4)-24*(ii+1+currGap) 60 20],'String',num2str(currGain),'Visible','on','Enable','on','UserData',ii,'Callback',@pzmodelGainEdit,'Style','edit');
0364
0365 objName{ii,15} = uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[300 panelDimens(4)-24*(ii+1+currGap)-2 40 20],'String','Poles:','FontName','Times New Roman','FontSize',8,'FontWeight','normal','Visible','on','Style','text');
0366
0367 for kk=1:numel(currPoles)
0368 poleFreqs(kk,1) = get(currPoles(kk),'f');
0369 poleQs(kk,1) = get(currPoles(kk),'q');
0370 if ~isnan(poleQs(kk,1)), poleFQs{kk,1}=strcat(num2str(poleFreqs(kk,1)),',',num2str(poleQs(kk,1)));
0371 else poleFQs{kk,1}=num2str(poleFreqs(kk,1));
0372 end
0373 end
0374 if numel(currPoles)>1 || numel(currZeros)>1, currGap=currGap-1; end
0375 poleFQs=char(poleFQs);
0376 objName{ii,5} = uicontrol('Parent',currPanel,'Units','pixels','Position',[335 panelDimens(4)-24*(ii+1+currGap)-47 60 20+(max(numel(currPoles),numel(currZeros))>1)*24],'Max',2,'String',poleFQs,'TooltipString','Insert ''freq'' or ''freq,q'' on multiple lines','Visible','on','Enable','on','UserData',ii,'Callback',@pzmodelPoleEdit,'Style','edit');
0377
0378 objName{ii,6} = uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[410 panelDimens(4)-24*(ii+2+currGap)-2 40 20],'String','Zeros:','FontName','Times New Roman','FontSize',8,'FontWeight','normal','Visible','on','Style','text');
0379
0380 for kk=1:numel(currZeros)
0381 zeroFreqs(kk,1) = get(currZeros(kk),'f');
0382 zeroQs(kk,1) = get(currZeros(kk),'q');
0383 if ~isnan(zeroQs(kk,1)), zeroFQs{kk,1}=strcat(num2str(zeroFreqs(kk,1)),',',num2str(zeroQs(kk,1)));
0384 else zeroFQs{kk,1}=num2str(zeroFreqs(kk,1)); end
0385 end
0386 zeroFQs=char(zeroFQs);
0387 objName{ii,7} = uicontrol('Parent',currPanel,'Units','pixels','Position',[445 panelDimens(4)-24*(ii+1+currGap)-47 60 20+(max(numel(currPoles),numel(currZeros))>1)*24],'Max',2,'String',zeroFQs,'TooltipString','Insert ''freq'' or ''freq,q'' on multiple lines','Visible','on','Enable','on','UserData',ii,'Callback',@pzmodelZeroEdit,'Style','edit');
0388 currGap=currGap+2;
0389
0390 end
0391
0392
0393 case 'pole'
0394
0395 currPoles = params.params(ii).val;
0396 for kk=1:numel(currPoles)
0397 poleFreqs(kk,1) = currPoles(kk).f;
0398 poleQs(kk,1) = currPoles(kk).q;
0399 if ~isnan(poleQs(kk,1))
0400 poleFQs{kk,1}=strcat(num2str(poleFreqs(kk,1)),',',num2str(poleQs(kk,1)));
0401 else
0402 poleFQs{kk,1}=num2str(poleFreqs(kk,1));
0403 end
0404 end
0405 poleFQs=char(poleFQs);
0406
0407 objName{ii,2} = uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','center','Position',[160 panelDimens(4)-24*(ii+1+currGap)-7 40 20],'String','Poles:','FontName','Times New Roman','FontSize',8,'FontWeight','normal','Visible','on','Style','text');
0408 if numel(currPoles)>1
0409 currGap=currGap+1;
0410 end
0411
0412 objName{ii,3} = uicontrol('Parent',currPanel,'Units','pixels','Position',[250 panelDimens(4)-24*(ii-1+currGap)-47 100 20+(numel(currPoles)>1)*20],'String',poleFQs,'Max',2,'TooltipString','Insert ''freq'' or ''freq,q''','Visible','on','Enable','on','UserData',ii,'Callback',@poleEdit,'Style','edit');
0413
0414
0415 case 'zero'
0416
0417 currZeros = params.params(ii).val;
0418 for kk=1:numel(currZeros)
0419 zeroFreqs(kk,1) = get(currZeros(kk),'f');
0420 zeroQs(kk,1) = get(currZeros(kk),'q');
0421 if ~isnan(zeroQs(kk,1))
0422 zeroFQs{kk,1}=strcat(num2str(zeroFreqs(kk,1)),',',num2str(zeroQs(kk,1)));
0423 else
0424 zeroFQs{kk,1}=num2str(zeroFreqs(kk,1));
0425 end
0426 end
0427 zeroFQs=char(zeroFQs);
0428
0429 objName{ii,2} = uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','center','Position',[160 panelDimens(4)-24*(ii+1+currGap)-7 40 20],'String','Zeros:','FontName','Times New Roman','FontSize',8,'FontWeight','normal','Visible','on','Style','text');
0430 if numel(currZeros)>1
0431 currGap=currGap+1;
0432 end
0433
0434 objName{ii,3} = uicontrol('Parent',currPanel,'Units','pixels','Position',[250 panelDimens(4)-24*(ii-1+currGap)-47 100 20+(numel(currZeros)>1)*20],'String',zeroFQs,'Max',2,'TooltipString','Insert ''freq'' or ''freq,q''','Visible','on','Enable','on','UserData',ii,'Callback',@zeroEdit,'Style','edit');
0435
0436
0437 case 'cell'
0438
0439 if isa(paramvals{ii}{1},'char') && strcmp(paramvals{ii}{1},'-->')
0440
0441 objName{ii,3} = uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','Position',[50 panelDimens(4)-5-24*(ii+1+currGap) 120 20],'String',paramkeys{ii},'Visible','on','Enable','off','UserData',ii,'Callback',@editNameCallback,'Style','text');
0442
0443 objName{ii,4} = uicontrol('TooltipString','Retrieve from Simulink','Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[200 panelDimens(4)-6-24*(ii+1+currGap) 200 20],'String','From Simulink environment','FontName','Times New Roman','FontSize',8,'FontWeight','normal','Visible','on','Style','text');
0444 fromSimulink = 1;
0445 else
0446
0447 objName{ii,2} = uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','center','Position',[40 panelDimens(4)-6-24*(ii+1+currGap) 70 20],'String','Name:','FontName','Times New Roman','FontSize',8,'FontWeight','normal','Visible','on','Style','text');
0448
0449 objName{ii,3} = uicontrol('Parent',currPanel,'Units','pixels','Position',[120 panelDimens(4)-24*(ii+1+currGap) 60 20],'String',paramkeys{ii},'Visible','on','Enable','off','UserData',ii,'Callback',@editNameCallback,'Style','edit');
0450 if ~noParamsReq && ~addedPar
0451 set(objName{ii,2},'Visible','off');
0452 set(objName{ii,3},'Style','text','BackgroundColor',backColor,'Position',[50 panelDimens(4)-5-24*(ii+1+currGap) 120 20]);
0453 end
0454
0455
0456 objName{ii,4} = uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[205 panelDimens(4)-6-24*(ii+1+currGap) 40 20],'String','Value:','FontName','Times New Roman','FontSize',8,'FontWeight','normal','Visible','on','Style','text');
0457
0458 data = cell2str(paramvals{ii});
0459 objName{ii,5} = uicontrol('Parent',currPanel,'Units','pixels','Position',[250 panelDimens(4)-24*(ii+1+currGap) 130 20],'String',data,'Visible','on','Enable','on','UserData',ii,'Callback',@editValueCallback,'Style','edit');
0460 fromSimulink = 0;
0461
0462
0463 objName{ii,6} = uicontrol('TooltipString','Retrieve from Simulink','Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[400 panelDimens(4)-24*(ii+1+currGap) 20 20],'Max',1,'Min',0,'Value',fromSimulink,'Visible','on','Tag',num2str(ii),'UserData',paramvals{ii},'Callback',@fromSimulinkCallback,'Style','checkbox');
0464
0465 end
0466
0467
0468 otherwise
0469
0470
0471 objName{ii,3} = uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','Position',[50 panelDimens(4)-5-24*(ii+1+currGap) 120 20],'String',paramkeys{ii},'Visible','on','Enable','off','UserData',ii,'Callback',@editNameCallback,'Style','text');
0472
0473 objName{ii,4} = uicontrol('Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[200 panelDimens(4)-6-24*(ii+1+currGap) 200 20],'String','Unsupported yet','FontName','Times New Roman','FontSize',8,'FontWeight','normal','Visible','on','Style','text');
0474 fromSimulink = 0;
0475
0476
0477 objName{ii,5} = uicontrol('TooltipString','Retrieve from Simulink','Parent',currPanel,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[400 panelDimens(4)-24*(ii+1+currGap) 20 20],'Max',1,'Min',0,'Value',fromSimulink,'Visible','on','Tag',num2str(ii),'UserData',paramvals{ii},'Callback',@fromSimulinkCallback,'Style','checkbox');
0478
0479
0480 end
0481
0482 if paramEnabled(ii) || noParamsReq==1
0483 [xx,yy] = size(objName);
0484 jj=2;
0485 while jj<=yy && ~isempty(objName{ii,jj})
0486 try set(objName{ii,jj},'Enable','on'); set(objName{ii,jj},'ForegroundColor',[0 0 0]); catch end
0487 jj=jj+1;
0488 end
0489 end
0490
0491 end
0492
0493
0494
0495 paramTypes = {'double/char','specwin','pole','zero','pzmodel','miir','-->'};
0496 for kk=1:y, paramTypes(strmatch(class(params.params(kk).val),paramTypes,'exact'))=[]; end
0497
0498 hparamType = uicontrol('Parent',currPanel,'Units','pixels','Position',[20 panelDimens(4)-40-24*(y+1+totalGaps) 80 20],'String',paramTypes,'Value',1,'Visible','on','Enable','on','Style','popupmenu');
0499
0500 uicontrol('Parent',currPanel,'Units','pixels','Position',[110 panelDimens(4)-40-24*(y+1+totalGaps) 20 20],'String','+','Visible','on','Enable','on','Callback', @AddParamCallback,'UserData',hparamType,'Style','pushbutton');
0501
0502
0503 end
0504
0505
0506
0507
0508
0509
0510
0511 function ContinuousParamCheck(varargin)
0512
0513
0514
0515 if ~isempty(bdroot) && ~isempty(find_system(bdroot,'FindAll','on','Type','Annotation','Tag','ltpda model'))
0516
0517
0518
0519
0520 consistent=1;
0521
0522 if ((length(selBlocks)==1 && selBlocks~=gcbh) || length(selBlocks)~=length(gcbsh)) && ~isempty(gcbsh)
0523 selBlocks = gcbsh;
0524 for i=1:length(selBlocks)
0525 set_param(selBlocks(i),'LinkStatus','inactive');
0526 currentTags{i}=get_param(selBlocks(i),'Tag');
0527 end
0528
0529 if length(gcbsh)>1
0530
0531
0532
0533
0534 for i=1:length(selBlocks)
0535 if ~strcmp(currentTags{i},currentTags{1})
0536 ErrorSelectionInconsistent();
0537 consistent=0;
0538 break
0539 end
0540 end
0541
0542 if strcmp(currentTags{1},'function')
0543 for i=1:length(selBlocks)
0544 childpath = find_system(selBlocks(i),'LookUnderMasks','all','BlockType','M-S-Function');
0545 functionname{i}=get_param(childpath,'Tag');
0546 if ~strcmp(functionname{i},functionname{1})
0547 ErrorSelectionInconsistent();
0548 consistent=0;
0549 end
0550 end
0551 end
0552 end
0553
0554
0555
0556 if consistent
0557 delete(findobj(gcf,'Parent',currPanel))
0558 switch strtok(get(gcbh,'Tag'))
0559
0560 case 'input'
0561 LoadInputParamCallback();
0562
0563
0564 case {'mux','demux'}
0565 LoadMuxParamCallback();
0566
0567
0568 case {'function','freepl','method'}
0569 buildplistFigureParam()
0570
0571
0572 case 'from'
0573 LoadFromBlockCallback();
0574
0575
0576 end
0577 end
0578
0579 end
0580 end
0581
0582 end
0583
0584
0585
0586
0587
0588 function editNameCallback(hObject, varargin)
0589 currParamIndex = get(hObject,'UserData');
0590 newName = get(hObject,'String');
0591 oldName = params.params(currParamIndex).key;
0592 addedPar = 0;
0593 try
0594 if strcmpi(oldName(1:7),'addPar_'), addedPar = 1; oldName(1:7)=[]; end
0595 catch end
0596
0597 if strcmp(params.params(currParamIndex).val,'-->')
0598 block2change = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','Name',lower(oldName));
0599 while ~isempty(find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','Name',lower(newName)))
0600 newName = [newName,'x'];
0601 end
0602 set_param(block2change{1},'Name',lower(newName))
0603 end
0604
0605 if addedPar, newName = ['addPar_',newName]; end
0606 params.params(currParamIndex).key = newName;
0607
0608 if strcmp(params.params(currParamIndex).val,'-->'), UpdateInports(lower(newName),2); end
0609
0610 paramcommand = BuildParamCommand(params);
0611 for kk=1:length(selBlocks)
0612 set_param(selBlocks(kk),'Description',paramcommand);
0613 end
0614 AnnotationUpdate(params);
0615 buildplistFigureParam()
0616 end
0617
0618
0619 function editValueCallback(hObject, varargin)
0620 currParamIndex = get(hObject,'UserData');
0621
0622 newValue = get(hObject,'String');
0623 if strcmp(newValue(1),''''),
0624 paramType = 'char';
0625 newValue(1) = []; newValue(numel(newValue)) = [];
0626 elseif ~strcmp(newValue(1),'{'),
0627 paramType = 'double';
0628 for i=numel(newValue)-1:-1:1
0629 if i~=1 && strcmp(newValue(i),'''') && ~strcmp(newValue(i-1),'''') && ~strcmp(newValue(i+1),'''')
0630 newValue(i+1:numel(newValue)+1) = newValue(i:numel(newValue));
0631 end
0632 end
0633 else
0634 paramType = 'double';
0635 end
0636
0637 switch paramType
0638 case 'double'
0639 try
0640 if ~strcmp(newValue(1),'[') && ~strcmp(newValue(1),'{'), newValue=['[',newValue,']']; end
0641 newValue = eval(newValue);
0642 catch
0643 set(hObject,'String',mat2str(params.params(currParamIndex).val))
0644 end
0645 end
0646
0647 params = pset(params,get(params.params(currParamIndex),'key'),newValue);
0648 paramcommand = BuildParamCommand(params);
0649 for kk=1:length(selBlocks)
0650 set_param(selBlocks(kk),'Description',paramcommand);
0651 end
0652 AnnotationUpdate(params);
0653
0654 end
0655
0656
0657 function browseCallback(hObject, varargin)
0658
0659 [fileName,filePath] = uigetfile('*.*','Choose source file');
0660 if fileName==0
0661 fileName = 'foo.txt';
0662 else
0663 fileName = [filePath,fileName];
0664 end
0665 editFieldHandle = get(hObject,'UserData');
0666 set(editFieldHandle,'String',fileName);
0667
0668
0669 newValue = fileName;
0670 params = pset(params,'FILENAME',newValue);
0671 paramcommand = BuildParamCommand(params);
0672 for kk=1:length(selBlocks)
0673 set_param(selBlocks(kk),'Description',paramcommand);
0674 end
0675 AnnotationUpdate(params);
0676
0677
0678 end
0679
0680
0681 function fromSimulinkCallback(hObject, varargin)
0682 currParamIndex = str2double(get(hObject,'Tag'));
0683 status = get(hObject,'Value');
0684
0685 paramval = get(hObject,'UserData');
0686
0687 if status
0688 paramKey = get(params.params(currParamIndex),'key');
0689 if ~isempty(paramval)
0690 params = pset(params,paramKey,{'-->'});
0691 else
0692 params = pset(params,paramKey,'-->');
0693 end
0694 paramEnabled(currParamIndex) = 1;
0695 UpdateInports(paramKey,1)
0696 else
0697 paramKey = get(params.params(currParamIndex),'key');
0698 if ~isempty(paramval) && isa(paramval,'cell') && numel(paramval)==1 && strcmp(paramval{1},'-->')
0699 params = pset(params,paramKey,{1});
0700 else
0701 params = pset(params,paramKey,1);
0702 end
0703 paramEnabled(currParamIndex) = 0;
0704 UpdateInports(paramKey,-1)
0705 end
0706 paramcommand = BuildParamCommand(params);
0707 for kk=1:length(selBlocks)
0708 set_param(selBlocks(kk),'Description',paramcommand);
0709 end
0710 AnnotationUpdate(params);
0711 buildplistFigureParam()
0712 end
0713
0714
0715
0716
0717
0718 function WindListCallback(hObject, varargin)
0719 currParamID = get(hObject,'UserData');
0720 currWindValue = get(hObject,'Value');
0721 listWindows = ['Kaiser',specwin('Types')];
0722 currWindow = listWindows{currWindValue};
0723 oldWindObj = params.params(currParamID);
0724 oldWindow = oldWindObj.name;
0725 if strcmp(currWindow,oldWindow)
0726 return;
0727 else
0728 currWindLength = str2double(get(objName{currParamID,5},'String'));
0729 if strcmp(currWindow,'Kaiser')
0730 currPSL=get(get(oldWindObj,'val'),'psll');
0731 windobj=specwin(eval('currWindow'),currWindLength,currPSL);
0732 else
0733 windobj=specwin(eval('currWindow'),currWindLength);
0734 end
0735 end
0736
0737 params=pset(params,'Win',windobj);
0738
0739 paramcommand = BuildParamCommand(params);
0740 for kk=1:length(selBlocks)
0741 set_param(selBlocks(kk),'Description',paramcommand);
0742 end
0743 AnnotationUpdate(params);
0744 delete(findobj(gcf,'Parent',currPanel))
0745 buildplistFigureParam()
0746
0747 end
0748
0749
0750 function WindlengthCallback(hObject,varargin)
0751
0752
0753
0754 currParamID = get(hObject,'UserData');
0755 selectedWind=get(objName{currParamID,3},'Value');
0756
0757 listWindows=specwin('Types');
0758 listWindows={'Kaiser',listWindows{:}};
0759 selectedWind=listWindows{selectedWind};
0760
0761 currWindLength=str2double(get(hObject,'String'));
0762
0763 if strcmp(selectedWind,'Kaiser')
0764 currPSL=str2double(get(objName{currParamID,7},'String'));
0765 windobj=specwin(eval('selectedWind'),currWindLength,currPSL);
0766 else
0767 windobj=specwin(eval('selectedWind'),currWindLength);
0768 end
0769
0770 params=pset(params,'Win',windobj);
0771
0772 paramcommand = BuildParamCommand(params);
0773 for kk=1:length(selBlocks)
0774 set_param(selBlocks(kk),'Description',paramcommand);
0775 end
0776
0777 AnnotationUpdate(params);
0778
0779 end
0780
0781
0782 function WindPSLCallback(hObject,varargin)
0783
0784
0785
0786 currParamID = get(hObject,'UserData');
0787 selectedWind = get(objName{currParamID,3},'Value');
0788
0789 listWindows = specwin('Types');
0790 listWindows = {'Kaiser',listWindows{:}};
0791 selectedWind = listWindows{selectedWind};
0792
0793 currWindLength = str2double(get(objName{currParamID,5},'String'));
0794 currPSL = str2double(get(hObject,'String'));
0795
0796 windobj=specwin(eval('selectedWind'),currWindLength,currPSL);
0797
0798 params = pset(params,'Win',windobj);
0799
0800 paramcommand = BuildParamCommand(params);
0801 for kk=1:length(selBlocks)
0802 set_param(selBlocks(kk),'Description',paramcommand);
0803 end
0804
0805 AnnotationUpdate(params);
0806 end
0807
0808
0809
0810
0811
0812 function pzmodelLoad(hObject, varargin)
0813 currParamIndex = get(hObject,'UserData');
0814
0815 switch class(get(params.params(currParamIndex),'val'))
0816 case 'pzmodel'
0817 try [FileName,PathName] = uigetfile('*.xml','Select the .XML pzmodel file');
0818 FileAddress = strcat(PathName,FileName);
0819 pzObj = pzmodel(FileAddress);
0820 if isempty(pzObj), return; end
0821 newParam = param('pzmodel',pzObj);
0822 newParams = plist();
0823 for jj=1:nparams(params)
0824 if jj~=currParamIndex
0825 newParams = append(newParams,params.params(jj));
0826 else
0827 newParams = append(newParams,newParam);
0828 end
0829 end
0830 params=newParams;
0831 catch
0832 end
0833 case 'miir'
0834 miirObj = get(params.params(currParamIndex),'val');
0835 miirPlist = miirObj.plist;
0836 try [FileName,PathName] = uigetfile('*.xml','Select the .XML pzmodel file');
0837 FileAddress = strcat(PathName,FileName);
0838 pzObj = pzmodel(FileAddress);
0839 newParam = param('pzmodel',pzObj);
0840 newParams = plist();
0841 for jj=1:nparams(miirPlist)
0842 if ~strcmp(get(miirPlist.params(jj),'key'),'pzmodel')
0843 newParams = append(newParams,miirPlist.params(jj));
0844 else
0845 newParams = append(newParams,newParam);
0846 end
0847 end
0848 miirPlist = newParams;
0849 newParam = param(miirObj.name,miir(miirPlist));
0850 newParams = plist();
0851 for jj=1:nparams(params)
0852 if jj~=currParamIndex
0853 newParams = append(newParams,params.params(jj));
0854 else
0855 newParams = append(newParams,newParam);
0856 end
0857 end
0858 params=newParams;
0859 catch
0860 end
0861 end
0862
0863 buildplistFigureParam()
0864 end
0865
0866
0867 function pzmodelGainEdit(hObject, varargin)
0868 currParamIndex = get(hObject,'UserData');
0869 pzGain = str2double(get(hObject,'String'));
0870
0871 switch class(get(params.params(currParamIndex),'val'))
0872 case 'pzmodel'
0873 pzObj = params.params(currParamIndex);
0874 pzKey = get(pzObj,'key');
0875 pzObj = get(pzObj,'val');
0876 poleList = get(pzObj,'poles');
0877 zeroList = get(pzObj,'zeros');
0878 pzObj = pzmodel(pzGain,poleList,zeroList);
0879 params = pset(params,pzKey,pzObj);
0880
0881 case 'miir'
0882 miirObj = get(params.params(currParamIndex),'val');
0883 miirKey = get(params.params(currParamIndex),'key');
0884 miirPlist = miirObj.plist;
0885 pzObj = find(miirPlist,'pzmodel');
0886 poleList = get(pzObj,'poles');
0887 zeroList = get(pzObj,'zeros');
0888
0889 pzObj = pzmodel(pzGain,poleList,zeroList);
0890 miirPlist = pset(miirPlist,'pzmodel',pzObj);
0891 params = pset(params,miirKey,miir(miirPlist));
0892
0893 end
0894
0895
0896
0897 paramcommand = BuildParamCommand(params);
0898 for kk=1:length(selBlocks)
0899 set_param(selBlocks(kk),'Description',paramcommand);
0900 end
0901 AnnotationUpdate(params);
0902
0903 end
0904
0905
0906 function pzmodelPoleEdit(hObject, varargin)
0907 currParamIndex = get(hObject,'UserData');
0908 poles = get(hObject,'String');
0909 poles = readInput(poles,2);
0910 [xx,yy]=size(poles);
0911 poleList=pole();
0912 for kk=1:xx
0913 if (yy>1 && poles(kk,2)==0) || yy==1
0914 poleList(kk)=pole(poles(kk,1));
0915 else
0916 poleList(kk)=pole(poles(kk,1),poles(kk,2));
0917 end
0918 end
0919
0920 switch class(get(params.params(currParamIndex),'val'))
0921 case 'pzmodel'
0922 pzObj = params.params(currParamIndex);
0923 pzKey = get(pzObj,'key');
0924 pzObj = get(pzObj,'val');
0925 pzGain = get(pzObj,'gain');
0926 zeroList = get(pzObj,'zeros');
0927 pzObj = pzmodel(pzGain,poleList,zeroList);
0928 params = pset(params,pzKey,pzObj);
0929
0930 case 'miir'
0931 miirObj = get(params.params(currParamIndex),'val');
0932 miirKey = get(params.params(currParamIndex),'key');
0933 miirPlist = miirObj.plist;
0934 pzObj = find(miirPlist,'pzmodel');
0935 pzGain = get(pzObj,'gain');
0936 zeroList = get(pzObj,'zeros');
0937 pzObj = pzmodel(pzGain,poleList,zeroList);
0938 miirPlist = pset(miirPlist,'pzmodel',pzObj);
0939 params = pset(params,miirKey,miir(miirPlist));
0940
0941 end
0942
0943
0944
0945 paramcommand = BuildParamCommand(params);
0946 for kk=1:length(selBlocks)
0947 set_param(selBlocks(kk),'Description',paramcommand);
0948 end
0949 AnnotationUpdate(params);
0950
0951 end
0952
0953
0954 function pzmodelZeroEdit(hObject, varargin)
0955 currParamIndex = get(hObject,'UserData');
0956 zeros = get(hObject,'String');
0957 zeros = readInput(zeros,2);
0958 [xx,yy] = size(zeros);
0959 zeroList = zero();
0960 for kk=1:xx
0961 if (yy>1 && zeros(kk,2)==0) || yy==1
0962 zeroList(kk)=zero(zeros(kk,1));
0963 else
0964 zeroList(kk)=zero(zeros(kk,1),zeros(kk,2));
0965 end
0966 end
0967
0968 switch class(get(params.params(currParamIndex),'val'))
0969 case 'pzmodel'
0970 pzObj = params.params(currParamIndex);
0971 pzKey = get(pzObj,'key');
0972 pzObj = get(pzObj,'val');
0973 pzGain = get(pzObj,'gain');
0974 poleList = get(pzObj,'poles');
0975 pzObj = pzmodel(pzGain,poleList,zeroList);
0976 params = pset(params,pzKey,pzObj);
0977
0978 case 'miir'
0979 miirObj = get(params.params(currParamIndex),'val');
0980 miirKey = get(params.params(currParamIndex),'key');
0981 miirPlist = miirObj.plist;
0982 pzObj = find(miirPlist,'pzmodel');
0983 pzGain = get(pzObj,'gain');
0984 poleList = get(pzObj,'poles');
0985 pzObj = pzmodel(pzGain,poleList,zeroList);
0986 miirPlist = pset(miirPlist,'pzmodel',pzObj);
0987 params = pset(params,miirKey,miir(miirPlist));
0988 end
0989
0990
0991
0992 paramcommand = BuildParamCommand(params);
0993 for kk=1:length(selBlocks)
0994 set_param(selBlocks(kk),'Description',paramcommand);
0995 end
0996 AnnotationUpdate(params);
0997
0998 end
0999
1000
1001
1002
1003
1004 function miirLoad(hObject, varargin)
1005 currParamIndex = get(hObject,'UserData');
1006 try [FileName,PathName] = uigetfile({'*.xml';'*.fil';'*.filt'},'Select the .XML pzmodel file');
1007 FileAddress = strcat(PathName,FileName);
1008 miirObj = miir(FileAddress);
1009 if isempty(miirObj), return; end
1010 newParam = param('miir',miirObj);
1011 newParams = plist();
1012 for jj=1:nparams(params)
1013 if jj~=currParamIndex
1014 newParams = append(newParams,params.params(jj));
1015 else
1016 newParams = append(newParams,newParam);
1017 end
1018 end
1019 params=newParams;
1020 catch
1021 end
1022
1023 buildplistFigureParam()
1024 end
1025
1026
1027 function miirTypeEdit(hObject, varargin)
1028 currParamIndex = get(hObject,'UserData');
1029 miirObj = get(params.params(currParamIndex),'val');
1030 miirPlist = miirObj.plist;
1031 paramList = {'type','gain','fs','order','fc','ripple'};
1032 miirTypes = get(hObject,'String');
1033 currMiirType = miirTypes{get(hObject,'Value')};
1034 prevMiirType = find(miirPlist,'type');
1035 if isempty(prevMiirType), prevMiirType='pzmodel'; end
1036
1037 miirPL = plist();
1038 if strcmp(currMiirType,'pzmodel')
1039 pzObj = pzmodel(1,[pole(10,2),pole(100)],zero(1));
1040 miirPL = append(miirPL, param('pzmodel', pzObj ));
1041 miirPL = append(miirPL, param('fs', 1 ));
1042 else
1043 miirPL = append(miirPL, param('type', currMiirType ));
1044 for ii=2:6
1045 miirVals{ii} = find(miirPlist,paramList{ii});
1046 if isempty(miirVals{ii}) && ii==6
1047 miirVals{ii} = 0.5;
1048 elseif isempty(miirVals{ii})
1049 miirVals{ii} = 1;
1050 end
1051 if ii==5
1052 if (strmatch(prevMiirType,miirTypes)<3 || strmatch(prevMiirType,miirTypes)==5) && (strmatch(currMiirType,miirTypes)==3 || strmatch(currMiirType,miirTypes)==4)
1053 miirVals{5}=[0.1,0.3];
1054 elseif (strmatch(prevMiirType,miirTypes)==3 || strmatch(prevMiirType,miirTypes)==4) && (strmatch(currMiirType,miirTypes)<3 || strmatch(currMiirType,miirTypes)==5)
1055 miirVals{5}=0.25;
1056 elseif strmatch(prevMiirType,miirTypes)==5 && strmatch(currMiirType,miirTypes)<3
1057 miirVals{5}=0.25;
1058 end
1059 end
1060 miirPL = append(miirPL, param(paramList{ii}, miirVals{ii} ));
1061 end
1062 end
1063 params = pset(params,get(params.params(currParamIndex),'key'),miir(miirPL));
1064
1065
1066
1067 paramcommand = BuildParamCommand(params);
1068 for kk=1:length(selBlocks)
1069 set_param(selBlocks(kk),'Description',paramcommand);
1070 end
1071 AnnotationUpdate(params);
1072 buildplistFigureParam()
1073 end
1074
1075
1076 function miirEdit(hObject, varargin)
1077 currParamIndex = get(hObject,'UserData');
1078 miirObj = get(params.params(currParamIndex),'val');
1079 miirKey = get(params.params(currParamIndex),'key');
1080 miirPlist = miirObj.plist;
1081
1082 propName = get(hObject,'Tag');
1083
1084
1085 newValue = str2num(get(hObject,'String'));
1086
1087
1088 if (isempty(newValue) || strcmp(newValue,'-') || strcmp(newValue,'NA')) && isempty(find(miirPlist,'type'))
1089 newMiirPlist = plist();
1090 for zz=1:nparams(miirPlist)
1091 if ~strcmp(get(miirPlist.params(zz),'key'),propName)
1092 newMiirPlist = append(newMiirPlist,miirPlist.params(zz));
1093 end
1094 end
1095 miirPlist = newMiirPlist;
1096 params = pset(params, miirObj.name , miir(miirPlist));
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107 paramcommand = BuildParamCommand(params);
1108 for kk=1:length(selBlocks)
1109 set_param(selBlocks(kk),'Description',paramcommand);
1110 end
1111 AnnotationUpdate(params);
1112 return
1113
1114 elseif (isempty(newValue) || strcmp(newValue,'-') || strcmp(newValue,'NA')) && ~isempty(find(miirPlist,'type'))
1115 set(hObject,'String',num2str(find(miirPlist,propName)));
1116 return
1117 end
1118
1119 fs = find(miirPlist,'fs');
1120 fc = find(miirPlist,'fc');
1121 if strcmp(propName,'fc') && numel(newValue)>2
1122 newValue = newValue(1:2);
1123 end
1124 if strcmp(propName,'fc') && numel(newValue)>2 && newValue(1)>newValue(2)
1125 newValue = fliplr(newValue);
1126 end
1127 if strcmp(propName,'fc') && numel(newValue)==1
1128 if newValue>=fs/2
1129 newValue = fs/2-fs/200;
1130 end
1131 elseif strcmp(propName,'fc') && numel(newValue)==2
1132 if max(newValue)>=fs/2
1133 if min(newValue)>=fs/2
1134 newValue = [fs/4 fs/2-fs/200];
1135 else
1136 newValue = [min(newValue) fs/2-fs/200];
1137 end
1138 end
1139
1140 elseif strcmp(propName,'fs') && numel(fc)==1
1141 if newValue<=fc*2
1142 miirPlist = set(miirPlist,'fc',newValue/2-newValue/20);
1143 end
1144 elseif strcmp(propName,'fs') && numel(fc)==2
1145 if newValue<=max(fc)*2
1146 if newValue<=min(fc)
1147 miirPlist = set(miirPlist,'fc',[newValue/4 newValue/2-newValue/20]);
1148 else
1149 miirPlist = set(miirPlist,'fc',[min(fc) newValue/2-newValue/20]);
1150 end
1151 end
1152
1153 elseif strcmp (propName,'order')
1154 newValue = ceil(newValue);
1155 end
1156
1157 miirPlist = pset(miirPlist,propName,newValue);
1158 params = pset(params,miirKey,miir(miirPlist));
1159
1160
1161 get(params.params(currParamIndex),'val')
1162 paramcommand = BuildParamCommand(params);
1163 for kk=1:length(selBlocks)
1164 set_param(selBlocks(kk),'Description',paramcommand);
1165 end
1166 AnnotationUpdate(params);
1167
1168 end
1169
1170
1171
1172
1173
1174 function poleEdit(hObject, varargin)
1175 currParamIndex = get(hObject,'UserData');
1176 poles = get(hObject,'String');
1177 poles = readInput(poles,2);
1178 [xx,yy] = size(poles);
1179 poleList = pole();
1180 for kk=1:xx
1181 if (yy>1 && poles(kk,2)==0) || yy==1
1182 poleList(kk)=pole(poles(kk,1));
1183 else
1184 poleList(kk)=pole(poles(kk,1),poles(kk,2));
1185 end
1186 end
1187 params = pset(params,params.params(currParamIndex).key,poleList);
1188
1189 paramcommand = BuildParamCommand(params);
1190 for kk=1:length(selBlocks)
1191 set_param(selBlocks(kk),'Description',paramcommand);
1192 end
1193 AnnotationUpdate(params);
1194 buildplistFigureParam()
1195 end
1196
1197
1198
1199
1200
1201 function zeroEdit(hObject, varargin)
1202 currParamIndex = get(hObject,'UserData');
1203 zeros = get(hObject,'String');
1204 zeros = readInput(zeros,2);
1205 [xx,yy] = size(zeros);
1206 zeroList = zero();
1207 for kk=1:xx
1208 if (yy>1 && zeros(kk,2)==0) || yy==1
1209 zeroList(kk)=zero(zeros(kk,1));
1210 else
1211 zeroList(kk)=zero(zeros(kk,1),zeros(kk,2));
1212 end
1213 end
1214 params = pset(params,params.params(currParamIndex).key,zeroList);
1215
1216 paramcommand = BuildParamCommand(params);
1217 for kk=1:length(selBlocks)
1218 set_param(selBlocks(kk),'Description',paramcommand);
1219 end
1220 AnnotationUpdate(params);
1221 buildplistFigureParam()
1222 end
1223
1224
1225
1226
1227
1228 function AddParamCallback(hObject,varargin)
1229
1230 hparamType = get(hObject,'UserData');
1231 paramTypes = get(hparamType,'String');
1232 paramType = paramTypes{get(hparamType,'Value')};
1233
1234 switch paramType
1235 case {'double','double/char'}
1236 key = 'addPar_name';
1237 while ~isempty(find(params,key))
1238 key =[key,'x'];
1239 end
1240 params = append(params, param(key,1));
1241 case 'specwin'
1242 newParam = param('addPar_Win',specwin('Kaiser',1000,200));
1243 params = append(params, newParam);
1244 case 'pzmodel'
1245 pzObj = pzmodel(1,[pole(10,2),pole(100)],zero(1));
1246 newParam = param('addPar_pzmodel',pzObj);
1247 params = append(params, newParam);
1248 case 'miir'
1249 pl = plist();
1250 pl = append(pl, param('type', 'highpass'));
1251 pl = append(pl, param('gain', 1));
1252 pl = append(pl, param('fs', 1));
1253 pl = append(pl, param('order', 1));
1254 pl = append(pl, param('fc', 0.25));
1255 pl = append(pl, param('ripple', 0.5));
1256 miirObj = miir(pl);
1257 newParam = param('addPar_filt',miirObj);
1258 params = append(params, newParam);
1259 case '-->'
1260 key = 'addPar_name';
1261 while find(params,key)
1262 key = [key,'x'];
1263 end
1264 params = append(params, param(key,'-->'));
1265 UpdateInports(key,1)
1266 case 'poles'
1267 params = append(params, param('addPar_poles',pole(1)));
1268 case 'zeros'
1269 params = append(params, param('addPar_zeros',zero(1)));
1270
1271 end
1272
1273 if nparams(params)==1, paramEnabled=1;
1274 else paramEnabled=[paramEnabled,1];
1275 end
1276
1277 paramcommand = BuildParamCommand(params);
1278 for kk=1:length(selBlocks)
1279 set_param(selBlocks(kk),'Description',paramcommand);
1280 end
1281
1282 AnnotationUpdate(params);
1283
1284 buildplistFigureParam()
1285 end
1286
1287
1288
1289 function RemParamCallback(hObject, varargin)
1290 currParamIndex = get(hObject,'UserData');
1291
1292 paramKey = params.params(currParamIndex).key;
1293 paramVal = params.params(currParamIndex).val;
1294
1295 newParams = plist();
1296 for jj=1:nparams(params)
1297 if jj~=currParamIndex
1298 newParams = append(newParams,params.params(jj));
1299 end
1300 end
1301 paramEnabled(currParamIndex)=[];
1302 params = newParams;
1303
1304 if strcmp(paramVal,'-->')
1305 UpdateInports(paramKey,-1);
1306 end
1307
1308 paramcommand = BuildParamCommand(params);
1309 for kk=1:length(selBlocks)
1310 set_param(selBlocks(kk),'Description',paramcommand);
1311 end
1312
1313 AnnotationUpdate(params);
1314
1315 buildplistFigureParam()
1316 end
1317
1318
1319
1320 function UpdateInports(varargin)
1321
1322
1323
1324 paramKey = varargin{1};
1325 try
1326 if strcmpi(paramKey(1:7),'addPar_'), paramKey(1:7)=[]; end
1327 catch end
1328
1329 if varargin{2}==-1
1330 block2delete = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','Name',lower(paramKey));
1331 blockLines = get_param(block2delete{1},'LineHandles');
1332 if (blockLines.Outport(1)~=-1 && ~isempty(blockLines.Outport(1))), delete_line(blockLines.Outport(1)); end
1333 delete_block(block2delete);
1334 end
1335
1336 if varargin{2}==1
1337 newBlock = add_block('simulink/Sources/In1', [gcb,'/Inport1'],'MakeNameUnique','on');
1338 set(newBlock,'Name',paramKey)
1339 end
1340
1341 if varargin{2}~=2
1342
1343 muxblock = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','BlockType','Mux');
1344 try
1345 muxLines = get_param(muxblock{1},'LineHandles');
1346 for k=1:numel(muxLines.Inport), if (muxLines.Inport(k)~=-1 && ~isempty(muxLines.Inport(k))), delete_line(muxLines.Inport(k)); end
1347 end
1348 for k=1:numel(muxLines.Outport), if (muxLines.Outport(k)~=-1 && ~isempty(muxLines.Outport(k))), delete_line(muxLines.Outport(k)); end
1349 end
1350 catch
1351 end
1352 delete_block(muxblock);
1353
1354 inports = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','BlockType','Inport');
1355 fakeInp = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','BlockType','Constant');
1356 inports = [fakeInp;inports];
1357
1358 if numel(inports)>1
1359 muxblock = add_block('built-in/Mux', [gcb,'/Mux']);
1360 set(muxblock,'Position',[70 , 10 , 73 , 150])
1361 set(muxblock,'Inputs',num2str(numel(inports)))
1362 end
1363 for k=1:numel(inports)
1364 inports{k}=get_param(inports{k},'Handle');
1365 blkLines = get(inports{k},'LineHandles');
1366 for j=1:numel(blkLines.Outport), if (blkLines.Outport(j)~=-1 && ~isempty(blkLines.Outport(j))), delete_line(blkLines.Outport(j)); end
1367 end
1368 set(inports{k},'Position',[10 , 10+30*(k-1) , 30 , 30+30*(k-1)])
1369 set(inports{k},'Tag',num2str(k))
1370 if numel(inports)>1
1371 add_line(gcb,[get(inports{k},'Name'),'/1'],[get(muxblock,'Name'),'/',num2str(k)]);
1372 end
1373 end
1374
1375 funcBlock = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','BlockType','M-S-Function');
1376 funcBlock = get_param(funcBlock,'Name');
1377 if numel(inports)>1
1378 add_line(gcb,[get(muxblock,'Name'),'/1'],[funcBlock{1},'/1']);
1379 else
1380 add_line(gcb,[get(inports{1},'Name'),'/1'],[funcBlock{1},'/1']);
1381 end
1382 else
1383 inports = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','BlockType','Inport');
1384 fakeInp = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','BlockType','Constant');
1385 inports = [fakeInp;inports];
1386 end
1387
1388 simKey = {};
1389 for i=1:nparams(params)
1390 if isa(params.params(i).val,'char') && strcmp(params.params(i).val,'-->')
1391 name = params.params(i).key;
1392 if strcmpi(name(1:7),'addPar_'), name(1:7)=[]; end
1393 simKey{numel(simKey)+1} = name;
1394
1395 end
1396 end
1397
1398 drawingCom = '';
1399 if numel(simKey)>0
1400 if numel(fakeInp)>0, currInp=1; else currInp=2; end
1401 for nn=1:numel(simKey)
1402 drawingCom = [drawingCom,'port_label(''input'',',num2str(currInp),',''',lower(simKey{1}),''');'];
1403 simKey(1) = [];
1404 currInp = currInp+1;
1405 end
1406 else
1407 funcBlock = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','BlockType','M-S-Function');
1408 funcName = get_param(funcBlock{1},'Tag');
1409 if numel(funcName)>6 && strcmp(funcName(1:6),'ltpda_'), funcName(1:6)=[]; end
1410 drawingCom = strcat('disp(''',lower(funcName),''')');
1411 end
1412 set(gcbh,'MaskDisplay',drawingCom)
1413
1414 end
1415
1416
1417
1418
1419 function [array]=readInput(inputdata, maxnumb, varargin)
1420 [xx,yy]=size(inputdata);
1421
1422
1423 array=[];
1424 for i=1:xx
1425 rowpos=1;
1426 elemidx(i)=1;
1427 for j=1:yy+1
1428 if (j==yy+1 || inputdata(i,j)==',' || strcmp(inputdata(i,j),' ') ) && (j==1 || (j>1 && (~strcmp(inputdata(i,j-1),' '))))
1429 if (j==1 || strcmp(inputdata(i,j-1),',')) && strcmp(inputdata(i,j),',')
1430 array(i,elemidx(i))=0;
1431 elemidx(i)=elemidx(i)+1;
1432 rowpos=j+1;
1433 else
1434
1435
1436
1437
1438 array(i,elemidx(i))=eval(inputdata(i,rowpos:j-1));
1439 rowpos=j+1;
1440 elemidx(i)=elemidx(i)+1;
1441 end
1442 elseif j<yy+1 && strcmp(inputdata(i,j),' ')
1443 rowpos=j+1;
1444 end
1445 if maxnumb~=0
1446 if elemidx(i)==maxnumb+1, break; end
1447 end
1448 end
1449 elemidx(i)=elemidx(i)-1;
1450 end
1451 end
1452
1453
1454
1455 function paramcommand = BuildParamCommand(params,varargin)
1456
1457
1458
1459 paramcommand = strcat('params=',string(params),';');
1460
1461 if exist('paramEnabled','var')
1462 paramcommand = strcat(paramcommand,'paramEnabled=[');
1463 for jj=1:numel(paramEnabled)
1464 paramcommand = strcat(paramcommand,num2str(paramEnabled(jj)),',');
1465 end
1466 if numel(paramEnabled)==0, paramcommand=[paramcommand,'0]']; end
1467 paramcommand(numel(paramcommand)) = ']';
1468 paramcommand = strcat(paramcommand,';');
1469 end
1470
1471 if ~exist('params','var') || nparams(params)==0, paramcommand='params=plist();paramEnabled=[];'; end
1472
1473 if exist('noParamsReq','var') && noParamsReq==1
1474 paramcommand = [paramcommand,'noParamsReq=1;'];
1475 end
1476
1477 description = get_param(gcbh,'Description');
1478 funcname = findstr('functionName=',description);
1479 if funcname
1480 i = funcname+14;
1481 while ~strcmp(description(i),';'), i=i+1; end
1482 funcname = description(funcname+13:i-1);
1483 paramcommand = [paramcommand,'functionName=',funcname,';'];
1484 end
1485
1486 if exist('paramSets','var')
1487 sets = find(paramSets,'sets');
1488 currSet = find(paramSets,'currSet');
1489 paramSets = plist('sets',sets,'currSet',currSet);
1490 paramcommand = [paramcommand,'paramSets=',string(paramSets),';'];
1491 end
1492
1493 end
1494
1495
1496
1497 function paramcommand = RetrievePlist(varargin)
1498
1499
1500
1501 try functionname = varargin{1};
1502 catch
1503 childpath = find_system(gcbh,'LookUnderMasks','all','BlockType','M-S-Function');
1504 functionname=get_param(childpath,'Tag');
1505 end
1506
1507 if isempty(functionname)
1508 description = get_param(gcbh,'Description');
1509 funcname = findstr('functionName=',description);
1510 if funcname
1511 i = funcname+14;
1512 while ~strcmp(description(i),';'), i=i+1; end
1513 functionname = description(funcname+14:i-2);
1514 end
1515 end
1516
1517 setappdata(0,'ltpda_currFunctionName',functionname);
1518
1519 try
1520 if strcmp(functionname,'generic')
1521 paramcommand = 'functionName=''generic'';params=plist();paramEnabled=[];';
1522 return
1523 end
1524
1525 [func,class] = strtok(get(gcbh,'Tag'));
1526
1527 if strcmp(func,'method')
1528 params=feval(functionname,eval(strtrim(class)),'Params');
1529 else
1530 params=feval(functionname,'Params');
1531 end
1532 if isa(params,'cell')
1533 paramSets = plist('sets',params,'currSet',1);
1534 paramcommand = strcat('paramSets=',string(paramSets),';','params=plist();');
1535 elseif nparams(params)
1536 paramcommand = strcat('params=',string(params),';');
1537 else
1538 paramcommand = 'params=plist();';
1539 end
1540 catch
1541 disp(sprintf('Error: unable to retrieve the parameters required by the function "%s". Maybe it''s not supported yet?',functionname));
1542 ErrorFuncNotSupported();
1543 paramcommand = '';
1544 rethrow(lasterror)
1545 return
1546 end
1547
1548 end
1549
1550
1551
1552 function AnnotationUpdate(params,varargin)
1553
1554
1555
1556 annotation='';
1557 numparams=nparams(params);
1558 firstpar=1;
1559 for kk=1:numparams
1560 if paramEnabled(kk)
1561 paramkey = params.params(kk).key;
1562 try
1563 if strcmpi(paramkey(1:7),'addPar_'), paramkey(1:7)=[]; end
1564 catch end
1565 paramval = params.params(kk).val;
1566 switch class(paramval)
1567 case 'specwin'
1568 windowName = get(paramval,'name');
1569 [xxx,windowlength] = size(get(paramval,'win'));
1570 if firstpar==1
1571 annotation = ['specwin ',windowName,',',num2str(windowlength)];
1572 firstpar=2;
1573 else
1574 annotation = [annotation,'\n','specwin ',windowName,',',num2str(windowlength)];
1575 end
1576 if strcmp(windowName,'Kaiser')
1577 windowPsll=get(paramval,'psll');
1578 annotation = [annotation,',',num2str(windowPsll)];
1579 end
1580 case 'double'
1581 paramval = mat2str(paramval);
1582 if numel(paramval)>25, paramval=['...',paramval(numel(paramval)-25:numel(paramval))]; end
1583 if firstpar==1, annotation=[lower(paramkey),' ',paramval]; firstpar=2;
1584 else annotation = [annotation,'\n',lower(paramkey),' ',num2str(paramval)];
1585 end
1586 case 'char'
1587 if numel(paramval)>25, paramval=['...',paramval(numel(paramval)-25:numel(paramval))]; end
1588 if firstpar==1, annotation=[lower(paramkey),' ',paramval]; firstpar=2;
1589 else annotation = [annotation,'\n',lower(paramkey),' ',paramval];
1590 end
1591 case 'pzmodel'
1592 if firstpar==1, annotation='pzmodel'; firstpar=2;
1593 else annotation = [annotation,'\n','pzmodel'];
1594 end
1595 case 'miir'
1596 if firstpar==1, annotation='miir'; firstpar=2;
1597 else annotation = [annotation,'\n','miir'];
1598 end
1599 case 'cell'
1600 if firstpar==1
1601 annotation = [lower(paramkey),' ',cell2str(paramval)]; firstpar=2;
1602 else annotation = [annotation,'\n',lower(paramkey),' ',cell2str(paramval)];
1603 end
1604 case 'pole'
1605 for kk=1:numel(paramval)
1606 poleFreqs(kk,1) = paramval(kk).f;
1607 poleQs(kk,1) = paramval(kk).q;
1608 if ~isnan(poleQs(kk,1))
1609 poleFQs{kk,1}=strcat(num2str(poleFreqs(kk,1)),',',num2str(poleQs(kk,1)));
1610 else
1611 poleFQs{kk,1}=num2str(poleFreqs(kk,1));
1612 end
1613 end
1614 poleFQs=char(poleFQs);
1615 if firstpar==1
1616 annotation = ['pole ',poleFQs(1,:)]; firstpar=2;
1617 for j=2:size(poleFQs,1), annotation = [annotation,'\n','pole ',poleFQs(j,:)]; end
1618 else
1619 annotation = [annotation,'\n','pole ',poleFQs(1,:)];
1620 for j=2:size(poleFQs,1), annotation = [annotation,'\n','pole ',poleFQs(j,:)]; end
1621 end
1622 case 'zero'
1623 for kk=1:numel(paramval)
1624 zeroFreqs(kk,1) = paramval(kk).f;
1625 zeroQs(kk,1) = paramval(kk).q;
1626 if ~isnan(zeroQs(kk,1))
1627 zeroFQs{kk,1}=strcat(num2str(zeroFreqs(kk,1)),',',num2str(zeroQs(kk,1)));
1628 else
1629 zeroFQs{kk,1}=num2str(zeroFreqs(kk,1));
1630 end
1631 end
1632 zeroFQs=char(zeroFQs);
1633 if firstpar==1
1634 annotation = ['zero ',zeroFQs(1,:)]; firstpar=2;
1635 for j=2:size(zeroFQs,1), annotation = [annotation,'\n','zero ',zeroFQs(j,:)]; end
1636 else
1637 annotation = [annotation,'\n','zero ',zeroFQs(1,:)];
1638 for j=2:size(zeroFQs,1), annotation = [annotation,'\n','zero ',zeroFQs(j,:)]; end
1639 end
1640 end
1641 end
1642 end
1643
1644 for nn=1:length(selBlocks)
1645 set_param(selBlocks(nn),'AttributesFormatString',annotation);
1646 end
1647 end
1648
1649
1650
1651 function functionName = functionNameSet(hObject, varargin)
1652
1653
1654 functionName2 = get(hObject,'String');
1655 classes = {'ao';'cdata';'fsdata';'history';'mfir';'miir';'param';'plist';'pole';'provenance';'pzmodel';'specwin';'time';'timeformat';'timespan';'tsdata';'xydata';'xyzdata';'zero'};
1656 for i=1:numel(classes)
1657 if ismethod(eval(classes{i}),functionName2)
1658 currSel = gcbsh;
1659 for j=1:numel(currSel), set(currSel(j),'Tag',['method ',classes{i}]); end
1660 break
1661 else
1662 currSel = gcbsh;
1663 for j=1:numel(currSel), set(currSel(j),'Tag','function'); end
1664 end
1665 end
1666 paramcommand = RetrievePlist(functionName2);
1667
1668 if ~isempty(paramcommand)
1669 functionName = functionName2;
1670 setappdata(0,'ltpda_currFunctionName',functionName);
1671 paramcommand = strcat(paramcommand,'functionName=''',functionName2,''';');
1672 for i=1:1000
1673 try
1674 for kk=1:length(selBlocks), set_param(selBlocks(kk),'Name',functionName2); end
1675 break;
1676 catch functionName2 = strcat(functionName,'_',num2str(i));
1677 end
1678 end
1679 for kk=1:length(selBlocks)
1680 set_param(selBlocks(kk),'Description',paramcommand);
1681 end
1682 delete(findobj(gcf,'Parent',currPanel))
1683 buildplistFigureParam()
1684
1685 else
1686 description = get_param(gcbh,'Description');
1687 funcname = findstr('functionName=',description);
1688 if funcname
1689 i = funcname+14;
1690 while ~strcmp(description(i),';'), i=i+1; end
1691 functionName = description(funcname+14:i-2);
1692 end
1693 set(hObject,'String',functionName);
1694 setappdata(0,'ltpda_currFunctionName',functionName);
1695 end
1696
1697
1698 end
1699
1700
1701
1702
1703
1704 function EnableSetCallback(hObject,varargin)
1705
1706
1707
1708 currParamID = get(hObject,'UserData');
1709 [xx,yy] = size(objName);
1710
1711 switch get(hObject,'Value')
1712 case 1
1713 jj=2;
1714 while jj<=yy && ~isempty(objName{currParamID,jj})
1715 try set(objName{currParamID,jj},'Enable','on'); set(objName{currParamID,jj},'ForegroundColor',[0 0 0]); catch end
1716 jj=jj+1;
1717 end
1718 paramEnabled(currParamID)=1;
1719 case 0
1720 jj=2;
1721 while jj<=yy && ~isempty(objName{currParamID,jj})
1722 try set(objName{currParamID,jj},'Enable','off'); set(objName{currParamID,jj},'ForegroundColor',[0.7 0.7 0.7]); catch end
1723 jj=jj+1;
1724 end
1725 paramEnabled(currParamID)=0;
1726 end
1727
1728 paramcommand = BuildParamCommand(params);
1729 for kk=1:length(selBlocks)
1730 set_param(selBlocks(kk),'Description',paramcommand);
1731 end
1732
1733 AnnotationUpdate(params);
1734 end
1735
1736
1737
1738 function SetsUpdate(hObject,varargin)
1739
1740 currSet = get(hObject,'Value');
1741 paramSets = pset(paramSets,'currSet',currSet);
1742 sets = get(hObject,'UserData');
1743 functionname = getappdata(0,'ltpda_currFunctionName');
1744 [func,classes] = strtok(get(gcbh,'Tag'));
1745 if strcmp(func,'method')
1746 params = feval(functionname,eval(strtrim(classes)),'Params',sets{currSet});
1747 else
1748 params = feval(functionname,'Params',sets{currSet});
1749 end
1750
1751 paramEnabled = zeros(1,nparams(params));
1752
1753 paramcommand = BuildParamCommand(params);
1754 for kk=1:length(selBlocks)
1755 set_param(selBlocks(kk),'Description',paramcommand);
1756 end
1757
1758
1759 for nn=1:length(selBlocks)
1760 set_param(selBlocks(nn),'AttributesFormatString','');
1761 end
1762
1763 buildplistFigureParam();
1764 end
1765
1766
1767
1768
1769
1770 function HelpButtonCallback(varargin)
1771
1772
1773 try
1774 childpath = find_system(gcbh,'LookUnderMasks','all','BlockType','M-S-Function');
1775 functionname = get_param(childpath,'Tag');
1776
1777 description = get_param(gcbh,'Description');
1778 funcname = findstr('functionName=',description);
1779 if funcname
1780 i = funcname+14;
1781 while ~strcmp(description(i),';'), i=i+1; end
1782 functionname = description(funcname+14:i-2);
1783 end
1784
1785 helptext = help(functionname);
1786 helpFigure = figure('MenuBar','none','Toolbar','none','Name',strcat(functionname,' help'),'NumberTitle','off','Units','pixels','Position',[200,200,500,300],'Resize','off','Color', get(0, 'defaultuicontrolbackgroundcolor'));
1787
1788 uicontrol('Parent',helpFigure,'Units','pixels','HorizontalAlignment','left','Position',[5 5 490 290],'FontSize',7,'String',helptext,'Visible','on','max',100,'Style','edit');
1789 catch
1790 disp('Something''s wrong with the creation of the Help figure. Please check ''HelpButtonCallback''')
1791 end
1792 end
1793
1794
1795
1796 function ResetButtonCallback(varargin)
1797
1798
1799 paramcommand = RetrievePlist();
1800
1801 if findstr(paramcommand,'functionName=''generic''')
1802 for i=1:length(selBlocks), set_param(selBlocks(i),'Name','generic'); end
1803 end
1804 eval(paramcommand)
1805 paramEnabled = zeros(1,nparams(params));
1806 for kk=1:length(selBlocks)
1807 set_param(selBlocks(kk),'Description',paramcommand);
1808 end
1809 AnnotationUpdate(params);
1810
1811 buildplistFigureParam()
1812
1813 end
1814
1815
1816
1817 function KeepResultCallback(hObject,varargin)
1818
1819
1820 switch get(hObject,'Value')
1821 case 0
1822 set_param(gcbh,'Backgroundcolor','red')
1823 set_param(gcbh,'UserData','')
1824 case 1
1825 set_param(gcbh,'Backgroundcolor','magenta')
1826 set_param(gcbh,'UserData','probe')
1827 end
1828 end
1829
1830
1831
1832 function SetNameCallback(hObject,varargin)
1833
1834
1835 setName = get(hObject,'Value');
1836 set(gcbh,'UserData',setName);
1837
1838 end
1839
1840
1841
1842
1843
1844 function LoadInputParamCallback(varargin)
1845
1846
1847
1848
1849 if length(LTPDAinvar)<1
1850
1851 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','center','Position',[(panelDimens(4)-200)/2 panelDimens(4)-100 200 30],'String','Please load at least one AO in memory','Visible','on','Style','text');
1852
1853 uicontrol('Parent',currPanel,'Units','pixels','HorizontalAlignment','center','Position',[(panelDimens(4)-200)/2 panelDimens(4)-150 200 30],'String','Add data','FontSize',8,'Visible','on','Enable','on','Callback',@AddButtonCallback,'Style','pushbutton');
1854 else
1855
1856 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','left','Position',[100 panelDimens(4)-60 50 20],'String','AO input:','Visible','on','Style','text');
1857 children=get_param(gcb,'Blocks');
1858 inputblock=strcat(gcb,'/',children{1});
1859 currAOinput=get_param(inputblock,'Value');
1860
1861 uicontrol('Parent',currPanel,'Units','pixels','HorizontalAlignment','center','Position',[170 panelDimens(4)-57 50 20],'String',currAOinput,'Visible','on','Enable','on','Callback',@InputEditCallback,'Style','edit');
1862 end
1863 end
1864
1865
1866
1867 function InputEditCallback(hObject, varargin)
1868
1869
1870
1871 newValue = str2double(get(hObject,'String'));
1872
1873 newValue = round(newValue);
1874
1875 if newValue>length(LTPDAinvar)
1876 newValue=length(LTPDAinvar);
1877 end
1878 set(hObject,'String',num2str(newValue));
1879
1880 for i=1:length(selBlocks)
1881
1882
1883
1884 children{i}=get_param(selBlocks(i),'Blocks');
1885 inputblock=strcat(strcat(get(selBlocks(i),'Path'),'/',get(selBlocks(i),'Name')),'/',children{i}{1});
1886 set_param(inputblock,'Value',num2str(newValue));
1887
1888
1889 set_param(selBlocks(i),'AttributesFormatString',num2str(newValue));
1890 end
1891 end
1892
1893
1894
1895 function AddButtonCallback(varargin)
1896
1897
1898 filenames=uipickfiles('REFilter','.txt');
1899 if ~isnumeric(filenames(1,1))
1900 [x,y]=size(filenames);
1901 for j=1:y
1902 anobject={ao(filenames{j})};
1903 LTPDAinvar=[LTPDAinvar;anobject];
1904 end
1905 disp(sprintf(' + %g AOs added to the global variable LTPDAinvar', y))
1906 buildplistFigureParam();
1907 end
1908 end
1909
1910
1911
1912 function LoadMuxParamCallback(varargin)
1913
1914
1915
1916
1917
1918 if strcmp(get(gcbh,'Tag'),'mux'),
1919
1920 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','left','Position',[100 panelDimens(4)-60 100 20],'String','Number of inputs:','Visible','on','Style','text');
1921
1922 uicontrol('Parent',currPanel,'Units','pixels','HorizontalAlignment','center','Position',[210 panelDimens(4)-57 50 20],'String',get(gcbh,'Inputs'),'Visible','on','Enable','on','Callback',@MuxEditCallback,'Style','edit');
1923 elseif strcmp(get(gcbh,'Tag'),'demux'),
1924
1925 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','left','Position',[100 panelDimens(4)-60 100 20],'String','Number of outputs:','Visible','on','Style','text');
1926
1927 uicontrol('Parent',currPanel,'Units','pixels','HorizontalAlignment','center','Position',[210 panelDimens(4)-57 50 20],'String',get(gcbh,'Outputs'),'Visible','on','Enable','on','Callback',@MuxEditCallback,'Style','edit');
1928 end
1929 end
1930
1931
1932
1933 function MuxEditCallback(hObject, varargin)
1934
1935
1936
1937 newValue = str2double(get(hObject,'String'));
1938
1939 newValue = round(newValue);
1940 set(hObject,'String',num2str(newValue));
1941 for i=1:length(selBlocks)
1942 newDimens=get(selBlocks(i),'Position');
1943 newDimens(4)=newDimens(2)+25*(newValue+1);
1944 if strcmp(get(gcbh,'Tag'),'mux'),
1945 set(selBlocks(i),'Inputs',num2str(newValue));
1946 elseif strcmp(get(gcbh,'Tag'),'demux'),
1947 set(selBlocks(i),'Outputs',num2str(newValue));
1948 end
1949 set(selBlocks(i),'Position',newDimens);
1950 end
1951 end
1952
1953
1954
1955 function LoadFromBlockCallback(varargin)
1956
1957
1958
1959 uicontrol('Parent',currPanel,'Units','pixels','HorizontalAlignment','center','Position',[(panelDimens(4)-200)/2 panelDimens(4)-100 200 30],'String','Find origin','FontSize',8,'Visible','on','Enable','on','Callback',@FindOriginCallback,'Style','pushbutton');
1960 end
1961
1962
1963
1964 function FindOriginCallback(varargin)
1965
1966
1967
1968 varName = get(gcbh,'GotoTag');
1969 origin = find_in_models(bdroot,'LookUnderMasks','all','BlockType','Goto','GotoTag',varName);
1970 if numel(origin)>1
1971
1972 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','center','Position',[(panelDimens(4)-400)/2 panelDimens(4)-160 400 30],'String','Error: there are multiple sources','Visible','on','Style','text');
1973 elseif numel(origin)==1
1974
1975 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','center','Position',[(panelDimens(4)-400)/2 panelDimens(4)-160 400 30],'String',origin{1},'Visible','on','Style','text');
1976 else
1977
1978 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','center','Position',[(panelDimens(4)-400)/2 panelDimens(4)-160 400 30],'String','Error: no source found','Visible','on','Style','text');
1979 end
1980
1981
1982
1983 end
1984
1985
1986
1987
1988
1989 function ErrorFuncNotSupported(varargin)
1990
1991
1992
1993 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','HorizontalAlignment','center','Position',[(panelDimens(4)-300)/2 panelDimens(4)-100-100 300 30],'String','Error: unable to retrieve the parameters required by this function. Maybe it''s not supported yet?','Visible','on','Style','text');
1994 end
1995
1996
1997
1998 function ErrorSelectionInconsistent(varargin)
1999
2000 uicontrol('Parent',currPanel,'Units','pixels','HorizontalAlignment','center','Position',[10 7 380 40],'String','Error: impossible to set unique parameters for the selected blocks','Visible','on','Style','text');
2001 end
2002
2003
2004
2005
2006
2007 end