tomwalters@0: % method of class @frame tomwalters@0: % tomwalters@0: % INPUT VALUES: tomwalters@0: % tomwalters@0: % RETURN VALUE: tomwalters@0: % tomwalters@0: % tomwalters@0: % (c) 2003, University of Cambridge, Medical Research Council tomwalters@0: % Stefan Bleeck (stefan@bleeck.de) tomwalters@0: % http://www.mrc-cbu.cam.ac.uk/cnbh/aimmanual tomwalters@0: % $Date: 2003/06/27 16:05:26 $ tomwalters@0: % $Revision: 1.16 $ tomwalters@0: tomwalters@0: function handlestr=plot(current_frame,options,ax) tomwalters@0: tomwalters@0: tomwalters@0: if nargin < 3 tomwalters@0: ax=gca; tomwalters@0: end tomwalters@0: if nargin < 2 tomwalters@0: options=[]; tomwalters@0: end tomwalters@0: tomwalters@0: % options.plotstyle='surf'; tomwalters@0: tomwalters@0: % extra options from aimmodules? tomwalters@0: if isfield(options,'extra_options'); tomwalters@0: has_extra_options=1; % in this case, jump at the end to a fucntion that makes colors tomwalters@0: else tomwalters@0: has_extra_options=0; % no extras in colors tomwalters@0: end tomwalters@0: tomwalters@0: % weather of not the plotting is linear tomwalters@0: if ~isfield(options,'is_log'); tomwalters@0: is_log=0; tomwalters@0: else tomwalters@0: is_log=options.is_log; tomwalters@0: end tomwalters@0: tomwalters@0: % the viewpoint in azimuth and elevation look help for view! tomwalters@0: if ~isfield(options,'viewpoint'); tomwalters@0: viewpoint=[0 90]; tomwalters@0: else tomwalters@0: viewpoint=options.viewpoint; tomwalters@0: end tomwalters@0: tomwalters@0: % which plot type, usually: waterfall, other: surf tomwalters@0: if ~isfield(options,'plotstyle'); tomwalters@0: plotstyle='waterfall'; tomwalters@0: else tomwalters@0: plotstyle=options.plotstyle; tomwalters@0: end tomwalters@0: tomwalters@0: % if waterfall, the plotcolor can be more complicated tomwalters@0: if ~isfield(options,'plotcolor'); tomwalters@0: has_specified_color=0; tomwalters@0: else tomwalters@0: plotcolor=options.plotcolor; tomwalters@0: has_specified_color=1; tomwalters@0: end tomwalters@0: tomwalters@0: % if positive time is to the right or to the left tomwalters@0: if isfield(options,'time_reversed'); tomwalters@0: time_reversed=options.time_reversed; tomwalters@0: else tomwalters@0: time_reversed=0; tomwalters@0: end tomwalters@0: tomwalters@0: % for compatibility. tomwalters@0: if isfield(options,'minimum_time'); tomwalters@0: options.minimum_time_interval=options.minimum_time; tomwalters@0: end tomwalters@0: if isfield(options,'maximum_time'); tomwalters@0: options.maximum_time_interval=options.maximum_time; tomwalters@0: end tomwalters@0: if ~isfield(options,'minimum_time_interval'); tomwalters@0: if is_log tomwalters@0: minimum_time_interval=0.001; tomwalters@0: else tomwalters@0: minimum_time_interval=getminimumtime(current_frame); tomwalters@0: end tomwalters@0: else tomwalters@0: minimum_time_interval=options.minimum_time_interval; tomwalters@0: end tomwalters@0: tomwalters@0: tomwalters@0: if ~isfield(options,'maximum_time_interval'); tomwalters@0: % maximum_time_interval=0.035; tomwalters@0: maximum_time_interval=getmaximumtime(current_frame); tomwalters@0: else tomwalters@0: maximum_time_interval=options.maximum_time_interval; tomwalters@0: end tomwalters@0: tomwalters@0: tomwalters@0: if ~isfield(options,'has_x_axis'); tomwalters@0: has_x_axis=1; tomwalters@0: else tomwalters@0: has_x_axis=options.has_x_axis; tomwalters@0: end tomwalters@0: tomwalters@0: if ~isfield(options,'has_y_axis'); tomwalters@0: has_y_axis=1; tomwalters@0: else tomwalters@0: has_y_axis=options.has_y_axis; tomwalters@0: end tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: current_frame_values=getvalues(current_frame); tomwalters@0: nr_channels=getnrchannels(current_frame); tomwalters@0: sr=getsr(current_frame); tomwalters@0: tomwalters@0: % prevent a matlab plotting-bug for empty matrices tomwalters@0: if max(max(current_frame_values))==0 && min(min(current_frame_values)) == 0 tomwalters@0: current_frame_values(1,400)=0.001; tomwalters@0: end tomwalters@0: tomwalters@0: % length=getlength(current_frame); tomwalters@0: start_time=getminimumtime(current_frame); tomwalters@0: tomwalters@0: if start_time < 0 % these are frames read in from ams! they start with negative times. Therefore we turn around the start and stoptime tomwalters@0: % temp=-maximum_time_interval; tomwalters@0: % maximum_time_interval=-minimum_time_interval; tomwalters@0: % minimum_time_interval=temp; tomwalters@0: % time_reversed=1-time_reversed; tomwalters@0: % current_frame=reverse(current_frame); tomwalters@0: % % max_time=getmaximumtime(current_frame); tomwalters@0: % fr=getpart(current_frame,start_time,0); tomwalters@0: % start_time=0; tomwalters@0: % current_frame=setstarttime(current_frame,0); tomwalters@0: end tomwalters@0: tomwalters@0: if is_log tomwalters@0: min_x_screen=1; % im logarithmischen Fall muss ich die ersten Punkte mitnehmen, damit ich sie plotten kann! tomwalters@0: max_x_screen=round(abs((maximum_time_interval-start_time)*sr)); % thats the first point we want to see on the screen tomwalters@0: else tomwalters@0: min_x_screen=round(abs((minimum_time_interval-start_time+1/sr)*sr)); % thats the first point we want to see on the screen tomwalters@0: max_x_screen=round(abs((maximum_time_interval-start_time)*sr)); % thats the first point we want to see on the screen tomwalters@0: end tomwalters@0: tomwalters@0: if max_x_screen>getnrpoints(current_frame) tomwalters@0: max_x_screen=getnrpoints(current_frame); tomwalters@0: maximum_time_interval=(max_x_screen/sr)+start_time; tomwalters@0: end tomwalters@0: tomwalters@0: step=1; tomwalters@0: if isequal(plotstyle,'surf') tomwalters@0: step=1; tomwalters@0: elseif isequal(plotstyle,'waterfall') tomwalters@0: oldunit2=get(ax,'Units'); tomwalters@0: set(ax,'Units','Pixel'); tomwalters@0: pos=get(ax,'Position'); tomwalters@0: breite=pos(3)/2; tomwalters@0: step=round((max_x_screen-min_x_screen)/breite); tomwalters@0: % step=1; tomwalters@0: if step<1 || nr_channels==1 tomwalters@0: step=1; tomwalters@0: end tomwalters@0: set(ax,'Units',oldunit2); tomwalters@0: tomwalters@0: if min_x_screen>2 tomwalters@0: current_frame_values(:,1:min_x_screen-1)=0; tomwalters@0: end tomwalters@0: end tomwalters@0: tomwalters@0: tomwalters@0: cvals=current_frame_values(:,min_x_screen:step:max_x_screen); tomwalters@0: if nr_channels==1 tomwalters@0: handle=plot(ax,cvals); tomwalters@0: ylabel(''); tomwalters@0: % set(ax,'YTick',[]); tomwalters@0: else tomwalters@0: if strcmp(plotstyle,'surf') tomwalters@0: % handle=surf(ax,cvals,'LineStyle','none'); tomwalters@0: handle=surf(ax,cvals,'LineStyle','none'); tomwalters@0: % view(ax,viewpoint); tomwalters@0: view(ax,[0 90]); tomwalters@0: else tomwalters@0: handle=waterfall(ax,cvals); % do the plotting! tomwalters@0: % this is a very important trick: If we plot it from directly above ([0 80]) tomwalters@0: % then white lines appear on the screen. To get rid of them, we have to tomwalters@0: % tilt the waterfall just marginally: tomwalters@0: % if min(min(cvals))<0 tomwalters@0: % view(ax,[viewpoint(1)-0.01 viewpoint(2)]); tomwalters@0: % else tomwalters@0: view(ax,[-0.01 80]); tomwalters@0: % view(ax,viewpoint); tomwalters@0: % end tomwalters@0: end tomwalters@0: grid off; tomwalters@0: end tomwalters@0: tomwalters@0: if time_reversed tomwalters@0: set(ax,'XDir','reverse') % turn them around, because the higher values shell end on the right tomwalters@0: else tomwalters@0: set(ax,'XDir','normal') % normale ausrichtung tomwalters@0: end tomwalters@0: if is_log tomwalters@0: min_x_screen=round(abs((minimum_time_interval-start_time+1/sr)*sr)); % thats the first point we want to see on the screen tomwalters@0: if nr_channels==1 tomwalters@0: set(ax,'xlim',[min_x_screen max_x_screen ]) tomwalters@0: set(ax,'ylim',[0 1]) tomwalters@0: % axis([ 0 1]); tomwalters@0: else tomwalters@0: if max_x_screen == min_x_screen tomwalters@0: max_x_screen = min_x_screen +1; tomwalters@0: end tomwalters@0: set(ax,'xlim',[min_x_screen max_x_screen]) tomwalters@0: set(ax,'ylim',[1 nr_channels]) tomwalters@0: set(ax,'zlim',[0 50]) tomwalters@0: tomwalters@0: % axis([ min_x_screen max_x_screen 1 nr_channels 0 50]); tomwalters@0: end tomwalters@0: set(ax,'XScale','log') tomwalters@0: t=minimum_time_interval; tomwalters@0: ti=[t 2*t 4*t 8*t 16*t 32*t 64*t]; tomwalters@0: tix=(ti)*sr; % there shell be the tix tomwalters@0: % tix(1)=tix(1)+1; tomwalters@0: ti=(ti*1000); tomwalters@0: ti=fround(ti,2); tomwalters@0: else % its not logarithmic! tomwalters@0: set(ax,'XScale','linear') tomwalters@0: nrx=size(cvals,2); tomwalters@0: if nr_channels==1 tomwalters@0: miny=min(cvals); tomwalters@0: maxy=max(cvals); tomwalters@0: set(ax,'xlim',[1 nrx]) tomwalters@0: set(ax,'ylim',[miny*1.3 maxy*1.3]) tomwalters@0: % axis([ 1 nrx miny*1.3 maxy*1.3]); tomwalters@0: else tomwalters@0: set(ax,'xlim',[1 nrx]) tomwalters@0: set(ax,'ylim',[1 nr_channels ]) tomwalters@0: set(ax,'zlim',[0 1]) tomwalters@0: tomwalters@0: % axis([ 1 nrx 1 nr_channels 0 1]); tomwalters@0: end tomwalters@0: nr_labels=8; tomwalters@0: tix=1:(nrx-1)/nr_labels:nrx; tomwalters@0: xstep=(maximum_time_interval-minimum_time_interval)*1000/(nr_labels); %works from -35 to 5 tomwalters@0: ti=([minimum_time_interval*1000:xstep:maximum_time_interval*1000+1]); tomwalters@0: ti=fround(ti,1); tomwalters@0: % text(min_x_screen*1.5,-scale_summe/5,'Time (ms)'); % this is at a nice position tomwalters@0: end tomwalters@0: tomwalters@0: if has_x_axis tomwalters@0: if max(tix)>1 tomwalters@0: set(ax,'XTick',tix); tomwalters@0: set(ax,'XTickLabel',ti); tomwalters@0: end tomwalters@0: else tomwalters@0: set(ax,'xtick',[]); % we dont want any z-Ticks! tomwalters@0: end % axis tomwalters@0: tomwalters@0: if has_y_axis && nr_channels>1 tomwalters@0: % make y-Ticks tomwalters@0: nr_labels=8; tomwalters@0: ystep=(nr_channels-1)/(nr_labels-1); tomwalters@0: tiy=1:ystep:nr_channels; tomwalters@0: ti=(current_frame.centerfrequencies(floor(tiy))/1000); tomwalters@0: ti=round(ti*10)/10; tomwalters@0: set(ax,'YTick',tiy); tomwalters@0: set(ax,'YTickLabel',ti); tomwalters@0: tomwalters@0: % if has_x_axis tomwalters@0: % if is_log tomwalters@0: % text(min_x_screen*1.9,-2,current_frame.x_axis_label); % this is at a nice position tomwalters@0: % else tomwalters@0: % text(120,-2,current_frame.x_axis_label); % this is at a nice position tomwalters@0: % end tomwalters@0: % end tomwalters@0: elseif nr_channels>1 tomwalters@0: set(ax,'ytick',[]); % we dont want any z-Ticks! tomwalters@0: end tomwalters@0: tomwalters@0: set(ax,'ztick',[]); % we dont want any z-Ticks! tomwalters@0: tomwalters@0: tomwalters@0: if strcmp(plotstyle,'surf') tomwalters@0: % which colormap should be used in case of a surf-plot tomwalters@0: if ~isfield(options,'colormap'); tomwalters@0: clrmap=zeros(64,3); tomwalters@0: else tomwalters@0: clrmap=options.colormap; tomwalters@0: end tomwalters@0: tomwalters@0: % shift the colormap tomwalters@0: tomwalters@0: % set the chosen colormap tomwalters@0: colormap(clrmap); tomwalters@0: % set the color limits so that it shows all colors tomwalters@0: set(ax,'CLimMode','manual'); tomwalters@0: tomwalters@0: colmin=0; tomwalters@0: colmax=max(max(cvals)); tomwalters@0: diff=colmax-colmin; tomwalters@0: tomwalters@0: % if ~isfield(options,'shiftcolormap'); tomwalters@0: % shiftcolormap=0.8; tomwalters@0: % else tomwalters@0: % shiftcolormap=options.shiftcolormap; tomwalters@0: % end tomwalters@0: % colmin=colmax-2*shiftcolormap*diff; tomwalters@0: % if colmax==colmin tomwalters@0: % colmax=colmin+0.001; tomwalters@0: % end tomwalters@0: tomwalters@0: % set(ax,'CLim',[colmin colmax]); tomwalters@0: tomwalters@0: % % colorbar is 1:256 tomwalters@0: % % actual spectrogram dynamic range is orig_dr tomwalters@0: % % new spectrogram dynamic range is new_dr tomwalters@0: % orig_dr = clrmap; tomwalters@0: % diff_dr = new_dr - orig_dr; tomwalters@0: % cmapIndices_per_dB = 256./diff(orig_dr); % a constant tomwalters@0: % diff_clim = diff_dr .* cmapIndices_per_dB; tomwalters@0: % cbar_clim = [1 256] + diff_clim; tomwalters@0: % % set(himage_cbar,'cdatamapping','scaled'); % do during creation tomwalters@0: % set(ax,'clim',cbar_clim); tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: % view(ax,viewpoint); tomwalters@0: tomwalters@0: % fancy graphics, takes time tomwalters@0: % shading interp tomwalters@0: % if isfield(options,'camlight'); tomwalters@0: % % can be 'left','right' or a vector of [az el] tomwalters@0: % if isnumeric(options.camlight) tomwalters@0: % for i=1:size(options.camlight,1) tomwalters@0: % eval(sprintf('lightangle(%f,%f);',options.camlight(i,1),options.camlight(i,2))); tomwalters@0: % end tomwalters@0: % else tomwalters@0: % eval(sprintf('camlight(''%s'',''infinite'');',options.camlight)); tomwalters@0: % end tomwalters@0: % end tomwalters@0: % tomwalters@0: % material default % looks best other options: dull, metal, shiny tomwalters@0: % tomwalters@0: % % tomwalters@0: % if isfield(options,'lighting'); tomwalters@0: % eval(sprintf('lighting %s',options.lighting)); tomwalters@0: % end tomwalters@0: tomwalters@0: % wheather or not there should be a colorbar tomwalters@0: % can be 'off', 'vertical, 'horizontal' tomwalters@0: if isfield(options,'colorbar'); tomwalters@0: if ~strcmp(options.colorbar,'off') tomwalters@0: colorbar(options.colorbar); tomwalters@0: end tomwalters@0: end tomwalters@0: tomwalters@0: else % boring waterfall plot tomwalters@0: if has_specified_color==1 tomwalters@0: if plotcolor=='k' tomwalters@0: clrmap(:,:)=0; tomwalters@0: elseif plotcolor=='r' tomwalters@0: clrmap(:,1)=0; tomwalters@0: elseif plotcolor=='c' tomwalters@0: clrmap(:,2)=0; tomwalters@0: elseif plotcolor=='g' tomwalters@0: clrmap(:,3)=0; tomwalters@0: end tomwalters@0: else tomwalters@0: % if nothing is set, then set everything is set to black tomwalters@0: clrmap=white; tomwalters@0: clrmap(:,:)=0; tomwalters@0: colormap(clrmap); tomwalters@0: end tomwalters@0: end tomwalters@0: tomwalters@0: tomwalters@0: % if is_log tomwalters@0: % x=300;y=nr_channels*1.1; tomwalters@0: % else tomwalters@0: % x=300;y=nr_channels*1.1; tomwalters@0: % end tomwalters@0: % text(x,y,current_frame.text); % this is at a nice position tomwalters@0: tomwalters@0: % if isfield(options,'display_time') tomwalters@0: % if options.display_time==1 tomwalters@0: % time=getcurrentframestarttime(current_frame); tomwalters@0: % time=fround(time*1000,0); tomwalters@0: % str=num2str(time); tomwalters@0: % text(x,y,[str ' ms']); % this is at a nice position tomwalters@0: % end tomwalters@0: % end tomwalters@0: tomwalters@0: if has_extra_options==1; % in this case, jump at the end to a fucntion that makes colors tomwalters@0: tomwalters@0: % cool_frame_plot_colors(current_frame,handle,options.extra_options); tomwalters@0: tomwalters@0: end tomwalters@0: tomwalters@0: % set(ax,'XDir',olddir) tomwalters@0: % set(ax,'XScale',oldscale); tomwalters@0: tomwalters@0: if nargout==1 tomwalters@0: handlestr=handle; tomwalters@0: end