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

📄 ctconplt.m

📁 trabajos en matlab para verificar son muy buenos
💻 M
字号:
function ctconplt(mode)
% CTCONPLT Plot control for CTCONGUI.


% 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');
   action_pop  = ui(13);
   n_edt      = ui(4);
   xn_edt     = ui(6);
   h_edt      = ui(10);
   hn_edt     = ui(12);
   sig_x = ui(24);
   sig_h=ui(25);
   fixed_line = ui(30);
   shift_line = ui(31);
   shift_mark = ui(32);
   conv_line = ui(33);
   conv_mark=ui(34);
   prod_line = ui(35);
   old1_axs = ui(26);
   old2_axs=ui(28);
   top_axs = ui(23);
   bot_axs     = ui(45);

if nargin == 0

txo=get(n_edt,'userdata');
xo=get(xn_edt,'userdata');
tyo=get(h_edt,'userdata');
yo=get(hn_edt,'userdata');
ts=eval(get(ui(38),'string'));

set(f,'windowbuttonmotionfcn','');

ty=get(action_pop,'value');
if ty==1 %edit
   set(top_axs,'pos',[-600 260 390 160]);
   set(bot_axs,'pos',[-600 40 390 160]);
   set(old1_axs,'pos',[210 260 390 160]);
   set(old2_axs,'pos',[210 40 390 160]);
return;
end
   set(top_axs,'pos',[210 260 390 160],'color','k');
   set(bot_axs,'pos',[210 40 390 160]);
   set(old1_axs,'pos',[-600 260 390 160]);
   set(old2_axs,'pos',[-600 40 390 160]);

%ver_str=version;
ver4=0;   %ver4=length(findstr('4.',ver_str));
if ty==2, %cxy
x=xo;y=yo;t1=txo;t2=tyo;meth='Convolution  x*h ';
if ver4,
xhtit= ' x(l) and h(t-l) ';
else
xhtit= ' x({\lambda}) and h({\itt}-{\lambda}) (folded)';
end
elseif ty==3, %cyx
x=yo;t1=tyo;y=xo;t2=txo;meth='Convolution  h*x ';
if ver4,
xhtit= ' x(t-l) and h(l) ';
else
xhtit= ' x({\itt}-{\lambda}) (folded) and h({\lambda}) ';
end
elseif ty==4, %rxy
x=xo;t1=txo;y=fliplr(yo);t2=-fliplr(tyo);meth='Correlation  x**h ';
if ver4,
xhtit= ' x(l) and h(l-t) ';
else
xhtit= ' x({\lambda}) and h({\lambda}-{\itt}) (shifted) ';
end
elseif ty==5, %ryx
x=yo;t1=tyo;y=fliplr(xo);t2=-fliplr(txo);meth='Correlation  h**x ';
if ver4,
xhtit= ' x(l) and h(l-t) ';
else
xhtit= ' x({\lambda}-{\itt}) (shifted) and h({\lambda}) ';
end
end

d1=max(t1)-min(t1);
d2=max(t2)-min(t2);
% ddif=abs(d2-d1);
 
 tst=min(t1)+min(t2);
 tend=max(t1)+max(t2);
 t3=min(t1)+(0:ts:tend-tst);
% mint=min(t1)-d2;
 t1=tst+(0:ts:d1);
 t3=(0:ts:d1+d2)+tst;  %%%NEW
% z=ts*conv(x,y);
 z=convnum(x,y,ts,'t');
 yf=fliplr(y);
set(ui(7),'userdata',t3);
set(ui(8),'userdata',z);

%For products
 ze=0*t3;
 tp=ze;
 lx=length(x);
 ly=length(y);
% lmax=max(lx,ly);
% lmin=min(lx,ly);
 tp(1,1:lx)=t1;
%tp=t1(1)+(0:length(tp)-1)*ts;
 xp=ze;
 yp=ze;
 xp(1,1:lx)=x;
 yp(1,1:ly)=y;


%For plotting product function
limits=[max(x);max(y);min(x);min(y);max(x)*max(y);min(x)*min(y);min(z);max(z)];
limits=[limits;max(x)*min(y);min(x)*max(y)];%%NEW
 prmax=max(limits);
 prmin=min(limits);
 if prmin>0,
  prmin=0;
 end

 l=length(t3);
 t1p=[t1(1) t1 t1(lx)];
 x1p=[0 x 0];
 t2f=(0:ts:d2)-d2+tst;
 mm=50;
 tj=max([1 fix(l/mm)]);

% setup matrix to store information necessary for the mouse motion option
 info_mat = zeros(6,l);
 info_mat(1,:) = t3;
 info_mat(2,:) = z;
 info_mat(3,:) = xp;
 info_mat(4,:) = yp;
 info_mat(5,:) = tp;
 info_mat(6,:) = [lx ly zeros(1,l-2)];


%top figure (for signals)
%set(f,'currentaxes',ui(23));
set(ui(23),'xlim',[tst-d2 tend],'ylim',[prmin-(0.1*abs(prmin))...
 prmax+(0.1*abs(prmax))]);
top_tit=get(ui(23),'title');
set(top_tit,'string',['Signals ' xhtit ' ready for operation']);
set(ui(24),'xdata',t1p,'ydata',x1p)
%set(ui(25),'xdata',[t2(1) t2 t2(ly)],'ydata',[0 y 0]);
%set(ui(24),'xdata',[txo(1) txo txo(length(txo))],'ydata',[0 xo 0])
%set(ui(25),'xdata',[tyo(1) tyo tyo(length(tyo))],'ydata',[0 yo 0]);
set(ui(25),'xdata',[t2f(1),t2f,t2f(length(t2f))],'ydata',[0,yf,0])


%Bottom figure (conv)
%set(f,'currentaxes',ui(45));
set(bot_axs,'xlim',[tst-d2 tend],'ylim',[prmin-(0.1*abs(prmin))...
 prmax+(0.1*abs(prmax))]);

tit_str=['Product (shaded).    ' meth ' starts at   t = ' num2str(tst)];
bot_tit=get(ui(45),'title');
set(bot_tit,'string',tit_str);

 xlabel('Time  t');

set(fixed_line,'xdata',t1p,'ydata',x1p)

% annotate graph

set(shift_line,'xdata',[t2f(1),t2f,t2f(length(t2f))],'ydata',[0,yf,0],...
      'buttondownfcn','ctconplt(1);');
set(conv_mark,'xdata',t3(1),'ydata',z(1));

%grid on;hold on;

% store handles and data necessary for mouse motion option
 set(shift_line,'userdata',info_mat);
 set(shift_mark,'userdata',t2f);
 set(conv_line,'userdata',ts);
 set(conv_mark,'userdata',lx);
 set(prod_line,'userdata',[]);
 set(fixed_line,'userdata',[t1;x]);
% set(f,'windowbuttonmotionfcn','ctcongui(5)');

%%% NEW FOR DRAG/CLICK 
 set(gcf,'windowbuttonupfcn','set(gcf,''windowbuttonmotionfcn'','''')');
 

%Start of movie
for j=[1:tj:l l],
  ta=t2f+(j-1)*ts;
  la=length(ta);
  tb=t3(j);
  zb=z(j);
  
% Compute product line
  xp1=xp(1:j);
  yp1=fliplr(yp(1:j));
  pr=xp1.*yp1;
%  tpr=tp(1:j);
  ind1=max(1, j-ly+1);
  ind2=min(j,lx);
  tpr=tp(ind1:ind2);
  pr=pr(ind1:ind2);
  lp=length(tpr);if lp==1,pr=0;end

% update shifted, conv and product lines
  set(shift_line,'xdata',[ta(1),ta,ta(la)]);
  set(shift_mark,'xdata',tb);
  set(conv_line,'xdata',t3(1:j),'ydata',z(1:j));
  set(conv_mark,'xdata',tb,'ydata',zb);
  set(prod_line,'xdata',[tpr(1) tpr tpr(lp)],'ydata',[0 pr 0]);

  drawnow;
end


elseif mode==1, % initial grab
ui=get(f,'userdata');
xdata=get(ui(31),'xdata');
info_mat = get(ui(31),'userdata');
t3 = info_mat(1,:);
%t3_loc = find(t3==xdata(length(xdata)));
t3_loc = find(abs(t3-xdata(length(xdata)))<1e-10);
init_pt = get(gca,'currentpoint');
set(ui(35),'userdata',[init_pt;t3_loc,0,0]);
 set(f,'windowbuttonmotionfcn','ctconplt(2);');
 
elseif mode==2, % mouse motion function
% obtain handles from current figure's userdata
 ui = get(f,'userdata');
 shift_line = ui(31);
 shift_mark = ui(32);
 conv_line = ui(33);
 conv_mark = ui(34);
 prod_line = ui(35);
fixed_line=ui(30);
% obtain convolution data
 info_mat = get(shift_line,'userdata');
 t2f = get(shift_mark,'userdata');
 ts = get(conv_line,'userdata');
 lmax = get(conv_mark,'userdata');
 init_pt = get(prod_line,'userdata');
x_d=get(fixed_line,'userdata');

 t3_loc = init_pt(3,1);
 t3 = info_mat(1,:);
 z = info_mat(2,:);
 xp = info_mat(3,:);
 yp = info_mat(4,:);
 tp = info_mat(5,:);
 lx=info_mat(6,1);
 ly=info_mat(6,2);
 
 cur_pt = get(gca,'currentpoint');
 delta_x = cur_pt(1,1) - init_pt(1,1);
 j = find(t3>=(t3(t3_loc)+delta_x));
 if length(j),
  j = j(1);
 else
  j = length(t3);
 end
 
 ta=t2f+(j-1)*ts;
 la=length(ta);
 tb=t3(j);
 zb=z(j);
 
% Compute product line
 xp1=xp(1:j);
 yp1=fliplr(yp(1:j));
 pr=xp1.*yp1;
 ind1=max(1, j-ly+1);
 ind2=min(j,lx);
 tpr=tp(ind1:ind2);
 pr=pr(ind1:ind2);
 lp=length(tpr);
 if lp==1,pr=0;end

% update shifted and convolved lines
 set(shift_line,'xdata',[ta(1),ta,ta(la)]);
 set(shift_mark,'xdata',tb);
 set(conv_line,'xdata',t3(1:j),'ydata',z(1:j));
 set(conv_mark,'xdata',tb,'ydata',zb);
 set(prod_line,'xdata',[tpr(1) tpr tpr(lp)],'ydata',[0 pr 0]);

% set(fixed_line,'xdata',x_d(1,:),'ydata',x_d(2,:));
% drawnow;
set(ui(20:21),'vis','on');
t_val=num2str(tb,4);y_val=num2str(zb,4);
disp_str=['y(' t_val ') = ' y_val];
set(ui(21),'string',disp_str);
end

⌨️ 快捷键说明

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