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

📄 fdcheby2.m

📁 有关matlab的电子书籍有一定的帮助希望有用
💻 M
📖 第 1 页 / 共 4 页
字号:
            xd1([2 5]) = f(3);
        elseif xd2(4) ~= f(4)
            xd2(4) = f(4);
        end
    case 4
      % L1 xdata = [0 f1 NaN 0 f1 NaN f4 Fs/2 NaN f4 Fs/2]
      % L2 xdata = [f2 f3]
        if xd1(2) ~= f(1)
            xd1([2 5]) = f(1);
        elseif xd2(1) ~= f(2)
            xd2(1) = f(2);
        elseif xd2(2) ~= f(3)
            xd2(2) = f(3);
        elseif xd1(7) ~= f(4)
            xd1([7 10]) = f(4);
        end
    end
    
    if ~minOrdCheckbox.value   % set order
        passbandChange = ...
          (type==(1:4))*[1 0 0 0; 0 1 0 0;...
                 0 1 1 0; 1 0 0 1 ]*(i==(1:4))';
        if passbandChange
            fChangeMeas(i,type,Fs,Lresp,L1,L2,f1,f2,f3,f4,Rp,Rs,Fs1,Fs2)
            return
        end
        L3_1.xdata = Fs1.value([1 1]);
        if type>2
            L3_2.xdata = Fs2.value([1 1]);
        end
    else
        [xd1,xd2] = fdutil('validateBands',xd1,xd2,...
                           type,i,f,f1,f2,f3,f4,Fs);
    end

    dirty = 0; % Flag used to indicate that specs have changed.
    
    % If there's a NaN in the data being compared the if-statement will
    % fail (return false) even tough the two variables are equal.  So,
    % remove the NaNs before comparing.
    nonNaNindx_L1 = ~isnan(L1.xdata);
    nonNaNindx_xd1 = ~isnan(xd1);
    if ~isequal(xd1(nonNaNindx_xd1),L1.xdata(nonNaNindx_L1)) 
        % only set if changed
        L1.xdata = xd1;
        dirty = 1;
    end

    % If there's a NaN in the data being compared the if-statement will
    % fail (return false) even tough the two variables are equal.  So,
    % remove the NaNs before comparing.
    nonNaNindx_L2 = ~isnan(L2.xdata);
    nonNaNindx_xd2 = ~isnan(xd2);
    if ~isequal(xd2(nonNaNindx_xd2),L2.xdata(nonNaNindx_L2)) 
        % only set if changed
        L2.xdata = xd2;
        dirty = 1;
    end

    if dirty  % Specs changed; update passband limits; show dotted lines
        ax.xlimPassband = fdutil('xlimpassband',type,...
                         Fs,f1.value,f2.value,f3.value,f4.value);
        fdcheby2('dirty')
    end

%---------------------------------------------------------------------
% fdcheby2('Rpchange')
%  Callback when Rp has changed
%  Need to update line L1
case 'Rpchange'
    type = bandpop.value;
    if minOrdCheckbox.value
        Rpass = Rp.value;
        above = 0; below = -Rpass;
    
        if type ~= 4
        % 'ydata':[maxpass maxpass NaN minpass minpass]
            yd = [above above NaN below below];
        else
        % 'ydata': [ maxpass maxpass NaN minpass minpass NaN ...
        %                    maxpass maxpass NaN minpass minpass])
            yd = [above above NaN below below ...
                   above above NaN below below ];
        end
        L1.ydata = yd;
        ylim = [below above];
        dyl = (ylim(2)-ylim(1))*.15;
        
        ax.ylimPassband = ylim + [-dyl/2 dyl/2];
    
        fdcheby2('dirty')
    else
        RChangeMeas(1,type,Fs,Lresp,L1,L2,f1,f2,f3,f4,Rp,Rs,Fs1,Fs2)
    end

    
%---------------------------------------------------------------------
% fdcheby2('Rschange')
%  Callback when Rs has changed
%  Need to update line L2
case 'Rschange'
    type = bandpop.value;
    
    Rstop = Rs.value;
    if type ~= 3
        yd = [-Rstop -Rstop];
    else
        yd = [-Rstop -Rstop NaN -Rstop -Rstop];
    end
    L2.ydata = yd;
    fdcheby2('dirty')


