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

📄 fdremez.m

📁 matlabDigitalSigalProcess内有文件若干
💻 M
📖 第 1 页 / 共 3 页
字号:
            xd1(2) = f(1);
            i = 1;
        else
            xd2([1 4]) = f(2);
            i = 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);
            i = 1;
        elseif xd1(1) ~= f(2)
            xd1([1 4]) = f(2);
            i = 2;
        elseif xd1(2) ~= f(3)
            xd1([2 5]) = f(3);
            i = 3;
        elseif xd2(4) ~= f(4)
            xd2(4) = f(4);
            i = 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);
            i = 1;
        elseif xd2(1) ~= f(2)
            xd2(1) = f(2);
            i = 2;
        elseif xd2(2) ~= f(3)
            xd2(2) = f(3);
            i = 3;
        elseif xd1(7) ~= f(4)
            xd1([7 10]) = f(4);
            i = 4;
        end
    end
    [xd1,xd2] = fdutil('validateBands',xd1,xd2,...
                       type,i,f,f1,f2,f3,f4,Fs);

    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,f(1),f(2),f(3),f(4));
       fdremez('dirty')
   end
   
%---------------------------------------------------------------------
% fdremez('Rpchange')
%  Callback when Rp has changed
%  Need to update line L1
case 'Rpchange'

    Rpass = Rp.value;
    dev = (10^(Rpass/20)-1)/(10^(Rpass/20)+1);
    above = 20*log10(1+dev); below = 20*log10(1-dev);

    type = bandpop.value;
    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;
    ylim = [below above];
    dyl = (ylim(2)-ylim(1))*.15;
    ax.ylimPassband = ylim + [-dyl/2 dyl/2];

    fdremez('dirty')
    
%---------------------------------------------------------------------
% fdremez('Rschange')
%  Callback when Rs has changed
%  Need to update line L2
case 'Rschange'

    Rstop = Rs.value;
    type = bandpop.value;
    if type ~= 3
        yd = [-Rstop -Rstop];
    else
        yd = [-Rstop -Rstop NaN -Rstop -Rstop];
    end
    L2.ydata = yd;

    fdremez('dirty')

%---------------------------------------------------------------------
% fdremez('checkbox')
%  Callback of minimum order checkbox
case 'checkbox'
    filt = filtdes('filt');
    
    newSetOrderFlag = ~get(minOrdCheckbox,'value');
    
    type = bandpop.value;
    if type < 3  % low or high pass
        f = [0 f1.value f2.value Fs/2]*2/Fs;
    else
        f = [0 f1.value f2.value f3.value f4.value Fs/2]*2/Fs;
    end
    wp = wt1m.value;
    ws = wt2m.value;
    switch type
    case 1
        wt = [wp ws];
    case 2
        wt = [ws wp];
    case 3
        wt = [ws wp ws];
    case 4
        wt = [wp ws wp];
    end
    if ~newSetOrderFlag   % set Rp and Rs
        Rp.value = Rpm.value;
        Rs.value = Rsm.value;
    end
    fdremez('newfilt',newSetOrderFlag,...
                 type,f,Rp.value,...
                 Rs.value,wt,order.value)
    fdremez('dirty')


