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

📄 fdcheby1.m

📁 有关matlab的电子书籍有一定的帮助希望有用
💻 M
📖 第 1 页 / 共 4 页
字号:
        else
            xd2(1) = f(2);
        end
    case 2
      % L1 xdata = [f2 Fs/2 NaN f2 Fs/2]
      % L2 xdata = [0 f1]
        if i == 1
            xd2(2) = f(1);
        else
            xd1([1 4]) = f(2);
        end
    case 3  % bandpass
      % L1 xdata = [f2 f3 NaN f2 f3]
      % L2 xdata = [0 f1 NaN f4 Fs/2]
        if xd2(2) ~= f(1)
            xd2(2) = f(1);
        elseif xd1(1) ~= f(2)
            xd1([1 4]) = f(2);
        elseif xd1(2) ~= f(3)
            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)
            return
        end
        L3_1.xdata = Fp1.value([1 1]);
        if type>2
            L3_2.xdata = Fp2.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);
        fdcheby1('dirty')
   end
  
%---------------------------------------------------------------------
% fdcheby1('Rpchange')
%  Callback when Rp has changed
%  Need to update line L1
case 'Rpchange'
    type = bandpop.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];
    
    fdcheby1('dirty')

    
%---------------------------------------------------------------------
% fdcheby1('Rschange')
%  Callback when Rs has changed
%  Need to update line L2
case 'Rschange'
    type = bandpop.value;
    
    if minOrdCheckbox.value
        Rstop = Rs.value;
        if type ~= 3
            yd = [-Rstop -Rstop];
        else
            yd = [-Rstop -Rstop NaN -Rstop -Rstop];
        end
        L2.ydata = yd;
        fdcheby1('dirty')
    else
        RChangeMeas(0,type,Fs,Lresp,L1,L2,f1,f2,f3,f4,Rp,Rs)
    end