%---------------------------------------------------------------------
% fdcheby2('checkbox')
%  Callback of minimum order checkbox
case 'checkbox'
    filt = filtdes('filt');
    
    newSetOrderFlag = ~get(minOrdCheckbox,'value');
    type = bandpop.value;
    oldtype = filt.specs.fdcheby2.type;
    if ~newSetOrderFlag   % from set to estimate order 
        if filt.specs.fdcheby2.setOrderFlag
            % obtain frequencies from measurements
            c = {pbmeasures(1) pbmeasures(2) sbspecs(1) sbspecs(2)};
            if (type==2) | (type==3)
                ind = [3 1 2 4];
            else
                ind = [1 3 4 2];
            end
            f = getFrequencyValues(oldtype,c{ind},Fs);
        else
            % obtain frequencies from filter specs field
            f = filt.specs.fdcheby2.f;
        end
        f = [0; fdutil('changeFilterType',type,oldtype,sort(f(2:end-1))); 1];
        Fstop = [0 0];  % place holder - ignored by 'newfilt'     
    else   % from estimate to set order 
        if ~filt.specs.fdcheby2.setOrderFlag
            % obtain frequencies from measurements
            Fs1temp = Fs1m;
            Fs2temp = Fs2m;
        else % obtain frequencies from specs
            Fs1temp = Fs1;
            Fs2temp = Fs2;
        end
        Fstop = Fs1temp.value * 2/Fs;
        if type > 2
            if oldtype > 2
                Fstop(2) = Fs2temp.value * 2/Fs;
            else
                Fstop(2) = (Fstop(1)+1)/2;
            end
        end
        f = [];  % place holder - ignored by 'newfilt'
    end
    
    fdcheby2('newfilt',newSetOrderFlag,...
                       type,f,Rp.value,...
                       Rs.value,Fstop,order.value)
    fdcheby2('dirty')