%---------------------------------------------------------------------
% fdremez('newfilt',setOrderFlag,type,f,Rp,Rs,wt,order)
%  set values of specs objects  DOES NOT DESIGN FILTER
case 'newfilt'
    setOrderFlag = varargin{2};
    type = varargin{3};
    f = varargin{4};
    Rpass = varargin{5};
    Rstop = varargin{6};
    wt = varargin{7};
    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
        set(order0,'visible','off')
        order = order1;
        Rp = pbspecs(3);
        Rs = sbspecs(3);
        set(Rp,'value',Rpass,'label','Rp','callback','fdremez(''Rpchange'')')
        set(Rs,'value',Rstop,'label','Rs','callback','fdremez(''Rschange'')')
        L1.color = co(min(2,size(co,1)),:);
        L2.color = co(min(2,size(co,1)),:);
    else
        set(order0,'visible','on')
        order = order0;
        order.value = N;
        wt1 = pbspecs(3);
        wt2 = sbspecs(3);
        set(wt1,'value',wt(1+(type == 2 | type == 3)),...
           'label','Weight','callback','fdremez(''dirty'')')
        set(wt2,'value',wt(2-(type == 2 | type == 3)),...
           'label','Weight','callback','fdremez(''dirty'')')
        L1.color = co(min(2,size(co,1)),:);
        L2.color = co(min(2,size(co,1)),:);
    end

    switch type
    case 1 % lowpass
        f1 = pbspecs(1);
        f2 = sbspecs(1);
        pbspecs(2).visible = 'off';
        sbspecs(2).visible = 'off';
        set(f1,'value',f(2)*Fs/2,'label','Fp')
        set(f2,'value',f(3)*Fs/2,'label','Fs')
    case 2 % highpass
        f1 = sbspecs(1);
        f2 = pbspecs(1);
        pbspecs(2).visible = 'off';
        sbspecs(2).visible = 'off';
        set(f1,'value',f(2)*Fs/2,'label','Fs')
        set(f2,'value',f(3)*Fs/2,'label','Fp')
    case 3 % bandpass
        f2 = pbspecs(1);
        f3 = pbspecs(2);
        f1 = sbspecs(1);
        f4 = sbspecs(2);
        pbspecs(2).visible = 'on';
        sbspecs(2).visible = 'on';
        set(f1,'value',f(2)*Fs/2,'label','Fs1')
        set(f2,'value',f(3)*Fs/2,'label','Fp1')
        set(f3,'value',f(4)*Fs/2,'label','Fp2')
        set(f4,'value',f(5)*Fs/2,'label','Fs2')
    case 4
        f1 = pbspecs(1);
        f4 = pbspecs(2);
        f2 = sbspecs(1);
        f3 = sbspecs(2);
        pbspecs(2).visible = 'on';
        sbspecs(2).visible = 'on';
        set(f1,'value',f(2)*Fs/2,'label','Fp1')
        set(f2,'value',f(3)*Fs/2,'label','Fs1')
        set(f3,'value',f(4)*Fs/2,'label','Fs2')
        set(f4,'value',f(5)*Fs/2,'label','Fp2')
    end
    ax.xlimPassband = fdutil('xlimpassband',type,...
                         Fs,f1.value,f2.value,f3.value,f4.value);

    if ax.xlimbound(2) ~= Fs/2
        set(ax,'xlimbound',[0 Fs/2],'xlim',[0 Fs/2])
    end
    
    f = f(:)';
    if ~setOrderFlag
        yd = passbandlimits(Rpass);
        minpass = yd(1);
        maxpass = yd(2);
        minstop = -Rstop;
    else
        minpass = L1.ydata(end);
        maxpass = L1.ydata(1);
        minstop = L2.ydata(1);
    end
    fdutil('setLines','fdremez',L1,L2,0,type,f,Fs,minpass,maxpass,minstop,1)

%---------------------------------------------------------------------
% fdremez('newtype')
%  Button down fcn band configuration popup
case 'newtype'
    filt = filtdes('filt');
    newtype = bandpop.value;
    oldtype = passframe.userdata;
    if isempty(oldtype)
        oldtype = filt.specs.fdremez.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 ~filt.specs.fdremez.setOrderFlag
            wp = get(wt1m,'value');
            ws = get(wt2m,'value');
        else
            wp = get(wt1,'value');
            ws = get(wt2,'value');
        end
        switch newtype
        case 1
            wt = [wp ws];
        case 2
            wt = [ws wp];
        case 3
            wt = [ws wp ws];
        case 4
            wt = [wp ws wp];
        end
        fdremez('newfilt',~minOrdCheckbox.value,...
                     newtype,f,Rp.value,...
                     Rs.value,wt,...
                     order.value)
        fdremez('dirty')
    else
       % disp('no change of type')
    end
    
%---------------------------------------------------------------------
% fdremez('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])
           
%---------------------------------------------------------------------
% fdremez('L1down')
%  Button down fcn of L1
case 'L1down'
    L1.erasemode = 'xor';
    L2.erasemode = 'xor';
    
%---------------------------------------------------------------------
% fdremez('L2down')
%  Button down fcn of L2
case 'L2down'
    L1.erasemode = 'xor';
    L2.erasemode = 'xor';
    
%---------------------------------------------------------------------
% fdremez('L1up')
%  Button up fcn of L1
case 'L1up'
    L1.erasemode = 'normal';
    L2.erasemode = 'normal';
    Lresp.erasemode = 'normal';
    
%---------------------------------------------------------------------
% fdremez('L2up')
%  Button up fcn of L2
case 'L2up'
    L1.erasemode = 'normal';
    L2.erasemode = 'normal';
    Lresp.erasemode = 'normal';

%---------------------------------------------------------------------
% fdremez('L1drag',type,ind)
%  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'

⌨️ 快捷键说明

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