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

📄 fdellip.m

📁 有关matlab的电子书籍有一定的帮助希望有用
💻 M
📖 第 1 页 / 共 3 页
字号:
    % 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);
        fdellip('dirty')                 
    end
    
%---------------------------------------------------------------------
% fdellip('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];
    
    fdellip('dirty')

    
%---------------------------------------------------------------------
% fdellip('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;
    fdellip('dirty')

%---------------------------------------------------------------------
% fdellip('checkbox')
%  Callback of minimum order checkbox
case 'checkbox'
    filt = filtdes('filt');
    
    newSetOrderFlag = ~get(minOrdCheckbox,'value');
    type = bandpop.value;
    oldtype = filt.specs.fdellip.type;
    if ~newSetOrderFlag   % from set to estimate order 
        if filt.specs.fdellip.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.fdellip.f;
        end
        f = filt.specs.fdellip.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
    
    fdellip('newfilt',newSetOrderFlag,...
                       type,f,Rp.value,...
                       Rs.value,Fpass,order.value)
    fdellip('dirty')

%---------------------------------------------------------------------
% fdellip('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;

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

        [f1,f2,f3,f4] = setupFrequencyObjects(type,'fdellip',...
                           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(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(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','fdellip(''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','fdellip(''fchange'')',...
               'visible','on')
            set(Fp2,'value',Fpass(2)*Fs/2,'range',[Fpass(1) 1]*Fs/2,...
               'label','Fp2','callback','fdellip(''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','fdellip',L1,L2,setOrderFlag,...
                          type,f(:)',Fs,minpass,maxpass,minstop)
    else  % set order
        set(L1,'segmentdragmode',{'none'},...
               'segmentpointer',{'forbidden'},...
               'vertexdragmode',{'none'},...
               'vertexpointer',{'forbidden'})
    end
    
%---------------------------------------------------------------------
% fdellip('newtype')
%  callback of band configuration popup
case 'newtype'
    filt = filtdes('filt');
    newtype = bandpop.value;
    oldtype = get(passframe,'userdata');
    if isempty(oldtype)
        oldtype = filt.specs.fdellip.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
        fdellip('newfilt',~minOrdCheckbox.value,newtype,f,Rp.value,...
                  Rs.value,Fpass,order.value)
        fdellip('dirty')
        
    else
       % disp('no change of type')
    end
    
%---------------------------------------------------------------------
% fdellip('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])
           
%---------------------------------------------------------------------
% fdellip('L1down')
%  Button down fcn of L1
% fdellip('L2down')
%  Button down fcn of L2
% fdellip('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';
        
%---------------------------------------------------------------------
% fdellip('L1up')
%  Button up fcn of L1
% fdellip('L2up')
%  Button up fcn of L2
case {'L1up', 'L2up'}
    L1.erasemode = 'normal';
    L2.erasemode = 'normal';
    Lresp.erasemode = 'normal';
    
%---------------------------------------------------------------------
% fdellip('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

%---------------------------------------------------------------------
% fdellip('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;
        L1.xdata = xd;
        f2.value = newf2;
        i = 2;
    case 3  % bandpass
    % L1 xdata = [f2 f3 NaN f2 f3]
        if any(ind == [1 4])   % dragging f2
            newf2 = inbounds(xd(ind),[f1.value+minspacing f3.value-minspacing]);
            xd([1 4]) = newf2;
            L1.xdata = xd;
            f2.value = newf2;
            i = 2;
        else % dragging f3
            newf3 = inbounds(xd(ind),[f2.value+minspacing f4.value-minspacing]);
            xd([2 5]) = newf3;
            L1.xdata = xd;
            f3.value = newf3;
            i = 3;
        end
    case 4   % bandstop
    % L1 xdata = [0 f1 NaN 0 f1 NaN f4 Fs/2 NaN f4 Fs/2]
        if any(ind == [2 5])   % dragging f1
            newf1 = inbounds(xd(ind),[minspacing f2.value-minspacing]);
            xd([2 5]) = newf1;
            L1.xdata = xd;
            f1.value = newf1;
            i = 1;
        else % dragging f4
            newf4 = inbounds(xd(ind),[f3.value+minspacing Fs/2-minspacing]);
            xd([7 10]) = newf4;
            L1.xdata = xd;
            f4.value = newf4;
            i = 4;
        end
    end
    ax.xlimPassband = fdutil('xlimpassband',type,...
                         Fs,f1.value,f2.value,f3.value,f4.value);

%---------------------------------------------------------------------
% fdellip('L2drag',type,ind)
%  drag callback of L2 - stopband line
%  Inputs:
%     type - band configuration 1==low, 2=high, 3=pass, 4=stop
%     ind - index of vertex being dragged
case 'L2drag'
    type = varargin{2};
    ind = varargin{3};
    xd = L2.xdata;
    minspacing = Fs/500;
    switch type
    case 1  % lowpass
        newf2 = inbounds(xd(ind),[f1.value+minspacing Fs/2-minspacing]);
        xd(1) = newf2;
        L2.xdata = xd;
        f2.value = newf2;
        i = 2;
    case 2  % highpass
        newf1 = inbounds(xd(ind),[minspacing f2.value-minspacing]);
        xd(2) = newf1;
        L2.xdata = xd;
        f1.value = newf1;
        i = 1;
    case 3  % bandpass
    % L2 xdata = [0 f1 NaN f4 Fs/2]
        if ind == 2   % dragging f1
            newf1 = inbounds(xd(ind),[minspacing f2.value-minspacing]);
            xd(2) = newf1;
            L2.xdata = xd;
            f1.value = newf1;
            i = 1;
        else % dragging f4
            newf4 = inbounds(xd(ind),[f3.value+minspacing Fs/2-minspacing]);
            xd(4) = newf4;
            L2.xdata = xd;
            f4.value = newf4;
            i = 4;
        end
    case 4   % bandstop
    % L2 xdata = [f2 f3]
        if ind == 1   % dragging f2
            newf2 = inbounds(xd(ind),[f1.value+minspacing f3.value-minspacing]);
            xd(1) = newf2;
            L2.xdata = xd;
            f2.value = newf2;
            i = 2;
        else % dragging f3
            newf3 = inbounds(xd(ind),[f2.value+minspacing f4.value-minspacing]);
            xd(2) = newf3;
            L2.xdata = xd;
            f3.value = newf3;
            i = 3;
        end
    end
    
%---------------------------------------------------------------------
% fdellip('Rpdrag',type,ind)
%  drag callback of L1 - passband line
%  Inputs:
%     type - band configuration 1==low, 2=high, 3=pass, 4=stop
%     ind - index of segment being dragged
case 'Rpdrag'
    type = varargin{2};
    ind = varargin{3};
    yd = L1.ydata;
    
    below = yd(ind);
    if below >= 0 
        below = -.00001;
    elseif below < -10
        below = -10;
    end
    above = 0;
    
    newRp = above-below;

    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 ...
               NaN above above NaN below below ];
    end
    L1.ydata = yd;
    Rp.value = newRp;

⌨️ 快捷键说明

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