%---------------------------------------------------------------------
% fdcheby2('newfilt',setOrderFlag,type,f,Rp,Rs,Fstop,order)
%  set values of SPECIFICATIONS objects ...  DOES NOT DESIGN FILTER
case 'newfilt'
    setOrderFlag = varargin{2};
    type = varargin{3};
    f = varargin{4};     % in range (0,1)
    Rpass = varargin{5};
    Rstop = varargin{6};
    Fstop = varargin{7};  % in range (0,1)
    N = varargin{8};

    co = get(0,'defaultaxescolororder');
    
    bandpop.value = type;
    % save last value of bandpop in passframe userdata:
    passframe.userdata = type;
    minOrdCheckbox.value = ~setOrderFlag;

    if ~setOrderFlag  % estimate order
        % initialize specs:
        order = order1;
        set(order0,'visible','off')

        [f1,f2,f3,f4] = setupFrequencyObjects(type,'fdcheby2',...
                           pbspecs,sbspecs,f,Fs,ax);
        
        pbspecs(1).visible = 'on';
        pbspecs(3).visible = 'on';
        sbspecs(1).visible = 'on';
        sbspecs(3).visible = 'on';
                
        Rp = pbspecs(3);
        Rs = sbspecs(3);
        set(Rp,'value',Rpass,'label','Rp','callback','fdcheby2(''Rpchange'')')
        set(Rs,'value',Rstop,'label','Rs','callback','fdcheby2(''Rschange'')')
                
        L1.color = co(min(2,size(co,1)),:);
        set(L3_1,'visible','off')     
        set(L3_2,'visible','off')     
    else  % set order
        order = order0;
        set(order0,'visible','on')
                        
        set(pbspecs(1),'visible','off')
        set(pbspecs(2),'visible','off')
        set(pbspecs(3),'visible','off')
               
        set(L3_1,'visible','on','xdata',Fstop([1 1])*Fs/2)     
        if type < 3  % low/high
            set(Fs1,'value',Fstop(1)*Fs/2,'range',[0 1]*Fs/2,...
               'label','Fs','callback','fdcheby2(''fchange'')',...
               'visible','on')
            Fs2.visible = 'off';
            set(L3_2,'visible','off')
        else  % pass/stop
            set(Fs1,'value',Fstop(1)*Fs/2,'range',[0 Fstop(2)]*Fs/2,...
               'label','Fs1','callback','fdcheby2(''fchange'')',...
               'visible','on')
            set(Fs2,'value',Fstop(2)*Fs/2,'range',[Fstop(1) 1]*Fs/2,...
               'label','Fs2','callback','fdcheby2(''fchange'')',...
               'visible','on')
            set(L3_2,'visible','on','xdata',Fstop([2 2])*Fs/2)     
        end
                
        L1.color = co(min(3,size(co,1)),:);
        order.value = N;
    end

    if ax.xlimbound(2) ~= Fs/2
        set(ax,'xlimbound',[0 Fs/2],'xlim',[0 Fs/2])
    end
    
    if ~setOrderFlag  % estimate order
        minpass = -Rpass;
        maxpass = 0;
        minstop = -Rstop;
        fdutil('setLines','fdcheby2',L1,L2,0,...
                          type,f(:)',Fs,minpass,maxpass,minstop)
    else  % set order
        set(L1,'segmentdragmode',{'none'},...
               'segmentpointer',{'forbidden'},...
               'vertexdragmode',{'none'},...
               'vertexpointer',{'forbidden'})
    end
    
%---------------------------------------------------------------------
% fdcheby2('newtype')
%  callback of band configuration popup
case 'newtype'
    filt = filtdes('filt');
    newtype = bandpop.value;
    oldtype = get(passframe,'userdata');
    if isempty(oldtype)
        oldtype = filt.specs.fdcheby2.type;
    end
    passframe.userdata = newtype;
    if (newtype ~= oldtype) | strcmp(filtdes('getenable'),'on')
        if oldtype < 3  % low or high pass
            edges = [f1.value f2.value]'*2/Fs;
        else
            edges = [f1.value f2.value f3.value f4.value]'*2/Fs;
        end
        edges = fdutil('changeFilterType',newtype,oldtype,edges);
        f = [0; edges(:); 1];
        
        if ~minOrdCheckbox.value
            Fstop = Fs1.value * 2/Fs;
            if newtype > 2
                Fstop(2) = Fs2.value * 2/Fs;
                if Fstop(2) <= Fstop(1) | Fstop(2)>1
                    Fstop(2) = (Fstop(1) + 1)/2;
                    Fs2.value = Fstop(2)*Fs/2;
                end
            end
        else
            Fstop = [0 0]; % place holder - ignored by newfilt
        end
        fdcheby2('newfilt',~minOrdCheckbox.value,newtype,f,Rp.value,...
                  Rs.value,Fstop,order.value)
        fdcheby2('dirty')
        
    else
       % disp('no change of type')
    end
    
%---------------------------------------------------------------------
% fdcheby2('Lrespdown')
%  Button down fcn of Lresp (response line) - pan
case 'LrespDown'
    bounds.xlim = [0 Fs/2];
    bounds.ylim = [-500 30];
    h = ax.h;
    panfcn('Ax',h,...
           'Bounds',bounds,...
           'UserHand',get(h,'zlabel'),...
           'Invisible',[L3_1.h L3_2.h])
           
%---------------------------------------------------------------------
% fdcheby2('L1down')
%  Button down fcn of L1
% fdcheby2('L2down')
%  Button down fcn of L2
% fdcheby2('L3_down',i)
%   buttondown fcn of stopband edge line 1 or 2 (i==1 or 2)
case {'L1down', 'L2down', 'L3_down'}
    L1.erasemode = 'xor';
    L2.erasemode = 'xor';
        
%---------------------------------------------------------------------
% fdcheby2('L1up')
%  Button up fcn of L1
% fdcheby2('L2up')
%  Button up fcn of L2
case {'L1up', 'L2up'}
    L1.erasemode = 'normal';
    L2.erasemode = 'normal';
    Lresp.erasemode = 'normal';
    
%---------------------------------------------------------------------
% fdcheby2('L3_drag',ind)
%  segment drag callback of L3_1 and L3_2 - stopband edge frequency lines
%  Inputs:
%     ind - index of line being dragged, 1 or 2
case 'L3_drag'
    ind = varargin{2};
    minspacing = Fs/500;
    if ind == 1
        xd = L3_1.xdata;
        newFstop1 = inbounds(xd(1),[minspacing Fs1.range(2)-minspacing]);
        if newFstop1 ~= Fs1.value
            Fs1.value = newFstop1;
            Fs2.range = [newFstop1 Fs/2];
            if newFstop1 ~= xd(1)
                L3_1.xdata = newFstop1([1 1]);
            end
        end
    else
        xd = L3_2.xdata;
        newFstop2 = inbounds(xd(1),[Fs2.range(1)+minspacing Fs/2-minspacing]);
        if newFstop2 ~= Fs2.value
            Fs2.value = newFstop2;
            Fs1.range = [0 newFstop2];
            if newFstop2 ~= xd(1)
                L3_2.xdata = newFstop2([1 1]);
            end
        end
    end

%---------------------------------------------------------------------
% fdcheby2('L1drag',type,ind)
%  vertex drag callback of L1 - passband line
%  Inputs:
%     type - band configuration 1==low, 2=high, 3=pass, 4=stop
%     ind - index of vertex being dragged
case 'L1drag'
    type = varargin{2};
    ind = varargin{3};
    xd = L1.xdata;
    minspacing = Fs/500;
    switch type
    case 1  % lowpass
        newf1 = inbounds(xd(ind),[minspacing f2.value-minspacing]);

⌨️ 快捷键说明

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