function scopeani() %Plots a slow-speed simulated scope screen to illustrate the effect %of proper or improper triggering. Use buttons to select the triggering to %animate. Push the stop button on the figure to get the menu back; quit %from the quit button on the menu %C. Sullivan, 7/01 Charles.R.Sullivan@dartmouth.edu choice=0; while choice ~= 5, choice=menu('Select Triggering','None','y = trigger level','+ slope crossing','- slope crossing','quit'); if choice==5, return, end f = 1.105; sweeprate = 0.5; sweeps = 50; triglevel = 0.5; points = 100; anifun(f,sweeprate,sweeps,choice,triglevel,points); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % End of Main, start of functions (just one) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function M=anifun(f,sweeprate,sweeps,trig,triglevel,anilen) %This function, though not scopani, offers partial support for... %OPTIONAL OUTPUT M=xlineani(....) %The animation can then be run, more smoothly, with %>>movie(M) displayrate = 20; figure(1) %____________________ % The STOP button--from odeplot %h = findobj(f,'Tag','stop'); %if isempty(h) ud.stop = 0; pos = get(0,'DefaultUicontrolPosition'); pos(1) = pos(1) - 15; pos(2) = pos(2) - 15; str = 'ud=get(gcf,''UserData''); ud.stop=1; set(gcf,''UserData'',ud);'; stophandle=uicontrol( ... 'Style','push', ... 'String','Stop', ... 'Position',pos, ... 'Callback',str, ... 'Tag','stop'); %else % set(h,'Visible','on'); % make sure it's visible % if ishold % oud = get(f,'UserData'); % ud.stop = oud.stop; % don't change old ud.stop status % else % ud.stop = 0; % end %end set(gcf,'UserData',ud); %____________________ %plot "beam", set up axes, etc. hx=plot(0,0,'wo','markersize',8,'markerFaceColor','g'); axis([0 1/sweeprate -1.5 1.5]) whitebg(gcf,'k') set(gcf,'DoubleBuffer','on') hold on ylabel('V') xlabel('t') told = 0; for sweep = 1:sweeps %Get some data ready to plot t=linspace(told,told+1/sweeprate,anilen); y = sin(2*pi*f*t); set(hx,'xdata',0) %Set beam to left %if trig == 1 %do nothing special--just go ahead. if trig ==6 %old method--no longer used. %find first place it gets close [minabs,imin] = min(abs(y-triglevel)); typabs = abs(y(imin+1)-triglevel); close = abs(y-triglevel) 0; it = find(pcross); it = it(1); for ti = 2:it set(hx,'ydata',y(ti)) pause(1/displayrate) end told = t(it); t=linspace(told,told+1/sweeprate,anilen); y = sin(2*pi*f*t); end if trig == 4 %find first place it crosses + to - y0=y(1); side = sign(y-triglevel); cross = diff(side); ncross = cross < 0; it = find(ncross); it = it(1); for ti = 2:it set(hx,'ydata',y(ti)) pause(1/displayrate) end told = t(it); t=linspace(told,told+1/sweeprate,anilen); y = sin(2*pi*f*t); end tplot = linspace(0,1/sweeprate,anilen); %set up initial plot h=plot(tplot(1),y(1),'g'); %Loop to generate animation SWEEP!!!!!!! for ti=1:anilen set(h,'Ydata',y(1:ti),'Xdata',tplot(1:ti)); set(hx,'ydata',y(ti),'Xdata',tplot(ti)); %Show and/or collect plots if(nargout > 0) M(ti)=getframe; else pause(1/displayrate) oud = get(gcf,'UserData'); if oud.stop ==1, break, end end end if oud.stop ==1, break, end told=t(length(t)); %hold on end hold off