📄 ctoplt.m
字号:
function ctoplt(plot_type)
%CTOPLT Support file for CTSIGGUI
% 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');
ele_mat = get(ui(1),'userdata');
stat_bar = ui(61);
data = get(ui(8),'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
%%%%
% get appropriate line handles
axs_han = get(ui(7),'userdata');
opr_han = get(axs_han,'userdata');
n = data(1,:);
xn = data(2,:);
dn = n(2)-n(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(46),'string','1');
set(ui(48),'string','0');
set(ui(44),'string','1');
new_n=n;
new_xn = xn;
set(opr_tit,'string','Signal Operation: y(t) = x(t)');
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 ~length(fold),
errordlg('Must input a VALID value.','Input Error');
return;
elseif fold == 0
errordlg('Time scale must be non-zero.','Input Error');
return;
end
opr_title = 'x(';
new_n = n;
temp_n = fold*n + delay;
new_xn = ctsiggen(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,'t'];
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(t) = ',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;
%if causal
i=find(abs(xn)>100*eps);
if ~isempty(i)
ind=i(1);i1=i(1);i2=i(length(i));
if n(i1)<=0 | n(i2)>=0
i=find(abs(new_n)<100*eps);
if ~isempty(i)
% new_xn(i)=0.5*new_xn(i);
% new_xn(i)=0.5*(new_xn(i-1)+new_xn(i+1));
if abs(0.5*xn(ind))>abs(0.5*(new_xn(i-1)+new_xn(i+1)))
new_xn(i)=0.5*xn(ind);
else
new_xn(i)=0.5*(new_xn(i-1)+new_xn(i+1));
end
end
end
end
%NEW LOOP
imid=(lnew+1)/2;
if abs(new_xn(imid-1))<100*eps & abs(new_xn(imid+1))<100*eps;
new_xn(imid)=0;
end
set(opr_tit,'string','y(t) = even part of x(t) = 0.5*[x(t) + x(-t)]');
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(t) = odd part of x(t) = 0.5*[x(t) - x(-t)]');
elseif plot_type == 4, % cummulative sum
new_xn = cumsum(xn)*dn;
new_n = n;
set(opr_tit,'string','y(t) = Running Integral of x(t)');
elseif plot_type == 5 % derivative
new_xn=diff(xn)/dn;
new_xn(len) = new_xn(len-1);
new_n = n;
set(opr_tit,'string','y(t) = Derivative of x(t)');
end
set(opr_han,'xdata',new_n,'ydata',new_xn);
% ylim
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=new_n(1);xlmax=new_n(length(new_n));
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);
set(ui(65),'userdata',[new_n;new_xn]);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -