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

📄 dtoplt.m

📁 ADSP TOOLBOX: Version 2.0 and gui m-files
💻 M
字号:
function dtoplt(plot_type)
%DTOPLT Support file for DTSIGGUI


% ADSP Toolbox: Version 2.0 
% For use with "Analog and Digital Signal Processing", 2nd Ed.
% Published by PWS Publishing Co.
%
% Ashok Ambardar, EE Dept. MTU, Houghton, MI 49931, USA
% http://www.ee.mtu/faculty/akambard.html
% e-mail: akambard@mtu.edu
% Copyright (c) 1998


f = gcf;
ui = get(f,'userdata');

%%%%%%%%%%%%
if get(ui(15),'userdata')==1
set(f,'currentaxes',ui(29));
zoom out,zoom reset
set(f,'currentaxes',ui(32));
zoom out,zoom reset
end
%%%%%%%%%%%


ele_mat = get(ui(1),'userdata');
stat_bar = ui(61);
data = get(ui(8),'userdata');

% get appropriate line handles
axs_han = get(ui(7),'userdata');
opr_han = get(axs_han,'userdata');

n = data(1,:);
xn = data(2,:);
dn = 1;
len=length(n);

% compute different measures of x[n]
summ = sum(xn)*dn;
abs_summ = sum(abs(xn))*dn;
ener = sum(xn.*xn)*dn;

set(ui(54),'string',num2str(summ,3));
set(ui(56),'string',num2str(abs_summ,3));
set(ui(60),'string',num2str(ener,3));

[r,c] = size(ele_mat);
i = sqrt(-1);

plot_type = get(ui(50),'value');

if plot_type > 1,
      set(ui([41:48,52]),'vis','off');
else
      set(ui([41:48,52]),'vis','on');
end


opr_tit = get(axs_han,'title');
set(opr_tit,'fontsize',10);


if plot_type == 1,
  if get(ui(52),'value')
  set(ui(42),'string','0');
  set(ui(44),'string','1');
  set(ui(46),'string','1');
  set(ui(48),'string','0');
   new_n=n;
   new_xn = xn;
   set(opr_tit,'string','Signal Operation: y[n] = x[n]');

  else
      delay = str2num(get(ui(42),'string'));
      if ~length(delay),
         errordlg('Must input a VALID delay value.','Input Error');
         return;
      end
      scale = str2num(get(ui(46),'string'));
      if ~length(scale),
         errordlg('Must input a VALID scale value.','Input Error');
         return;
      end
      shift = str2num(get(ui(48),'string'));
      if ~length(shift),
         errordlg('Must input a VALID shift value.','Input Error');
         return;
      end

   fold_str  = get(ui(44),'string');
   fold  = str2num(fold_str);
      if fold ~=1 & fold ~=-1,
         errordlg('C can only be -1 or +1.','Input Error');
         return;
      end

   opr_title = 'x[';
   new_n = n;

   temp_n = fold*n + delay;
   new_xn = dtsiggen(temp_n,[fold,delay]);

if fold == -1
      opr_title = [opr_title,'-'];
elseif fold ~= 1
      opr_title = [opr_title,fold_str];
end
      opr_title = [opr_title,'n'];

   if delay > 0,
      opr_title = [opr_title,' + ',num2str(delay),']'];
   elseif delay == 0,
      opr_title = [opr_title,']'];
   else
      opr_title = [opr_title,' - ',num2str(abs(delay)),']'];
   end

% then shifting and scaling
   new_xn=shift + scale*new_xn;

   if scale >= 0 & scale ~= 1,
      opr_title = [num2str(scale),'*',opr_title];
   elseif scale < 0,
      opr_title = ['(',num2str(scale),')*',opr_title];
   end

   if shift ~= 0,
      opr_title = [num2str(shift),' + ',opr_title];
   end

% set operations axis title
   set(opr_tit,'string',['Signal Operation: y[n] = ',opr_title]);
  end

elseif plot_type == 2, % even
   new_n=n;
   new_xn = xn;

   if abs(n(1))~=abs(n(len)) 
   nmax=max(abs(n));
   new_n=-nmax:dn:nmax;
   lnew=length(new_n);
   z=zeros(1,lnew-len);
   if nmax > n(len), new_xn=[xn z];
   elseif -nmax < n(1), new_xn=[z xn]; 
   end
   end
   new_xn = (new_xn+fliplr(new_xn))/2;

   set(opr_tit,'string','y[n] = even part of x[n] = 0.5*{x[n] + x[-n]}');

elseif plot_type == 3, % odd
   new_n=n;
   new_xn = xn;
   if abs(n(1))~=abs(n(len)) 
   nmax=max(abs(n));
   new_n=-nmax:dn:nmax;
   lnew=length(new_n);
   z=zeros(1,lnew-len);
   if nmax > n(len), new_xn=[xn z];
   elseif -nmax < n(1), new_xn=[z xn]; 
   end
   end
   new_xn = (new_xn-fliplr(new_xn))/2;
   new_xn = new_xn.*(abs(new_xn)>100*eps);

   set(opr_tit,'string','y[n] = odd part of x[n] = 0.5*{x[n] - x[-n]}');


elseif plot_type == 4, % cummulative sum
   new_xn = cumsum(xn)*dn;
   new_n = n;

   set(opr_tit,'string','y[n] = running sum of x[n]');

elseif plot_type == 5 % derivative
new_xn=diff(xn)/dn;
%lxn=length(xn);
new_xn(len) = new_xn(len-1);
new_n = n;

   set(opr_tit,'string','y[n] = first difference of x[n]');

end

dtstem(opr_han,new_n,new_xn);
llim=min(new_xn);ulim=max(new_xn);
if llim>=0,llim=0;end
if ulim<=0,ulim=0;end
ulim=1.2*ulim;llim=1.2*llim;
if ulim==llim,ulim=ulim+0.5;llim=llim-0.5;end
xlmin=n(1);xlmax=n(len);
if any(plot_type==[2,3]),xlmin=-xlmax;end
xlim=[xlmin,xlmax];
set(ui(32),'xlim',xlim,'ylim',[llim,ulim]);
set(ui(29),'xlim',xlim);

%SAVE??
set(ui(65),'userdata',[new_n;new_xn]);

⌨️ 快捷键说明

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