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

📄 yjxt.m

📁 信号实验常用的simulink模型和mfile,可直接在matlan下运行。
💻 M
📖 第 1 页 / 共 2 页
字号:
function yjxt(action,in1,in2);
%yjxt 系统特性演示 - 1 : 一阶系统
%	Illustrating some basic signal processing concepts, such as 
%	sampling, aliasing, and windowing.

%	possible actions:
%	  'start'
%	  'down'
%	  'move'
%	  'up'
%	  'redraw'
%	  'done'
%	  'setR'
%	  'setwindow'
%	  'showwin'

if nargin<1,
    action='start';
end;

global yjxt_DAT
global ADDIT_DAT	% this is for WINDOW pop-up button
global fun_str

if strcmp(action,'start'),

    %====================================
    % Graphics initialization
    oldFigNumber = watchon;
    figNumber = figure;
    set(gcf, ...
        'NumberTitle','off', ...
        'Name','一阶系统特性', ...
        'backingstore','off',...
        'Units','normalized');

    %====================================
    % Information for all buttons
    labelColor=192/255*[1 1 1];
    top=0.95;
    bottom=0.05;
    left=0.75;
    yInitLabelPos=0.90;
    left = 0.78;
    labelWid=0.18;
    labelHt=0.05;
    btnWid = 0.18;
    btnHt=0.07;
    % Spacing between the label and the button for the same command
    btnOffset=0.003;
    % Spacing between the button and the next command's label
    spacing=0.05;
 
    %====================================
    % The CONSOLE frame
    frmBorder=0.02;
    yPos=0.05-frmBorder;
    frmPos=[left-frmBorder yPos btnWid+2*frmBorder 0.9+2*frmBorder];
    h=uicontrol( ...
        'Style','frame', ...
        'Units','normalized', ...
        'Position',frmPos, ...
        'BackgroundColor',[0.5 0.5 0.5]);
    
    %====================================
    % The SIGNAL command popup button

    btnNumber=1;
    yLabelPos=top-(btnNumber-1)*(btnHt+labelHt+spacing);
    labelStr='一阶系统 ';

    % Generic label information
    labelPos=[left yLabelPos-labelHt labelWid labelHt];
    uicontrol( ...
        'Style','text', ...
        'Units','normalized', ...
        'Position',labelPos, ...
        'BackgroundColor',labelColor, ...
        'HorizontalAlignment','left', ...
        'String',labelStr);

    btnPos=[left yLabelPos-labelHt-btnHt-btnOffset btnWid btnHt];
    popup=uicontrol('Style','Popup','String','一阶低通|一阶高通|',...
        'Position', btnPos, ...
        'BackgroundColor','w', ...
        'ForegroundColor','k', ...
        'Units','normalized',...
        'CallBack',[...
		'global yjxt_DAT;',...
		'popup=yjxt_DAT(11);',...
		'val = get(popup,''Value'');',...
		'if val<=3',...
		'	yjxt(''redraw'');',...
		'else',...
		'	getstr;',...
		'end']);

    %====================================
    % The WINDOW command popup button
   
    winHndl=0;
    % Generic label information
    

    % Generic popup button information
  
  %====================================
    % The FUNDAMENTAL editable text box
    btnNumber=2;
    yLabelPos=top-(btnNumber-1)*(btnHt+labelHt+spacing);
    labelPos=[left yLabelPos-labelHt-0.15 labelWid+0.02 labelHt];
    freq_text = uicontrol( ...
        'Style','text', ...
        'Position', labelPos, ...
        'Units','normalized', ...
        'BackgroundColor',[0.5 0.5 0.5], ...
        'ForegroundColor','w', ...
        'HorizontalAlignment','left', ...
        'String','时间常数(t):');

    btnPos=[left+0.02  yLabelPos-labelHt-btnHt-btnOffset-0.15 ...
            0.5*btnWid+frmBorder  btnHt];
    R_field = uicontrol( ...
        'Style','edit', ...
        'BackgroundColor','w', ...
        'ForegroundColor','k', ...
        'Position', btnPos, ...
        'Units','normalized', ...
        'HorizontalAlignment','left', ...
        'String','10',...
        'CallBack','yjxt(''settime''); yjxt(''redraw'')');

   %====================================
    % The Show Window CheckBox
    
    
   %====================================
    % The INFO button
    uicontrol( ...
        'Style','push', ...
        'Units','normalized', ...
        'Position',[left bottom+(2*labelHt)+spacing btnWid 2*labelHt], ...
        'String','信息', ...
        'Callback','yjxt(''info'')');

   %========================================
   % The CLOSE button
    done_button=uicontrol('Style','Pushbutton', ...
        'Position',[left bottom btnWid 2*labelHt], ...
        'Units','normalized','Callback',...
        'yjxt(''done'')','String','关闭');
   %====================================

    % Create intial signal
    N=512;     % number of samples
%    N=21;
    C=1;
