annotate private/EDB1plotstackedIRs.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 Bigir = EDB1plotstackedIRs(firstirfile,nfiles,offset,filtir,typeofir,startsample,endsample)
tp@0 2 % EDB1plotstackedIRs - Plots a number of IRs in a stacked way.
tp@0 3 %
tp@0 4 % Input parameters:
tp@0 5 % firstirfile The data file containing the first IR file
tp@0 6 % nfiles The number of files
tp@0 7 % offset The numerical offset for each file
tp@0 8 % filtir A window to filter with
tp@0 9 % typeofir 't' (default), 'g' (geom), 'f' (direct sound), 'd'
tp@0 10 % (diffracted)
tp@0 11 % startsample (optional) The first sample number that should be
tp@0 12 % plotted for each IR (after filtering). Default: 1.
tp@0 13 % endsample (optional) The last sample number that should be
tp@0 14 % plotted for each IR (after filtering). Default: the
tp@0 15 % last sample for the longest of all IRs.
tp@0 16 %
tp@0 17 % Output parameters:
tp@0 18 % Bigir Matrix, [nfiles,nlength], of the IRs in the files, one
tp@0 19 % per row.
tp@0 20 %
tp@0 21 % Uses functions EDB1strpend
tp@0 22 %
tp@0 23 % ----------------------------------------------------------------------------------------------
tp@0 24 % This file is part of the Edge Diffraction Toolbox by Peter Svensson.
tp@0 25 %
tp@0 26 % The Edge Diffraction Toolbox is free software: you can redistribute it and/or modify
tp@0 27 % it under the terms of the GNU General Public License as published by the Free Software
tp@0 28 % Foundation, either version 3 of the License, or (at your option) any later version.
tp@0 29 %
tp@0 30 % The Edge Diffraction Toolbox is distributed in the hope that it will be useful,
tp@0 31 % but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
tp@0 32 % FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
tp@0 33 %
tp@0 34 % You should have received a copy of the GNU General Public License along with the
tp@0 35 % Edge Diffraction Toolbox. If not, see <http://www.gnu.org/licenses/>.
tp@0 36 % ----------------------------------------------------------------------------------------------
tp@0 37 % Peter Svensson (svensson@iet.ntnu.no) 20030806
tp@0 38 %
tp@0 39 % EDB1plotstackedIRs(firstirfile,nfiles,offset,filtir,typeofirs,startsample,endsample);
tp@0 40
tp@0 41 %--------------------------------------------------------------
tp@0 42 % Extract the filename stem
tp@0 43
tp@0 44 if nargin == 0
tp@0 45 [firstirfile,irfilepath] = uigetfile('*ir.mat','Please select the first irfile');
tp@0 46 [irfilepath,temp1,temp2] = fileparts(irfilepath);
tp@0 47 if ~isstr(firstirfile) | isempty(firstirfile)
tp@0 48 return
tp@0 49 end
tp@0 50 else
tp@0 51 [irfilepath,firstirfile,fileext] = fileparts(firstirfile);
tp@0 52 irfilepath = [irfilepath,filesep];
tp@0 53 firstirfile = [firstirfile,fileext];
tp@0 54 end
tp@0 55
tp@0 56 if nargin < 5
tp@0 57 typeofir = 't';
tp@0 58 else
tp@0 59 typeofir = lower(typeofir(1));
tp@0 60 end
tp@0 61
tp@0 62 if nargin < 6
tp@0 63 startsample = 1;
tp@0 64 end
tp@0 65 if nargin < 7
tp@0 66 endsample = -1;
tp@0 67 end
tp@0 68
tp@0 69 filestem = EDB1strpend(firstirfile,'_ir');
tp@0 70 iv = find(filestem=='_');
tp@0 71 iv = iv(length(iv));
tp@0 72 firstnumber = str2num(filestem(iv+1:length(filestem)));
tp@0 73 filestem = filestem(1:iv)
tp@0 74
tp@0 75 %--------------------------------------------------------------
tp@0 76 % Read the files
tp@0 77
tp@0 78 offsetvec = ([1:nfiles].'-1)*offset;
tp@0 79
tp@0 80 disp(' Loading files')
tp@0 81 for ii = nfiles:-1:1
tp@0 82 irfile = [filestem,int2str(ii+firstnumber-1),'_ir.mat'];
tp@0 83 eval(['load ',irfilepath,irfile])
tp@0 84 irtot = real(irtot);
tp@0 85 if typeofir == 'f'
tp@0 86 irtot = irdirect;
tp@0 87 elseif typeofir == 'g'
tp@0 88 irtot = irgeom + irdirect;
tp@0 89 elseif typeofir == 's'
tp@0 90 irtot = irgeom;
tp@0 91 elseif typeofir == 'd'
tp@0 92 irtot = real(irdiff);
tp@0 93 end
tp@0 94
tp@0 95 if isempty(irtot)
tp@0 96 irtot = [0 0].';
tp@0 97 end
tp@0 98
tp@0 99 irtot = conv(filtir,full(irtot));
tp@0 100 if endsample == -1
tp@0 101 irtot = irtot(startsample:end);
tp@0 102 else
tp@0 103 if endsample <= length(irtot)
tp@0 104 irtot = irtot(startsample:endsample);
tp@0 105 else
tp@0 106 irtot = irtot(startsample:end);
tp@0 107 end
tp@0 108 end
tp@0 109
tp@0 110 signvec = sign(irtot);
tp@0 111 irtot = abs(irtot).^(1/1).*signvec;
tp@0 112
tp@0 113 if ii == nfiles
tp@0 114 Bigir = zeros(nfiles,length(irtot));
tp@0 115 [slask,nbigir] = size(Bigir);
tp@0 116 Bigir = Bigir + offsetvec(:,ones(1,nbigir));
tp@0 117 Bigir(ii,:) = Bigir(ii,:) + (irtot).';
tp@0 118 else
tp@0 119 [slask,nbigir] = size(Bigir);
tp@0 120 nir = length(irtot);
tp@0 121 if nir > nbigir
tp@0 122 Bigir = [Bigir offsetvec(:,ones(1,nir-nbigir))];
tp@0 123 end
tp@0 124 Bigir(ii,1:nir) = Bigir(ii,1:nir) + (irtot).';
tp@0 125 end
tp@0 126
tp@0 127 end
tp@0 128
tp@0 129 if ~isempty(Bigir)
tp@0 130 plot(Bigir.','r')
tp@0 131 else
tp@0 132 error(' ERROR: The IRs were all empty. Please check that you did not specify start and end samples that were longer than the IR length!')
tp@0 133 end