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

📄 fdbutter.m

📁 matlabDigitalSigalProcess内有文件若干
💻 M
📖 第 1 页 / 共 4 页
字号:
            xd1([7 10]) = f(4);
        end
    end
    
    if minOrdCheckbox.value
        [xd1,xd2] = fdutil('validateBands',xd1,xd2,...
                           type,i,f,f1,f2,f3,f4,Fs);
        fdbutter('dirty')
    else
        fChangeMeas(i,type,Fs,Lresp,L1,L2,f1,f2,f3,f4,Rp,Rs)
        return
    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 have changed; update passband limits
        ax.xlimPassband = fdutil('xlimpassband',type,...
                         Fs,f1.value,f2.value,f3.value,f4.value);
    end
    
    % fdutil('updateRanges',i,f1,f2,f3,f4)    % update ranges
    
%---------------------------------------------------------------------
% fdbutter('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];
    
        fdbutter('dirty')
    else
        RChangeMeas(1,type,Fs,Lresp,L1,L2,f1,f2,f3,f4,Rp,Rs)
    end

    
%---------------------------------------------------------------------
% fdbutter('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;
        fdbutter('dirty')
    else
        RChangeMeas(0,type,Fs,Lresp,L1,L2,f1,f2,f3,f4,Rp,Rs)
    end


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


%---------------------------------------------------------------------
% fdbutter('newfilt',setOrderFlag,type,f,Rp,Rs,w3db,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};
    w3db = 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:
        passframe.visible = 'on';
        stopframe.visible = 'on';
        order = order1;
        set(order0,'visible','off')

        [f1,f2,f3,f4] = setupFrequencyObjects(type,'fdbutter',...
                           pbspecs,sbspecs,f,Fs,ax);
        
        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','fdbutter(''Rpchange'')')
        set(Rs,'value',Rstop,'label','Rs','callback','fdbutter(''Rschange'')')
                
        L1.color = co(min(2,size(co,1)),:);
        L2.color = co(min(2,size(co,1)),:);   
        set(L3db1,'visible','off')     
        set(L3db2,'visible','off')     
    else  % set order
        passframe.visible = 'off';
        stopframe.visible = 'off';
        order = order0;
        set(order0,'visible','on')
                        
        w3db1 = pbspecs(1);
        w3db2 = pbspecs(2);
        set(pbspecs(3),'visible','off')
        set(sbspecs(1),'visible','off')
        set(sbspecs(2),'visible','off')
        set(sbspecs(3),'visible','off')
       
        set(L3db1,'visible','on','xdata',w3db([1 1])*Fs/2)     
        if type < 3  % low/high
            set(w3db1,'value',w3db(1)*Fs/2,'range',[0 1]*Fs/2,...
               'label','F3db','callback','fdbutter(''fchange'')',...
               'visible','on')
            w3db2.visible = 'off';
            set(L3db2,'visible','off')
        else  % pass/stop
            set(w3db1,'value',w3db(1)*Fs/2,'range',[0 w3db(2)]*Fs/2,...
               'label','F3db 1','callback','fdbutter(''fchange'')',...
               'visible','on')
            set(w3db2,'value',w3db(2)*Fs/2,'range',[w3db(1) 1]*Fs/2,...
               'label','F3db 2','callback','fdbutter(''fchange'')',...
               'visible','on')
            set(L3db2,'visible','on','xdata',w3db([2 2])*Fs/2)     
        end
                
        L1.color = co(min(3,size(co,1)),:);
        L2.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','fdbutter',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
    
%---------------------------------------------------------------------
% fdbutter('newtype')
%  callback of band configuration popup
case 'newtype'
    filt = filtdes('filt');
    newtype = bandpop.value;
    oldtype = get(passframe,'userdata');
    if isempty(oldtype)
        oldtype = filt.specs.fdbutter.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
            w3db = w3db1.value * 2/Fs;
            if newtype > 2
                w3db(2) = w3db2.value * 2/Fs;
                if w3db(2) <= w3db(1) | w3db(2)>1
                    w3db(2) = (w3db(1) + 1)/2;
                    w3db2.value = w3db(2)*Fs/2;
                end
            end
        else
            w3db = [0 0]; % place holder - ignored by newfilt
        end
        fdbutter('newfilt',~minOrdCheckbox.value,newtype,f,Rp.value,...
                  Rs.value,w3db,order.value)
        fdbutter('dirty')
        
    else
       % disp('no change of type')
    end
    
%---------------------------------------------------------------------
% fdbutter('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',[L3db1.h L3db2.h])
           
%---------------------------------------------------------------------
% fdbutter('L1down')
%  Button down fcn of L1
% fdbutter('L2down')
%  Button down fcn of L2
% fdbutter('3db_down',i)
%   buttondown fcn of 3db line 1 or 2 (i==1 or 2)
case {'L1down', 'L2down', '3db_down'}
    L1.erasemode = 'xor';
    L2.erasemode = 'xor';
   
%---------------------------------------------------------------------
% fdbutter('L1up')
%  Button up fcn of L1
% fdbutter('L2up')
%  Button up fcn of L2
case {'L1up', 'L2up'}
    L1.erasemode = 'normal';
    L2.erasemode = 'normal';
    Lresp.erasemode = 'normal';
    
%---------------------------------------------------------------------
% fdbutter('3db_drag',ind)
%  segment drag callback of L3db1 and L3db2 - 3db frequency lines
%  Inputs:
%     ind - index of line being dragged, 1 or 2
case '3db_drag'
    ind = varargin{2};
    minspacing = Fs/500;
    if ind == 1
        xd = L3db1.xdata;
        newf3db1 = inbounds(xd(1),[minspacing w3db1.range(2)-minspacing]);
        if newf3db1 ~= w3db1.value
            w3db1.value = newf3db1;
            w3db2.range = [newf3db1 Fs/2];
            if newf3db1 ~= xd(1)
                L3db1.xdata = newf3db1([1 1]);
            end
        end
    else
        xd = L3db2.xdata;
        newf3db2 = inbounds(xd(1),[w3db2.range(1)+minspacing Fs/2-minspacing]);
        if newf3db2 ~= w3db2.value
            w3db2.value = newf3db2;
            w3db1.range = [0 newf3db2];
            if newf3db2 ~= xd(1)
                L3db2.xdata = newf3db2([1 1]);
            end
        end
    end

%---------------------------------------------------------------------
% fdbutter('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
    if minOrdCheckbox.value
%         [n,w3db] = estimateOrder(type,Rp.value,Rs.value,Fs,...
%                  f1.value,f2.value,f3.value,f4.value);
%         order.value = n;
%         w3db1m.value = w3db(1) * Fs/2;
%         if length(w3db)>1
%             w3db2m.value = w3db(2) * Fs/2;
%         end
    else

⌨️ 快捷键说明

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