%---------------------------------------------------------------------
% fdcheby1('checkbox')
%  Callback of minimum order checkbox
case 'checkbox'
    filt = filtdes('filt');
    
    newSetOrderFlag = ~get(minOrdCheckbox,'value');
    type = bandpop.value;
    oldtype = filt.specs.fdcheby1.type;
    if ~newSetOrderFlag   % from set to estimate order 
        if filt.specs.fdcheby1.setOrderFlag
            % obtain frequencies from measurements
            c = {pbspecs(1) pbspecs(2) sbmeasures(1) sbmeasures(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.fdcheby1.f;
        end
        f = filt.specs.fdcheby1.f;
        f = [0; fdutil('changeFilterType',type,oldtype,sort(f(2:end-1))); 1];
        Fpass = [0 0];  % place holder - ignored by 'newfilt'     
    else   % from estimate to set order 
        Fpass = Fp1.value * 2/Fs;
        if type > 2
            if oldtype > 2
                Fpass(2) = Fp2.value * 2/Fs;
            else
                Fpass(2) = (Fpass(1)+1)/2;
            end
        end
        f = [];  % place holder - ignored by 'newfilt'
    end
    
    fdcheby1('newfilt',newSetOrderFlag,...
                       type,f,Rp.value,...
                       Rs.value,Fpass,order.value)
    fdcheby1('dirty')

%---------------------------------------------------------------------
% fdcheby1('newfilt',setOrderFlag,type,f,Rp,Rs,Fpass,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};
    Fpass = varargin{7};  % in range (0,1)
    N = varargin{8};
    
    bandpop.value = type;
    % save last value of bandpop in passframe userdata:
    passframe.userdata = type;
    minOrdCheckbox.value = ~setOrderFlag;
    
    co = get(0,'defaultaxescolororder');

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

        [f1,f2,f3,f4] = setupFrequencyObjects(type,'fdcheby1',...
                           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)
        set(Rs,'value',Rstop)
        set(L2,'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(sbspecs(1),'visible','off')
        set(sbspecs(2),'visible','off')
        set(sbspecs(3),'visible','off')
        
        set(L2,'color',co(min(3,size(co,1)),:))
        set(L3_1,'visible','on','xdata',Fpass([1 1])*Fs/2)     
        if type < 3  % low/high
            set(Fp1,'value',Fpass(1)*Fs/2,'range',[0 1]*Fs/2,...
               'label','Fp','callback','fdcheby1(''fchange'')',...
               'visible','on')
            Fp2.visible = 'off';
            set(L3_2,'visible','off')
        else  % pass/stop
            set(Fp1,'value',Fpass(1)*Fs/2,'range',[0 Fpass(2)]*Fs/2,...
               'label','Fp1','callback','fdcheby1(''fchange'')',...
               'visible','on')
            set(Fp2,'value',Fpass(2)*Fs/2,'range',[Fpass(1) 1]*Fs/2,...
               'label','Fp2','callback','fdcheby1(''fchange'')',...
               'visible','on')
            set(L3_2,'visible','on','xdata',Fpass([2 2])*Fs/2)     
        end
        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','fdcheby1',...
            L1,L2,0,type,f(:)',Fs,minpass,maxpass,minstop)
    else  % set order
        set(L1,'segmentdragmode',{'none'},...
               'segmentpointer',{'forbidden'},...
               'vertexdragmode',{'none'},...
               'vertexpointer',{'forbidden'})
        set(L2,'segmentdragmode',{'none'},...
               'segmentpointer',{'forbidden'},...
               'vertexdragmode',{'none'},...
               'vertexpointer',{'forbidden'})
    end
    
%---------------------------------------------------------------------
% fdcheby1('newtype')
%  callback of band configuration popup
case 'newtype'
    filt = filtdes('filt');
    newtype = bandpop.value;
    oldtype = get(passframe,'userdata');
    if isempty(oldtype)
        oldtype = filt.specs.fdcheby1.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
            Fpass = Fp1.value * 2/Fs;
            if newtype > 2
                Fpass(2) = Fp2.value * 2/Fs;
                if Fpass(2) <= Fpass(1) | Fpass(2)>1
                    Fpass(2) = (Fpass(1) + 1)/2;
                    Fp2.value = Fpass(2)*Fs/2;
                end
            end
        else
            Fpass = [0 0]; % place holder - ignored by newfilt
        end
        fdcheby1('newfilt',~minOrdCheckbox.value,newtype,f,Rp.value,...
                  Rs.value,Fpass,order.value)
        fdcheby1('dirty')
        
    else
       % disp('no change of type')
    end
    
%---------------------------------------------------------------------
% fdcheby1('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])
           
%---------------------------------------------------------------------
% fdcheby1('L1down')
%  Button down fcn of L1
% fdcheby1('L2down')
%  Button down fcn of L2
% fdcheby1('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';
        
%---------------------------------------------------------------------
% fdcheby1('L1up')
%  Button up fcn of L1
% fdcheby1('L2up')
%  Button up fcn of L2
case {'L1up', 'L2up'}
    L1.erasemode = 'normal';
    L2.erasemode = 'normal';
    Lresp.erasemode = 'normal';
    
%---------------------------------------------------------------------
% fdcheby1('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;
        newFpass1 = inbounds(xd(1),[minspacing Fp1.range(2)-minspacing]);
        if newFpass1 ~= Fp1.value
            Fp1.value = newFpass1;
            Fp2.range = [newFpass1 Fs/2];
            if newFpass1 ~= xd(1)
                L3_1.xdata = newFpass1([1 1]);
            end
        end
    else
        xd = L3_2.xdata;
        newFpass2 = inbounds(xd(1),[Fp2.range(1)+minspacing Fs/2-minspacing]);
        if newFpass2 ~= Fp2.value
            Fp2.value = newFpass2;
            Fp1.range = [0 newFpass2];
            if newFpass2 ~= xd(1)
                L3_2.xdata = newFpass2([1 1]);
            end
        end
    end

%---------------------------------------------------------------------
% fdcheby1('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]);
        xd([2 5]) = newf1;
        L1.xdata = xd;
        f1.value = newf1;
        i = 1;
    case 2  % highpass
        newf2 = inbounds(xd(ind),[f1.value+minspacing Fs/2-minspacing]);
        xd([1 4]) = newf2;

⌨️ 快捷键说明

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