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

📄 qsynth.m

📁 PLLmatlab for simulink
💻 M
📖 第 1 页 / 共 2 页
字号:
function [Out1,Out2]=qsynth(Action,In1,In2)
% Dick Benson 
% design singly terminated elliptic passive LC low pass filters
% [L,C] = qsynth('getLC');

    if nargin ==0
       Action = 'init';
    end;   

    if ~strcmp(Action,'init')
      Hqsynth_ = get(gcf,'userdata');
    end

    % handle index definitions
    i_f1      = 1;
    i_topology   = 2;
    i_order   = 3;
    i_synthpb = 4;
    i_ripl    = 5;
    i_ripv    = 6;
    i_stopl   = 7;
    i_stopv   = 8;
    i_ax1     = 9;
    i_pl1     = 10;
    i_pl2     = 11;
    i_fcl     = 12;
    i_fcv     = 13;
    i_lv      = 14;
    i_cv      = 15;
    i_lcl     = 16;
    i_testpb  = 17;
    


    if strcmp(Action,'init')
        color_h;   %  color definitions
        load my_color 
        qsynth_color=stored_vi_colors;
        
        Hqsynth_(i_f1)= figure('Color',[0 0 0] ,'Name','Qsynth: Singly Terminated Ladder Elliptic Filter',... 
                          'Position',[20 20 640 440],...
                          'Resize','off',...
                          'Color',qsynth_color(FIG_BKc,:),...
                          'NumberTitle','off','visible','on');
                          % ###### userdata contains vector of handles if desired
        
        Hqsynth_(i_topology)=uicontrol('Style','popup','visible','on',...
                                    'String','RIN=1,RL=inf|RIN=0,RL=1',...
                                    'Position',[10 400 105 20],...
                                    'BackgroundColor',qsynth_color(PUP_BKc,:),...
                                    'ForeGroundColor',qsynth_color(PUP_FRc,:),...
                                    'Value',1,...
                                    'callback','qsynth(''clear'')',...
                                    'HorizontalAlignment','Left');  
        
        Hqsynth_(i_order)=uicontrol('Style','popup','visible','on',...
                                'String','Order:3|Order:5|Order:7|Order:9|Order:11',...
                                'Position',[10 380 105 20],...
                                'BackgroundColor',qsynth_color(PUP_BKc,:),...
                                'ForeGroundColor',qsynth_color(PUP_FRc,:),...
                                'Value',4,...
                                'HorizontalAlignment','Left');  
        
        Hqsynth_(i_ripl) =  uicontrol('Style','text','visible','on',...
                                'String','Ripple (dB):',...
                                'Position',[10,355,60,18],...
                                'BackGroundColor',qsynth_color(LBL_BKc,:),...
                                'ForeGroundColor',qsynth_color(LBL_FRc,:),...
                                'HorizontalAlignment','left'); 
                               
         
         Hqsynth_(i_ripv) = uicontrol('Style','edit','visible','on',...
                                'Position',[70,355,45,18],...
                                'String','1',...
                                'BackgroundColor',qsynth_color(EDT_BKc,:),...
                                'ForeGroundColor',qsynth_color(EDT_FRc,:),...
                                'HorizontalAlignment','center',...
                                'Max',1);

        
         Hqsynth_(i_stopl) =  uicontrol('Style','text','visible','on',...
                                'String','Stop (dB):',...
                                'Position',[10,330,60,18],...
                                'BackGroundColor',qsynth_color(LBL_BKc,:),...
                                'ForeGroundColor',qsynth_color(LBL_FRc,:),...
                                'HorizontalAlignment','left'); 
                               
         
         Hqsynth_(i_stopv) = uicontrol('Style','edit','visible','on',...
                                'Position',[70,330,45,18],...
                                'String','60',...
                                'BackgroundColor',qsynth_color(EDT_BKc,:),...
                                'ForeGroundColor',qsynth_color(EDT_FRc,:),...
                                'HorizontalAlignment','center',...
                                'Max',1);
                                
         Hqsynth_(i_fcl) =  uicontrol('Style','text','visible','on',...
                                'String','Cutoff (Hz):',...
                                'Position',[10,305,60,18],...
                                'BackGroundColor',qsynth_color(LBL_BKc,:),...
                                'ForeGroundColor',qsynth_color(LBL_FRc,:),...
                                'HorizontalAlignment','left'); 
                               
         
         Hqsynth_(i_fcv) = uicontrol('Style','edit','visible','on',...
                                'Position',[70,305,45,18],...
                                'String','1.0e6',...
                                'BackgroundColor',qsynth_color(EDT_BKc,:),...
                                'ForeGroundColor',qsynth_color(EDT_FRc,:),...
                                'HorizontalAlignment','center',...
                                'Max',1);
                                
          Hqsynth_(i_lcl) =  uicontrol('Style','text','visible','on',...
                                'String','              L                         C',...
                                'Position',[10,280,165,18],...
                                'BackGroundColor',qsynth_color(LBL_BKc,:),...
                                'ForeGroundColor',qsynth_color(LBL_FRc,:),...
                                'HorizontalAlignment','left');                                 
      
        Hqsynth_(i_lv)  =  uicontrol('Style','edit','visible','on',...
                                'Position',[10,35,85,240],...   % was 80
                                'String','',...
                                'BackgroundColor',qsynth_color(EDT_BKc,:),...
                                'ForeGroundColor',qsynth_color(EDT_FRc,:),...
                                'HorizontalAlignment','left',...
                                'Max',14); 
                                
        Hqsynth_(i_cv)  =  uicontrol('Style','edit','visible','on',...
                                'Position',[100,35,85,240],...  % was 95,35,80
                                'String','',...
                                'BackgroundColor',qsynth_color(EDT_BKc,:),...
                                'ForeGroundColor',qsynth_color(EDT_FRc,:),...
                                'HorizontalAlignment','left',...
                                'Max',14);                        
                                
                                
        Hqsynth_(i_ax1)=axes('Units','pixels','Position',[240,80,370,300],... 
                                'Box','on',...
                                'visible','on',...
                                'NextPlot','add',...
                                'DrawMode','fast',...           
                                'Color',qsynth_color(PLT_BKc,:),...
                                'TickDir','out',...
                                'YlimMode','auto',...
                                'XlimMode','auto',...
                                'Xcolor',qsynth_color(XY_AXc,:),...    
                                'Ycolor',qsynth_color(XY_AXc,:),...
                                'FontSize',12);
                                
        title('Singly Terminated Elliptic Filter ','color',qsynth_color(XY_AXc,:),'fontsize',9);
        xlabel('Frequency in Hz','fontsize',9);
        ylabel('Magnitude in dB','fontsize',9)
        
        Hqsynth_(i_pl1) = plot(Hqsynth_(i_ax1),0,0,'clipping','on',...
                                  'Color',qsynth_color(TRA_1c,:),...
                                  'erasemode','xor','visible','on');
        
        Hqsynth_(i_pl2) = plot(Hqsynth_(i_ax1),0,0,'clipping','on',...
                                  'Color',qsynth_color(TRA_2c,:),...
                                  'erasemode','xor','visible','on');
        
        Hqsynth_(i_synthpb) = uicontrol('Style','Pushbutton',...
                              'Position',[10,10,105,20],...
                              'String','Synthesize',...
                              'Callback','qsynth(''synth'');');

        Hqsynth_(i_testpb) = uicontrol('Style','Pushbutton',...
                              'Position',[120,10,105,20],...
                              'String','Test',...
                              'Callback','qsynth(''test'');');

    
        set(Hqsynth_(i_f1),'userdata',Hqsynth_);
        zoom on
    
    elseif strcmp(Action,'synth')
       fmtstr = '%8.5g';
    
       n  = get(Hqsynth_(i_order),'value')*2+1;          % only odd orders supported 
       rp = str2num(get(Hqsynth_(i_ripv),'string'));
       rs = str2num(get(Hqsynth_(i_stopv),'string'));
       wn = 2*pi*str2num(get(Hqsynth_(i_fcv),'string'));
       
       [b,a]=ellip(n,rp,rs,wn,'s');
       save lpf_coefs b a
       w = 0:(wn/25):10*wn;
       h = freqs(b,a,w);
    
       
       set(Hqsynth_(i_ax1),'Ylim',[-rs-20,5],'Xlim',[0,10*wn/(2*pi)]);
       set(Hqsynth_(i_pl1),'xdata',w/(2*pi),'ydata',20*log10(h));
       
       topology = get(Hqsynth_(i_topology),'value');
       if topology ==1
          %  Rin = 1, Rl = inf , Vsource with 1 ohm Z0, no load 
          % must be odd order
          m     = b(2:length(b));
          zeros = roots(m);
          m2 = [];
          n2 = [];
          for i=1:length(a)  
              if rem(i,2)
                 n2=[n2,a(i),0];
              else
                 m2=[m2,a(i),0];
              end;
          end;
          m2=m2(1:(length(m2)-1));
          
          % remove admittance pole @ s=inf
          % z=m2/n2  y = n2/m2 yp = n2/m2-c1s
          
          C(1) = n2(1)/m2(1);  % shunt capacitor
          n2 = n2 - conv(m2,[C(1),0]);
          % now it gets tricky ....
          for i = 1:(n-1)/2
              % need an xmission zero @ w=wx
              wx = j*abs(zeros(2*i)); % pick an xmission zero....
              % do a partial removal of the impedance pole @ inf
              % first evaluate impedance @ w=wx
              zmag = polyval(m2,wx)/polyval(n2,wx);
              L(2*i) = zmag/wx;
              
              if i==1
                 n2=n2(3:length(n2));
              end;
              % this partially removes the pole
              m2 = m2-conv(n2,[L(2*i),0]);
              
              % now remaining admittance has a pole at w=wx
              % remove it by shunting a series LC
              
              % first must determine L & C values
              [q,r1]= deconv(m2,[1 0 abs(wx)^2]);  % r should be zero
              k    = n2(1);
              n2p  = n2/k;
              n2p  = n2p(1:length(n2p)-1);
              L(2*i+1)=1/(k*(polyval(n2p,wx)/polyval(q,wx)));
              C(2*i+1)= 1/(L(2*i+1)*(abs(wx)^2));

              % then remove the addmittance.... not obvious! 
              [n2pp,r2] = deconv(( n2p-q/(k*L(2*i+1)) )*k,[1 0 1/(C(2*i+1)*L(2*i+1))]);
              n2 = conv(n2pp,[1 0]);
              m2 = q;
          end;
          L=L';
          C=C';

⌨️ 快捷键说明

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