annotate private/EDB1makemovie.m @ 18:2d5f50205527 jabuilder_int tip

Escape the trailing backslash as well
author Chris Cannam
date Tue, 30 Sep 2014 16:23:00 +0100
parents 90220f7249fc
children
rev   line source
tp@0 1 function M = EDB1makemovie(firstirfile,xvec,yvec,starttimestep,ntimesteps,filtir,maxvalue,viewpoint,...
tp@0 2 outlinecorners,noutlinepoints,sourcepoint,typeofir,windowsize,ampexp)
tp@0 3 % EDB1makemovie - Makes a movie based on IRs.
tp@0 4 %
tp@0 5 % Input parameters:
tp@0 6 % firstirfile The first of the IR files
tp@0 7 % xvec, yvec The ranges of x- and y-values of the receiver positions
tp@0 8 % starttimestep The time step to start from - useful if the impulse
tp@0 9 % responses have initial zeros.
tp@0 10 % ntimesteps The number of time steps
tp@0 11 % filtir A window to filter with
tp@0 12 % maxvalue [1,2] The minimum and maximum amplitude in the plot
tp@0 13 % viewpoint The point to view from [x y z]
tp@0 14 % outlinecorners A matrix of corners which will be plotted as an outline
tp@0 15 % in the form [x1 y1;x2 y2;x3 y3;...]
tp@0 16 % If the matrix has more columns than two, each pair of
tp@0 17 % column will be plotted as a separate outline, and they
tp@0 18 % will not be tied together.
tp@0 19 % noutlinepoints A list with the number of points in each column pair.
tp@0 20 % sourcepoint The [x y z] coordinates of the source.
tp@0 21 % typeofir 't' (default), 'g' (geom), 'f' (direct sound), 'd'
tp@0 22 % (diffracted), 'c' (direct sound + geom)
tp@0 23 % windowsize 's', 'm' or 'l' or 'x'
tp@0 24 % ampexp (optional) If a value is given here, the signal will be
tp@0 25 % plotted as abs(pressure)^ampexp, so that if ampexp =
tp@0 26 % 0.5, sqrt(abs(pressure)) will be plotted. If no value
tp@0 27 % is given, or the value zero is given, the linear pressure will be plotted.
tp@0 28 %
tp@0 29 % Output parameters:
tp@0 30 % M A movie, in the format which can be played by the
tp@0 31 % command movie(M);
tp@0 32 %
tp@0 33 % Uses functions EDB1strpend
tp@0 34 %
tp@0 35 % ----------------------------------------------------------------------------------------------
tp@0 36 % This file is part of the Edge Diffraction Toolbox by Peter Svensson.
tp@0 37 %
tp@0 38 % The Edge Diffraction Toolbox is free software: you can redistribute it and/or modify
tp@0 39 % it under the terms of the GNU General Public License as published by the Free Software
tp@0 40 % Foundation, either version 3 of the License, or (at your option) any later version.
tp@0 41 %
tp@0 42 % The Edge Diffraction Toolbox is distributed in the hope that it will be useful,
tp@0 43 % but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
tp@0 44 % FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
tp@0 45 %
tp@0 46 % You should have received a copy of the GNU General Public License along with the
tp@0 47 % Edge Diffraction Toolbox. If not, see <http://www.gnu.org/licenses/>.
tp@0 48 % ----------------------------------------------------------------------------------------------
tp@0 49 % Peter Svensson (svensson@iet.ntnu.no) 20050922
tp@0 50 %
tp@0 51 % M = EDB1makemovie(firstirfile,xvec,yvec,starttimestep,ntimesteps,filtir,maxvalue,viewpoint
tp@0 52 % outlinecorners,noutlinepoints,sourcepoint,typeofir,windowsize,ampexp);
tp@0 53
tp@0 54 disp('*************************************')
tp@0 55 disp('*')
tp@0 56 disp('* Creating a movie....')
tp@0 57 disp(' ')
tp@0 58
tp@0 59
tp@0 60 %--------------------------------------------------------------
tp@0 61 % Extract the filename stem
tp@0 62
tp@0 63 if nargin == 0
tp@0 64 [firstirfile,irfilepath] = uigetfile('*ir.mat','Please select the first irfile');
tp@0 65 [irfilepath,temp1,temp2] = fileparts(irfilepath);
tp@0 66 if ~isstr(firstirfile) | isempty(firstirfile)
tp@0 67 return
tp@0 68 end
tp@0 69 else
tp@0 70 [irfilepath,firstirfile,fileext] = fileparts(firstirfile);
tp@0 71 irfilepath = [irfilepath,filesep];
tp@0 72 firstirfile = [firstirfile,fileext];
tp@0 73 end
tp@0 74
tp@0 75 if nargin < 12
tp@0 76 typeofir = 't';
tp@0 77 windowsize = 's';
tp@0 78 ampexp = 0;
tp@0 79 else
tp@0 80 typeofir = lower(typeofir(1));
tp@0 81 if nargin < 13
tp@0 82 windowsize = 's';
tp@0 83 ampexp = 0;
tp@0 84 else
tp@0 85 windowsize = lower(windowsize(1));
tp@0 86 if nargin < 14
tp@0 87 ampexp = 0;
tp@0 88 else
tp@0 89 if ampexp < 0
tp@0 90 error('ERROR: ampexp must be larger than, or equal to, zero')
tp@0 91 end
tp@0 92 end
tp@0 93 end
tp@0 94 end
tp@0 95
tp@0 96 filestem = EDB1strpend(firstirfile,'_ir');
tp@0 97 iv = find(filestem=='_');
tp@0 98 iv = iv(length(iv));
tp@0 99 firstnumber = str2num(filestem(iv+1:length(filestem)));
tp@0 100 filestem = filestem(1:iv);
tp@0 101
tp@0 102 nx = length(xvec);
tp@0 103 ny = length(yvec);
tp@0 104 nfiles = nx*ny;
tp@0 105
tp@0 106 %--------------------------------------------------------------
tp@0 107 % Read the files, filter and store
tp@0 108
tp@0 109 Bigir = zeros(nfiles,ntimesteps);
tp@0 110
tp@0 111 disp(' Loading the files, starting with:')
tp@0 112 for ii = 1:nfiles
tp@0 113 irfile = [filestem,int2str(ii+firstnumber-1),'_ir.mat'];
tp@0 114 if ii == 1
tp@0 115 disp([' ',irfile])
tp@0 116 end
tp@0 117 eval(['load ',irfilepath,irfile])
tp@0 118 if typeofir == 'f'
tp@0 119 irtot = irdirect;
tp@0 120 elseif typeofir == 'g'
tp@0 121 irtot = irgeom;
tp@0 122 elseif typeofir == 'c'
tp@0 123 irtot = irgeom + irdirect;
tp@0 124 elseif typeofir == 'd',
tp@0 125 irtot = irdiff;
tp@0 126 end
tp@0 127
tp@0 128 if ~isempty(irtot)
tp@0 129 if length(irtot) < starttimestep
tp@0 130 disp(['WARNING: The value of starttimestep was set higher than the length of some of the IRs'])
tp@0 131 irtot = [0 0].';
tp@0 132 else
tp@0 133 irtot = irtot(starttimestep:end);
tp@0 134 end
tp@0 135 irtot = conv(filtir,full(irtot));
tp@0 136 if length(irtot) < ntimesteps
tp@0 137 irtot = [irtot;zeros(ntimesteps-length(irtot),1)];
tp@0 138 end
tp@0 139 else
tp@0 140 irtot = zeros(ntimesteps,1);
tp@0 141 end
tp@0 142
tp@0 143 if ampexp == 0
tp@0 144 Bigir(ii,:) = irtot(1:ntimesteps).';
tp@0 145 else
tp@0 146 Bigir(ii,:) = (abs(irtot(1:ntimesteps).')).^ampexp;
tp@0 147 end
tp@0 148
tp@0 149 end
tp@0 150
tp@0 151 disp(' ... files are loaded.')
tp@0 152
tp@0 153 sigvalues = sum(abs(Bigir));
tp@0 154 dsigvalues = diff([0 sigvalues]);
tp@0 155 ivstart = find(dsigvalues~=0);
tp@0 156 if isempty(ivstart)
tp@0 157 error('ERROR: All IRs are empty. Check if you have chosen the right IRs')
tp@0 158 end
tp@0 159 ivstart = ivstart(1);
tp@0 160 if ivstart > 1
tp@0 161 ivstart = ivstart-1;
tp@0 162 end
tp@0 163 Bigir = Bigir(:,ivstart:end);
tp@0 164 [slask,ntimesteps] = size(Bigir);
tp@0 165
tp@0 166 if length(maxvalue) < 2
tp@0 167 maxvalue = [maxvalue(1) max(max(Bigir))];
tp@0 168 end
tp@0 169
tp@0 170 %--------------------------------------------------------------
tp@0 171 % Go through, time step by time step and plot
tp@0 172
tp@0 173 opengl neverselect
tp@0 174
tp@0 175 % Prepare the outline plotting
tp@0 176
tp@0 177 [noutlinerows,ncolumns] = size(outlinecorners);
tp@0 178 noutlines = floor(ncolumns/2);
tp@0 179 if noutlines == 1
tp@0 180 outlinecorners = [outlinecorners;outlinecorners(1,:)];
tp@0 181 noutlinepoints = noutlinepoints+1;
tp@0 182 end
tp@0 183
tp@0 184 M = moviein(ntimesteps);
tp@0 185
tp@0 186 axisvalues = [min(xvec) max(xvec) min(yvec) max(yvec) maxvalue(1) maxvalue(2)];
tp@0 187 figure(1)
tp@0 188 clf
tp@0 189
tp@0 190 xyaspectratio = abs(max(xvec)-min(xvec))/abs(max(yvec)-min(yvec));
tp@0 191
tp@0 192 windowheight = 675;
tp@0 193 windowwidth = windowheight*xyaspectratio;
tp@0 194
tp@0 195 if windowwidth > 800
tp@0 196 scaledownfactor = windowwidth/800;
tp@0 197 windowwidth = windowwidth/scaledownfactor;
tp@0 198 windowheight = windowheight/scaledownfactor;
tp@0 199 end
tp@0 200
tp@0 201 windowpos = [380 80];
tp@0 202 if windowsize == 's'
tp@0 203 windowwidth = windowwidth/2;
tp@0 204 windowheight = windowheight/2;
tp@0 205 elseif windowsize == 'm'
tp@0 206 windowwidth = windowwidth/1.41;
tp@0 207 windowheight = windowheight/1.41;
tp@0 208 elseif windowsize == 'x'
tp@0 209 windowwidth = windowwidth*1.41;
tp@0 210 windowheight = windowheight*1.41;
tp@0 211 windowpos(1) = 100;
tp@0 212 end
tp@0 213
tp@0 214 %set(1,'Position',[380 80 530 675])
tp@0 215 set(1,'Position',[windowpos(1:2) windowwidth windowheight])
tp@0 216
tp@0 217 for jj=1:ntimesteps
tp@0 218 disp(int2str(jj))
tp@0 219 slice = Bigir(:,jj);
tp@0 220 slice = reshape(slice,ny,nx);
tp@0 221 surf(xvec,yvec,slice);
tp@0 222
tp@0 223 shading interp
tp@0 224
tp@0 225 if noutlines > 0
tp@0 226 for kk = 1:noutlines
tp@0 227 for ll = 1:noutlinepoints(kk)-1
tp@0 228 line([outlinecorners(ll,(kk-1)*2+1) outlinecorners(ll+1,(kk-1)*2+1)],[outlinecorners(ll,(kk-1)*2+2) outlinecorners(ll+1,(kk-1)*2+2)],[0 0])
tp@0 229 line([outlinecorners(ll,(kk-1)*2+1) outlinecorners(ll+1,(kk-1)*2+1)],[outlinecorners(ll,(kk-1)*2+2) outlinecorners(ll+1,(kk-1)*2+2)],[maxvalue(2) maxvalue(2)])
tp@0 230 line([outlinecorners(ll,(kk-1)*2+1) outlinecorners(ll,(kk-1)*2+1)],[outlinecorners(ll,(kk-1)*2+2) outlinecorners(ll,(kk-1)*2+2)],[0 maxvalue(2)])
tp@0 231 end
tp@0 232 line([outlinecorners(ll+1,(kk-1)*2+1) outlinecorners(ll+1,(kk-1)*2+1)],[outlinecorners(ll+1,(kk-1)*2+2) outlinecorners(ll+1,(kk-1)*2+2)],[0 maxvalue(2)])
tp@0 233 end
tp@0 234 end
tp@0 235 if ~isempty(sourcepoint)
tp@0 236 line([sourcepoint(1) sourcepoint(1)],[sourcepoint(2) sourcepoint(2)],[0 maxvalue(2)])
tp@0 237 end
tp@0 238
tp@0 239 colormap('jet')
tp@0 240 caxis([maxvalue(1) maxvalue(2)])
tp@0 241 brighten(0.5);
tp@0 242 axis(axisvalues);
tp@0 243 axis off
tp@0 244 view(viewpoint)
tp@0 245 M(:,jj) = getframe;
tp@0 246 end