R=10;    % hertz
t=R*C;
    %t0=-10;      % seconds
    %t1=10;      % seconds
    t1=logspace(-3,5);
    %T=(t1-t0)/N;
    %ws=2*pi./T;            % sampling rate in seconds
    M=512;     % length of fft
    %window=ones(N,1);    % use window to lower side-lobes in the freq. domain
                             % (makes peaks wider)

    %C_field=0; % freq. domain lower axis limit
    %w=ws*(1:N/2)/N;
    %w2=ws*(-(0:N/2-1))/N;
    % create axes for time domain and frequency domain plot
     ax_pha=axes('Position',[.12 .14 .6 .3],'XLim',...
             [1e-3,1e5],'YLim',[-4 4]);

    % time domain
    val = get(popup,'Value');
    %if(freq<0.05)freq=0.05;end
     %if(freq>0.95)freq=0.95;end
      %if(amp>1.0)amp=1.0;end
    if (val == 1),
       num=[0 1];den=[t 1];
[m,p]=bode(num,den,w);
subplot(211),semilogx(w,20*log10(m));
subplot(212),semilogx(w,p); 
     
    elseif (val == 2),   % square wave
 num=[t 0];den=[t 1];
[m,p]=bode(num,den,w);
subplot(211),semilogx(w,20*log10(m));
subplot(212),semilogx(w,p); 
           
   end;
pha_line= semilogx(w,p, '-','markersize',8,'EraseMode','xor');
      axis([1e-3 1e5 -4 4]);

    grid;
    ylabel('相频特性');
    xlabel('频率 (Hz)');

    ax_amp=axes('Position',[.12 .58 .6 .3],'XLim',[1e-3 1e5],'YLim',[-80 0]);
    amp_line= semilogx(w,20*log10(m),'-','markersize',8,'EraseMode','xor');
      axis([1e-3 1e5 -80 0]);
    % (set to xor mode to prevent re-rendering, that is, for speed)
    grid;
    ylabel('幅频特性');
    xlabel('频率 (Hz)');
    text(-7.55, 1.25,'点击并拖放信号波形以改变其基频与振幅。');

    set(amp_line,'ButtonDownFcn','yjxt(''down'')');

    yjxt_DAT = [R; C; N; M; C_field; 0; 0; ...
		amp_line; pha_line; R_field; popup; -1; gcf; ...
		t(:); window(:); 0];
    ADDIT_DAT = winHndl;

    watchoff(oldFigNumber);

elseif strcmp(action,'down'),

  popup=yjxt_DAT(11);
  val = get(popup,'value');
  if val<=3
    % assumes that a line was clicked
    amp_line=yjxt_DAT(8);
    axes(get(amp_line,'parent'));	% set the right axes

    % Obtain coordinates of mouse click location in axes units
    pt=get(gca,'currentpoint');
    x=pt(1,1);
    y=pt(1,2);


% find closest vertex of line to mouse click location (call it fixed_x, fixed_y)

    line_x=get(amp_line,'XData');
    line_y=get(amp_line,'YData');
    units_str = get(gca,'units');  % save normalized state
    set(gca,'units','pixels');     % distance must be in pixels
    p=get(gca,'pos');
    xa=get(gca,'xlim');
    ya=get(gca,'ylim');
    
    dist=((line_x-x)*p(3)/(xa(2)-xa(1))).^2 + ...
         ((line_y-y)*p(4)/(ya(2)-ya(1))).^2;
    [temp,i]=min(dist);
    fixed_x=line_x(i);
    fixed_y=line_y(i);
    set(amp_line,'LineStyle',':');

    yjxt_DAT(6)=fixed_x;
    yjxt_DAT(7)=fixed_y;

    set(gca,'units',units_str );
    set(gcf,'WindowButtonMotionFcn', 'yjxt(''move'')');
    set(gcf,'WindowButtonUpFcn', 'yjxt(''up'')');
  %  set(gcf,'userdata',u);
end

elseif strcmp(action,'move'),
    % u = get(gcf,'userdata');
    freq=yjxt_DAT(1);
    amp=yjxt_DAT(2);
    N=yjxt_DAT(3);
    M=yjxt_DAT(4);
    C_field=yjxt_DAT(5);
    fixed_x=yjxt_DAT(6);
    fixed_y=yjxt_DAT(7);
    amp_line=yjxt_DAT(8);
    pha_line=yjxt_DAT(9);
    R_field=yjxt_DAT(10);
    popup=yjxt_DAT(11);
    t=yjxt_DAT(14:14+N-1);
    window=yjxt_DAT(14+N:14+N+N-1);

    pt=get(gca,'currentpoint');
    x=pt(1,1);
    y=pt(1,2);

    amp1=y/fixed_y*amp;
    if (abs(amp1)>1.0),
       amp1=1.0*sign(amp1);
    end;
    if (abs(amp1)<0.05),
       amp1=0.05*sign(amp1);
    end;
    if (amp1 == 0),
        amp1=0.05;
    end;
    freq1=fixed_x/x*freq;

    val = get(popup,'Value');
     %if(freq1<0.05)freq1=0.05;end
      %if(freq>0.95)freq1=0.95;end
     % if(amp1>1.0)amp1=1.0;end
    if (val == 1),
           %if t==0 f=1;
           %else 
          f=amp1*sin(freq1*t)./(t*pi);
         %  end;
    elseif (val == 2),   % square wave
            for i=1:N
            if abs(i-N/2)<=N/(6*freq1)
              f(i)=amp1;
           else
              f(i)=0;

⌨️ 快捷键说明

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