⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cltidemo.m

📁 很多matlab的源代码
💻 M
📖 第 1 页 / 共 2 页
字号:
      MAKECHANGE = YES;            if strcmp(Tag, 'FilterSFreq1')	h.Filter.Freq1 = get(gco, 'Value');      else	NewFreq = str2num(get(gco, 'String'));	if ( NewFreq < get(h.Slider.FilterFreq1,'Min') ) ...	      | (NewFreq > get(h.Slider.FilterFreq1,'Max'))	  set(gco,'String',num2str(h.Filter.Freq1));	  MAKECHANGE = NO;	else	  h.Filter.Freq1 = NewFreq;	end      end            if abs(h.Filter.Freq1) <= 1e-10	h.Filter.Freq1 = 0;      end            if MAKECHANGE	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 - Update for BandPass filter	if any(h.PopUpValue==[3 4 7 8])	  set(h.Text.FilterFreq1, 'String', ['Center Freq = ' ,...		    num2str(h.Filter.Freq1)]);	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])	  [h.Filter.Range, h.Filter.FFT] = IdealFilter(h);	end		setuprop(gcbf,'Handles',h);	changeplots(h);      end    end       %==================================           case 'FilterBW'    Tag = get(gco, 'Tag');    if any(h.PopUpValue== [7 8])      MAKECHANGE = YES;            if strcmp(Tag, 'FilterSBW')	h.Filter.BW = get(gco, 'Value');      else	NewBW = str2num(get(gco, 'String'));	if ( NewBW < get(h.Slider.FilterBW,'Min') ) ...	      | (NewBW > get(h.Slider.FilterBW,'Max'))	  set(gco,'String',num2str(h.Filter.BW));	  MAKECHANGE = NO;	else	  h.Filter.BW = NewBW;	end      end            if abs(h.Filter.BW) <= 1e-10	h.Filter.BW = 10;      end            if MAKECHANGE	set(h.Edit.FilterBW, 'String', num2str(h.Filter.BW));	set(h.Slider.FilterBW, 'Value', h.Filter.BW);      	set(h.Text.FilterBW, 'String', ['Bandwidth = ' num2str(h.Filter.BW)]);	%% xxx - Update for BandPass filter	if h.PopUpValue == 7	  %if h.PopUpValue == 	  [h.Filter.Range, h.Filter.FFT] = ...	      ctfirstorderfilter('Bandpass', h.Filter.Freq1, h.Filter.BW);	  %end	else	  [h.Filter.Range, h.Filter.FFT] = ...	      ctfirstorderfilter('Bandreject', h.Filter.Freq1, h.Filter.BW);	end		setuprop(gcbf,'Handles',h);	changeplots(h);      end    end        %==================================       case 'FilterPhase'    Tag = get(gco, 'Tag');    MAKECHANGE = YES;        if strcmp(Tag, 'FilterSPhase')      h.Filter.PhaseShift = get(gco, 'Value');    else      NewPhase = str2num(get(gco, 'String'));      if ( NewPhase < get(h.Slider.FilterPhase,'Min') ) ...	    | (NewPhase > get(h.Slider.FilterPhase,'Max'))	set(gco,'String',num2str(h.Filter.PhaseShift));	MAKECHANGE = NO;      else	h.Filter.PhaseShift = NewPhase;      end    end    if abs(h.Filter.PhaseShift) <= 1e-10      h.Filter.PhaseShift = 0;    end    if MAKECHANGE      set(h.Edit.FilterPhase, 'String', num2str(h.Filter.PhaseShift));      set(h.Slider.FilterPhase, 'Value', h.Filter.PhaseShift);            set(h.Text.FilterPhase, 'String', ['Phase Slope = ' num2str(h.Filter.PhaseShift) '*pi']);      [h.Filter.Range, h.Filter.FFT] = IdealFilter(h);      setuprop(gcbf,'Handles',h);      changeplots(h);    end  %==================================     case 'Answer'  set(h.Text.OutputTitle, 'String', ...		    cosinestring(h.Output.Mag, h.Freq, ...				 h.Output.Phase, 0, h.Output.DC));  %==================================     case 'LineWidth'  h.LineWidth = linewidthdlg(h.LineWidth);  set(findobj(gcbf, 'Type', 'line'), 'LineWidth', h.LineWidth);  setuprop(gcbf,'Handles',h);  %==================================       case 'Help'    hBar = waitbar(0.25,'Opening internet browser...');    DefPath = which(mfilename);    DefPath = ['file:///' strrep(DefPath,filesep,'/') ];    URL = [ DefPath(1:end-10) , 'help/','index.html'];    if h.MATLABVER >= 6      STAT = web(URL,'-browser');    else      STAT = web(URL);    end    waitbar(1);    close(hBar);    switch STAT     case {1,2}      s = {'Either your internet browser could not be launched or' , ...	   'it was unable to load the help page.  Please use your' , ...	   'browser to read the file:' , ...	   ' ', '     index.html', ' ', ...	   'which is located in the DConvDemo help directory.'};      errordlg(s,'Error launching browser.');    end        sTitlePage = { ...	'Usage              - Using the CLTIDemo Graphical User Interface.'; ...	'README             - Version history and other important information.'; ...	'License            - License information.'; ...	'About              - Acknowledgements and contact information.'};    %helpwin(sTitlePage,'CLTIDemo Help');    %==================================   case 'CloseRequestFcn'    delete(gcbf);   otherwise    error (['Illegal Action:' action]);  end% endfunction cltidemo%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% IDEAL FILTER DESIGNfunction [ff,HH] = IdealFilter(h)  f = h.Filter.Freq1;  % bw = h.Filter.BW;  % Fixed bandwidth for Ideal filters  bw = 20;  phaseshift = h.Filter.PhaseShift;  ff = linspace(0,200,1001);  TOL = 1e-6;  HH = exp(-j*2*pi*ff*phaseshift);    %------------     if h.PopUpValue == 1    % Ideal Low Pass    HH = HH.*(abs(ff)<=f+TOL);    elseif h.PopUpValue == 2    % Ideal High Pass    HH = HH.*(abs(ff)>=f-TOL);   elseif h.PopUpValue == 3    % Ideal Band Pass    HH = HH.*(abs(abs(ff)-f) <= (bw/2)+TOL);  elseif h.PopUpValue == 4    % Ideal Band Reject    HH = HH.*(abs(abs(ff)-f) >= (bw/2)+TOL);  else    error('Ideal Filter must be 1,2,3 or 4');  end  set(h.FilterMagPlot,{'XData','YData'},{ff, abs(HH)});  set(h.FilterPhasePlot,{'XData','YData'},{ff, angle(HH)});%endfunction IdealFilter%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CHANGEPLOTSfunction changeplots(h)% Input Plothhin = h.DC + h.Amp*cos(2*pi*h.Freq*h.t + h.Phase*pi); set(h.InputPlot,'xdata',h.t,'ydata',hhin);%--- Following line was for discrete-time, not necessary in continuous-time%h.Freqmod = h.Freq; while h.Freqmod>=0.5, h.Freqmod = h.Freqmod-1; endh.Freqmod = h.Freq;  % Do this instead of search/replace for FreqMod% Filter Plotif isempty(h.Filter.FFT)  error('Invalid Filter response');endh.Filter.Mag =  abs(h.Filter.FFT);h.Filter.Phase =  angle(h.Filter.FFT);filterplot(h.Filter.Range, h.Filter.Mag, h.FilterMagPlot);Hmax = max(abs(h.Filter.Mag));set(get(h.FilterMagPlot,'Parent'),'YLim',[0, max([1,ceil(Hmax-0.05)])+0.1]);filterplot(h.Filter.Range, h.Filter.Phase, h.FilterPhasePlot);   % Output Plot[qq,k0] = min(abs(h.Filter.Range));  %<-- find DC[qq,kMag] = min(abs(h.Filter.Range-h.Freqmod));   %<-- find "positive" freq[qq,kMag2] = min(abs(h.Filter.Range+h.Freqmod));  %<-- find "negative" freqif any(h.PopUpValue==[1,2,3,4,5,6,7,8])  h.Output.Mag = h.Filter.Mag(kMag)*h.Amp;  %h.Filter.Range(kMag), h.Freqmod  h.Output.Phase = h.Filter.Phase(kMag)/pi + h.Phase;  h.Output.DC = h.Filter.FFT(k0)*h.DC;    %% This part is not used in Continuous time LTI  %else  % HHH =feval(h.Filter.freqzMethod,h.Filter.ImpResp,1,2*pi*[0,h.Freq,-h.Freq]);  % h.Output.Mag = abs(HHH(2))*h.Amp;  % h.Output.Phase = angle(HHH(2))/pi + h.Phase;  % h.Output.DC = real(HHH(1))*h.DC;endhhout = h.Output.DC + h.Output.Mag*cos(2*pi*h.Freq*h.t + h.Output.Phase*pi); set(h.OutputPlot,'xdata',h.t,'ydata',hhout);% Calculating and plotting the frequency markersif h.DC~=0    set(h.Line.FreqMagMark0,{'XData','YData'},{0,h.Filter.Mag(k0)});    set(h.Line.FreqPMark0,{'XData','YData'},{0,h.Filter.Phase(k0)});    set(h.Line.FreqMagMark0, 'Visible', 'On');      set(h.Line.FreqPMark0, 'Visible', 'On');  else    set(h.Line.FreqMagMark0, 'Visible', 'Off');      set(h.Line.FreqPMark0, 'Visible', 'Off');  endif h.Freqmod==0 & h.DC~=0    set(h.Line.FreqMagMark1, 'Visible', 'Off');      set(h.Line.FreqMagMark2, 'Visible', 'Off');      set(h.Line.FreqPMark1, 'Visible', 'Off');  else    set(h.Line.FreqMagMark1, 'Visible', 'On');      set(h.Line.FreqMagMark1,{'XData','YData'},{h.Freqmod,h.Filter.Mag(kMag)});    set(h.Line.FreqPMark1, 'Visible', 'On');      set(h.Line.FreqPMark1,{'XData','YData'},{h.Freqmod,h.Filter.Phase(kMag)});    if abs(h.Freq)<1e-5        set(h.Line.FreqMagMark2, 'Visible', 'Off');      else        set(h.Line.FreqMagMark2, 'Visible', 'On');          set(h.Line.FreqMagMark2,{'XData','YData'},...			  {-h.Freqmod,h.Filter.Mag(kMag)});    endend % Clearing the Output Titleset(h.Text.OutputTitle, 'String', '');setuprop(gcbf,'Handles',h);% endfunction changeplots%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SETHANDLESfunction Handles = sethandles(Handles,field,value)%SETHANDLES%   Handles = sethandles(Handles,field,value) sets the field to the %   given value within the structure Handles and then saves the%   structure in the current figure using SETUPROP.%%   See also SETUPROP%% Jordan RosenthalHandles = setfield(Handles,field,value);setuprop(gcbf, 'Handles', Handles);% endfunction sethandles%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% FILTERPLOTfunction filterplot(x,y, hLines)%FILTERPLOT Create Filter plot %   FILTERPLOT(x,y,hLines) changes the plot of the filter given by the handles%   in hLines to the new data x and y.%%   The input x and y should be equal length vectors.% Budiyanto Junus, 1/20/99% Modified from Jordan Rosenthal's STEMDATAset(hLines,{'XData','YData'},{x, y});% endfunction filterplot% eof: cltidemo.m

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -