annotate aim-mat/tools/@signal/plot.m @ 4:537f939baef0 tip

various bug fixes and changed copyright message
author Stefan Bleeck <bleeck@gmail.com>
date Tue, 16 Aug 2011 14:37:17 +0100
parents 20ada0af3d7d
children
rev   line source
tomwalters@0 1 % method of class @signal
tomwalters@0 2 %
tomwalters@0 3 % INPUT VALUES:
tomwalters@0 4 %
tomwalters@0 5 % RETURN VALUE:
tomwalters@0 6 %
tomwalters@0 7 %
bleeck@3 8 % This external file is included as part of the 'aim-mat' distribution package
bleeck@3 9 % (c) 2011, University of Southampton
bleeck@3 10 % Maintained by Stefan Bleeck (bleeck@gmail.com)
bleeck@3 11 % download of current version is on the soundsoftware site:
bleeck@3 12 % http://code.soundsoftware.ac.uk/projects/aimmat
bleeck@3 13 % documentation and everything is on http://www.acousticscale.org
tomwalters@0 14
bleeck@3 15
bleeck@3 16 function rethandle=plot(sig,border,style,ax)
bleeck@3 17 % usage: handle=plot(sig,border,style)
tomwalters@0 18 % plots the class signal. This plot works a little bit different from usual.
bleeck@3 19 % Parameter can either be: plot(signal,style) or plot(signal,border) or plot(signal,border,style)
tomwalters@0 20 % the border can consist of times and y-value or only the times that should be plotted (in seconeds!)
tomwalters@0 21
tomwalters@0 22 if nargin<4
tomwalters@0 23 ax=gca;
tomwalters@0 24 end
tomwalters@0 25 if nargin<3
bleeck@3 26 style='b-';
tomwalters@0 27 end
tomwalters@0 28
bleeck@3 29 if nargin==2 && all(ishandle(border))
tomwalters@0 30 ax=border;
tomwalters@0 31 end
bleeck@3 32 if nargin==3 && ishandle(style)
bleeck@3 33 ax=style;
tomwalters@0 34 end
tomwalters@0 35
tomwalters@0 36
tomwalters@0 37
tomwalters@0 38 durationbin=size(sig.werte,1);
tomwalters@0 39 % duration=durationbin/sr;
tomwalters@0 40 if nargin<2
tomwalters@0 41 t1=1;
tomwalters@0 42 t2=durationbin;
tomwalters@0 43 border=[t1 t2 min(sig.werte(t1:t2)) max(sig.werte(t1:t2))];
tomwalters@0 44 end
tomwalters@0 45
tomwalters@0 46 if isstruct(border) || isempty(border)
tomwalters@0 47 options=border;
tomwalters@0 48 t1=1;
tomwalters@0 49 t2=durationbin;
tomwalters@0 50 border=[t1 t2 min(sig.werte(t1:t2)) max(sig.werte(t1:t2))];
tomwalters@0 51 else
tomwalters@0 52 options=[];
tomwalters@0 53 if ischar(border)
bleeck@3 54 style=border;
tomwalters@0 55 t1=1;
tomwalters@0 56 t2=durationbin;
tomwalters@0 57 border=[t1 t2 min(sig.werte(t1:t2)) max(sig.werte(t1:t2))];
tomwalters@0 58 else
tomwalters@0 59 if isempty(border)
tomwalters@0 60 t1=1;
tomwalters@0 61 t2=durationbin;
tomwalters@0 62 border=[t1 t2 min(sig.werte(t1:t2)) max(sig.werte(t1:t2))];
tomwalters@0 63 else
tomwalters@0 64 t1=border(1);
tomwalters@0 65 t2=border(2);
tomwalters@0 66 x1=time2bin(sig,t1);
tomwalters@0 67 x2=time2bin(sig,t2);
tomwalters@0 68 nr=size(border,2);
tomwalters@0 69 if nr==2 % wenn nur die x-Werte angegeben werden
tomwalters@0 70 border=[x1 x2 min(sig.werte(x1+1:x2)) max(sig.werte(x1+1:x2))];
tomwalters@0 71 else
tomwalters@0 72 border(1)=x1;
tomwalters@0 73 border(2)=x2;
tomwalters@0 74 end
tomwalters@0 75 end
tomwalters@0 76 end
tomwalters@0 77 end
tomwalters@0 78
tomwalters@0 79 if ~isfield(options,'is_log');
tomwalters@0 80 is_log=0;
tomwalters@0 81 else
tomwalters@0 82 is_log=options.is_log;
tomwalters@0 83 end
tomwalters@0 84
tomwalters@0 85 if isfield(options,'minimum_time');
tomwalters@0 86 border(1)=time2bin(sig,options.minimum_time);
tomwalters@0 87 minimum_time=options.minimum_time;
tomwalters@0 88 else
tomwalters@0 89 minimum_time=bin2time(sig,border(1));
tomwalters@0 90 end
tomwalters@0 91
tomwalters@0 92 if isfield(options,'maximum_time');
tomwalters@0 93 border(2)=time2bin(sig,options.maximum_time);
tomwalters@0 94 maximum_time=options.maximum_time;
tomwalters@0 95 else
tomwalters@0 96 maximum_time=bin2time(sig,border(2));
tomwalters@0 97 end
tomwalters@0 98
tomwalters@0 99
tomwalters@0 100 % if the time scale is reversed (time from left to right)
tomwalters@0 101 if isfield(options,'time_reversed');
tomwalters@0 102 time_reversed=options.time_reversed;
tomwalters@0 103 else
tomwalters@0 104 time_reversed=0;
tomwalters@0 105 end
tomwalters@0 106
tomwalters@0 107 start_time=getminimumtime(sig);
tomwalters@0 108
tomwalters@0 109 min_x_screen=border(1); % einer wird abgezogen damit wir bei Null beginnen, nicht beim ersten bin, was blöde aussieht
tomwalters@0 110 max_x_screen=border(2);
tomwalters@0 111 minshowy=border(3);
tomwalters@0 112 maxy=border(4);
tomwalters@0 113
tomwalters@0 114 xvals=getxvalues(sig);
tomwalters@0 115 % if we are dealing with milliseconds (very often), then the units are in
tomwalters@0 116 % ms as well
bleeck@3 117 % if strfind(sig.unit_x,'(ms)')>0
bleeck@3 118 % multiplier=1000;
bleeck@3 119 % else
tomwalters@0 120 multiplier=1;
bleeck@3 121 % end
tomwalters@0 122
tomwalters@0 123
tomwalters@0 124 xvals=xvals.*multiplier;
tomwalters@0 125 yvals=getvalues(sig);
tomwalters@0 126
bleeck@3 127 if ishandle(style) % ups, something gone wrong
bleeck@3 128 style='b-';
bleeck@3 129 end
bleeck@3 130
tomwalters@0 131 % this is the plotting command:
bleeck@3 132 handle=plot(ax,xvals,yvals,style);
tomwalters@0 133
tomwalters@0 134 if time_reversed
tomwalters@0 135 set(ax,'XDir','reverse') % turn them around, because the higher values shell end on the right
tomwalters@0 136 else
tomwalters@0 137 set(ax,'XDir','normal') % normale ausrichtung
tomwalters@0 138 end
tomwalters@0 139
tomwalters@0 140 if is_log
tomwalters@0 141 set(ax,'XScale','log')
tomwalters@0 142 t=minimum_time*multiplier;
tomwalters@0 143 tix=[t 2*t 4*t 8*t 16*t 32*t 64*t 128*t 256*t 512*t 1024*t];
tomwalters@0 144 if ~isempty(sig.x_tick_labels)
tomwalters@0 145 ti=sig.x_tick_labels;
tomwalters@0 146 set(ax,'XTicklabel',ti);
tomwalters@0 147 end
tomwalters@0 148 set(ax,'XTick',tix);
tomwalters@0 149 else % its linear
tomwalters@0 150 set(ax,'XScale','linear')
tomwalters@0 151 end
tomwalters@0 152
tomwalters@0 153 miny=border(3);
tomwalters@0 154 maxy=border(4);
tomwalters@0 155 y=[miny maxy];
tomwalters@0 156 if miny==maxy
tomwalters@0 157 maxy=miny+1;
tomwalters@0 158 miny=miny-1;
tomwalters@0 159 end
bleeck@3 160 try
bleeck@3 161 set(ax,'xlim',[minimum_time*multiplier maximum_time*multiplier ])
bleeck@3 162 set(ax,'ylim',[miny*1.05 maxy*1.05])
bleeck@3 163 axis([minimum_time*multiplier maximum_time*multiplier miny*1.05 maxy*1.05]);
bleeck@3 164 end
tomwalters@0 165
tomwalters@0 166
tomwalters@0 167 xlabel(sig.unit_x);
tomwalters@0 168 ylabel(sig.unit_y);
tomwalters@0 169 title(sig.name,'Interpreter','none');
tomwalters@0 170
tomwalters@0 171 if nargout==1
tomwalters@0 172 rethandle=handle;
tomwalters@0 173 end
tomwalters@0 174
tomwalters@0 175 return