📄 cltidemo.m
字号:
function cltidemo(action)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% NOTE: The GUI layout provided by CLTIGUI uses character units to be platform% independent. CLTIDEMO calls CLTIGUI to provide the basic GUI layout % and then changes all units/fontunits to normalized to provide accurate% resizing response.% The actual response to a resize operation depends on the Matlab version% (see the comments in the 'ResizeFcn' case).%% Because of the changes made by CLTIDEMO to the layout from CLTIGUI, the% GUIDE layout tool should NOT be used on the figure created by CLTIDEMO.% When using the GUIDE tool for GUI layout, run CLTIGUI directly and keep % all units as characters.%% The font setup in CLTIGUI is overriden by CLTIDEMO as well, so when % making font changes, it will be necessary to change the settings in the% SETUPFONTS file.%% - Jordan Rosenthal%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% NO = 0; YES = 1; if nargin == 0 action = 'Initialize'; else % Note: getuprop/setuprop "obsoleted" in Matlab 5.3 h = getuprop(gcbf, 'Handles'); %GETUPROP Get value of user-defined property. %GCBF Get handle to current callback figure. end switch action case 'Initialize' %--- Check the installation, the Matlab Version, and the Screen Size ---% errCmd = 'errordlg(lasterr,''Error Initializing Figure''); error(lasterr);'; cmdCheck1 = 'installcheck;'; cmdCheck2 = 'h.MATLABVER = versioncheck(5.1);'; cmdCheck3 = 'screensizecheck([800 600]);'; cmdCheck4 = ['adjustpath(''' mfilename ''');']; eval(cmdCheck1,errCmd); % Simple installation check eval(cmdCheck2,errCmd); % Check Matlab Version eval(cmdCheck3,errCmd); % Check Screen Size eval(cmdCheck4,errCmd); % Adjust path if necessary %--- Set up GUI ---% if h.MATLABVER == 5.1 gui51; else gui; end % Version string for figure title strVersion = '2.03'; set(gcf, 'Name', ['CLTI (Linear Time Invariant) System Demo ver ' ,... strVersion]); % Sets the linewidth of the graph of mag. and phase of filters. h.LineWidth = 2.0; h.FigPos = get(gcf,'Pos'); % Platform dependent code to determine SCALE parameter SCALE = getfontscale; % Setup fonts: override default fonts used in cltigui setfonts(gcf,SCALE); % Change all 'units'/'font units' to normalized configresize(gcf); % Get GUI graphic handles h = gethandles(h); % Create default plots h = defaultplots(h); % Store handles as new userproperty setuprop(gcf, 'Handles', h); % Make figure inaccessible from command line set(gcf,'HandleVisibility','callback'); %================================== case 'SetFigureSize' % Center figure on screen OldUnits = get([0; gcf], 'units'); set([0; gcf],'units','pixels'); ScreenSize = get(0,'ScreenSize'); FigPos = get(gcf,'Position'); newFigPos = [ (ScreenSize(3)-FigPos(3))/2 ,... (ScreenSize(4)-FigPos(4))/2 FigPos(3:4) ]; set(gcf,'Pos',newFigPos); set([0; gcf],{'units'},OldUnits); %================================== case 'ResizeFcn' % Fix for bugs in normalized fontunits in Matlab 5.2. % Force constant figure aspect ratio if in Matlab 5.3. % Version dependent resize code FigPos = resizefcn(h.FigPos,gcbo,h.MATLABVER); switch computer case 'MAC2' % On MAC, baseline of text inside edit boxes remains at same % vertical position irregardless of change in font size. % To properly align text, here the old edit boxes are deleted % and new ones created with the proper size. hEd = findall(gcbf,'type','uicontrol','style','edit'); OldFontUnits = get(hEd,'FontUnits'); set(hEd,'FontUnits','Pixels'); hEdNew = zeros(size(hEd)); relHeightChange = FigPos(4)/h.FigPos(4); for i = 1:length(hEd) Props = get(hEd(i)); FontSize = relHeightChange*Props.FontSize; Props = rmfield(Props,{'Extent','Type','FontSize','FontUnits'}); delete(hEd(i)); hEdNew(i) = uicontrol('FontUnits','Pixels', ... 'FontSize',FontSize,Props); end set(hEdNew,{'FontUnits'},OldFontUnits); h = gethandles(h); setuprop(gcbf,'Handles',h); end % Store old position sethandles(h,'FigPos',FigPos); %================================== case 'ChangeAmp' Tag = get(gco, 'Tag'); MAKECHANGE = YES; if strcmp(Tag, 'SAmplitude') h.Amp = get(gco, 'Value'); else NewAmp = str2num(get(gco, 'String')); if ( NewAmp < get(h.Slider.Amp,'Min') ) ... | (NewAmp > get(h.Slider.Amp,'Max')) set(gco,'String',num2str(h.Amp)); MAKECHANGE = NO; else h.Amp = NewAmp; end end if MAKECHANGE set(h.Edit.Amp, 'String', num2str(h.Amp)); set(h.Slider.Amp, 'Value', h.Amp); set(h.Text.Amp, 'String', ['Amplitude = ' num2str(h.Amp)]); set(h.Text.InputTitle, 'String',... cosinestring(h.Amp, h.Freq, h.Phase, 0, h.DC)); setuprop(gcbf,'Handles',h); changeplots(h); end %================================== case 'ChangeDC' Tag = get(gco, 'Tag'); MAKECHANGE = YES; if strcmp(Tag, 'SDC') h.DC = get(gco, 'Value'); else NewDC = str2num(get(gco, 'String')); if ( NewDC < get(h.Slider.DC,'Min') ) ... | (NewDC > get(h.Slider.DC,'Max')) set(gco,'String',num2str(h.DC)); MAKECHANGE = NO; else h.DC = NewDC; end end if abs(h.DC) <= 1e-7 h.DC = 0; end if MAKECHANGE set(h.Edit.DC, 'String', num2str(h.DC)); set(h.Slider.DC, 'Value', h.DC); set(h.Text.DC, 'String', ['DC Level = ' num2str(h.DC)]); set(h.Text.InputTitle, 'String',... cosinestring(h.Amp, h.Freq, h.Phase, 0, h.DC)); setuprop(gcbf,'Handles',h); changeplots(h); end %================================== case 'ChangeFreq' Tag = get(gco, 'Tag'); MAKECHANGE = YES; if strcmp(Tag, 'SFreq') NewFreq = get(gco, 'Value'); else NewFreq = str2num(get(gco, 'String')); if ( NewFreq < get(h.Slider.Freq,'Min') ) ... | (NewFreq > get(h.Slider.Freq,'Max')) set(gco,'String',num2str(h.Freq)); MAKECHANGE = NO; end end h.Freq = NewFreq; if abs(h.Freq) <= 1e-7 h.Freq = 0; end if MAKECHANGE set(h.Edit.Freq, 'String', num2str(h.Freq)); set(h.Slider.Freq, 'Value', h.Freq); set(h.Text.Freq, 'String', ['Frequency = ' num2str(h.Freq)]); set(h.Text.InputTitle, 'String', ... cosinestring(h.Amp, h.Freq, h.Phase, 0, h.DC)); setuprop(gcbf,'Handles',h); changeplots(h); end %================================== case 'ChangePhase' Tag = get(gco, 'Tag'); MAKECHANGE = YES; if strcmp(Tag, 'SPhase') h.Phase = get(gco, 'Value'); else NewPhase = str2num(get(gco, 'String')); if ( NewPhase < get(h.Slider.Phase,'Min') ) ... | (NewPhase > get(h.Slider.Phase,'Max')) set(gco,'String',num2str(h.Phase)); MAKECHANGE = NO; else h.Phase = NewPhase; end end if abs(h.Phase) <= 1e-7 h.Phase = 0; end if MAKECHANGE set(h.Edit.Phase, 'String', num2str(h.Phase)); set(h.Slider.Phase, 'Value', h.Phase); set(h.Text.Phase, 'String', ['Phase = ' num2str(h.Phase) '*pi']); set(h.Text.InputTitle, 'String',... cosinestring(h.Amp, h.Freq, h.Phase, 0, h.DC)); setuprop(gcbf,'Handles',h); changeplots(h); end %================================== case 'FilterChoice' h.PopUpValue = get(gco, 'Value'); if any(h.PopUpValue == (1:8)) set(h.Slider.FilterFreq1, 'Min', 0.0, 'Max', 100.0); set(h.UserhnGroup, 'Visible', 'Off'); set(h.FilterSpecs, 'Visible', 'On'); set(h.PhaseGroup, 'Visible', 'Off'); set(h.FilterBWGroup, 'Visible', 'Off'); set(h.Edit.FilterFreq1, 'CallBack', 'cltidemo FilterFreq1'); set(h.Edit.FilterFreq1, 'String', num2str(h.Filter.Freq1)); set(h.Slider.FilterFreq1, 'Value', h.Filter.Freq1); set(h.Text.FilterFreq1, 'String', ['Cutoff Freq = ' ,... num2str(h.Filter.Freq1)]); %% xxx - Bandpass filter if any(h.PopUpValue==[3 4 7 8]) set(h.Text.FilterFreq1, 'String', ['Center Freq = ' ,... num2str(h.Filter.Freq1)]); if any(h.PopUpValue == [7 8]) set(h.FilterBWGroup, 'Visible', 'On'); end end % Bandpass , Highpass if any(h.PopUpValue == [3,4,6,7,8]) set(h.Slider.FilterFreq1, 'Min', 20, 'Max', 100); if any(h.PopUpValue == [3 4]) set(h.PhaseGroup, 'Visible', 'On'); end if h.Filter.Freq1 < 20 | h.Filter.Freq1 > 100 h.Filter.Freq1 = 50; set(h.Edit.FilterFreq1, 'String', num2str(h.Filter.Freq1)); set(h.Slider.FilterFreq1, 'Value', h.Filter.Freq1); set(h.Text.FilterFreq1, 'String', ['Cutoff Freq = ' ,... num2str(h.Filter.Freq1)]); if any(h.PopUpValue==[3 4 7 8]) set(h.Text.FilterFreq1, 'String', ['Center Freq = ' ,... num2str(h.Filter.Freq1)]); set(h.Text.FilterBW, 'String', ['Bandwidth = ', ... num2str(h.Filter.BW)]); end end else set(h.Slider.FilterFreq1, 'Min', 10.0, 'Max', 100.0); end if any(h.PopUpValue == [5,6,7,8]) if h.PopUpValue == 5 [h.Filter.Range, h.Filter.FFT] = ... ctfirstorderfilter('Lowpass', h.Filter.Freq1, ''); elseif h.PopUpValue == 6 [h.Filter.Range, h.Filter.FFT] = ... ctfirstorderfilter('Highpass', h.Filter.Freq1, ''); elseif h.PopUpValue == 7 [h.Filter.Range, h.Filter.FFT] = ... ctfirstorderfilter('Bandpass', h.Filter.Freq1, h.Filter.BW); else [h.Filter.Range, h.Filter.FFT] = ... ctfirstorderfilter('Bandreject', h.Filter.Freq1, h.Filter.BW); end elseif any(h.PopUpValue == [1,2,3,4]) set(h.PhaseGroup, 'Visible', 'On'); set(h.Text.FilterPhase, 'String', ['Phase Slope = ' ,... num2str(h.Filter.PhaseShift) '*pi']); [h.Filter.Range, h.Filter.FFT] = IdealFilter(h); end %elseif h.PopUpValue==9 % set(h.FilterSpecs, 'Visible', 'Off'); % set(h.Text.FilterFreq1, 'String', 'Filter Coeffs: b_k'); % set(h.Edit.bk, 'String', h.Filter.bk); % eval( ['h.Filter.ImpResp = ',h.Filter.bk,';']); % h.Filter.FFT = [ ]; % set(h.UserhnGroup, 'Visible', 'On'); end setuprop(gcbf,'Handles',h); changeplots(h); %================================== case 'Userhn' Tag = get(gco, 'Tag'); h.Filter.bk = get(gco, 'String'); set(h.Edit.bk, 'String', h.Filter.bk); eval( ['h.Filter.ImpResp = ',h.Filter.bk,';']); h.Filter.FFT = [ ]; setuprop(gcbf,'Handles',h); changeplots(h); %================================== case 'FilterFreq1' Tag = get(gco, 'Tag'); if any(h.PopUpValue==(1:8))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -