from High Speed PIV and Hotwire post processing by Anurag
High Speed PIV and hotwire post processing routines

stim1(frm1,frm2)
function [] = stim1(frm1,frm2)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%                                                                                                  %%
%%   Copyright (C) 2005-2007  Anurag Singh                                                          %%
%%                                                                                                  %%
%%       This program/code snippet/file (hence forth refered as "library")                          %%
%%       is free software; you can redistribute it and/or                                           %%
%%       modify it under the terms of the GNU Lesser General Public                                 %%
%%       License as published by the Free Software Foundation; either                               %%
%%       version 2.1 of the License, or (at your option) any later version.                         %%
%%                                                                                                  %%
%%       This library is distributed in the hope that it will be useful,                            %%
%%       but WITHOUT ANY WARRANTY; without even the implied warranty of                             %%
%%       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                          %%
%%       Lesser General Public License for more details.                                            %%
%%                                                                                                  %%
%%       You should have received a copy of the GNU Lesser General Public                           %%
%%       License along with this library; if not, write to the Free Software                        %%
%%       Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                  %%
%%                                                                                                  %%
%%   FILENAME:                                                                                      %%
%%      stim1.m                                                                                     %%
%%                                                                                                  %%
%%   AUTHOR:                                                                                        %%
%%                                                                                                  %%
%%      Anurag Singh,                                                                               %%
%%      MS, 2007                                                                                    %%
%%      Aerospace Engineering & Mechanics                                                           %%
%%      University of Minnesota - Twin Cities.                                                      %%
%%      Minneapolis, MN 55455 (USA)                                                                 %%
%%                                                                                                  %%
%%      (currently working at: Exa Corporation, Burlington, MA 01803)                               %%
%%                                                                                                  %%
%%   CONTACT/EMAIL:                                                                                 %%
%%                                                                                                  %%
%%      anurag@aem.umn.edu                                                                          %%
%%      anurag9@gmail.com                                                                           %%
%%                                                                                                  %%
%%   SOURCE CONTROL INFORMATION:                                                                    %%
%%      None (since I was planning on putting it under source control since it has                  %%
%%      reached the critical file system size. Would be a good thing to put it under                %%
%%      source control while making changes.                                                        %%
%%                                                                                                  %%
%%   DESCRIPTION:                                                                                   %%
%%                                                                                                  %%
%%       Need to add                                                                                %%
%%                                                                                                  %%
%%                                                                                                  %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% USAGE:
%
%  stim1(frame1,frame2)
%
%  Input Arguments:
%     frame1     First frame index which marks the biginning of the range of frames
%     frame2     Last frame index upto which images are considered for stitching
%
% Output: Stitched image along with corresponding x y dimension array
%
% EXAMPLE:
%  stim1(1,200)
%
% This function stitches vector images such that some are skipped inbetween to create a continuous large image.

global u_norm u v x y piv_ustd skip_files piv_ubar vecimfreq fov NX stimindx uim1 vim1 xim1 yim1 delta_99 u_tau nu

if(nargin ~= 2)
   disp ('  ERROR: Insufficient arguments.');
   help stim1;
else
   if (skip_files > 0)
    disp('Warning: Files were skipped while reading them initially.');
    disp('         The stitched image may not be a correct physical representation.');
   end

   dpix = round(size(u_norm,2)*piv_ubar/vecimfreq/(fov/1000));


   xim1  = x; 
   yim1  = y; 
   uim1  = squeeze(u_norm(frm1,:,:)); 
   vim1  = squeeze(v(frm1,:,:)); 

   imstep =  (fov/1000/piv_ubar)*vecimfreq - 1;
   inifrm = frm1 + imstep;

   stimindx = [frm1 1 NX 0];
   k      = 1;
   a      = frm1 + k*imstep;
   frame  = floor(a);

   while frame <= frm2


      % Compute the indices of the part of the image to be stitched
      p1 = 1;
      p2 = round(NX*(1 - (a - frame)));
      if(p2 == 0)
         frame = frame + 1;
         p2    = NX - 1;
      end
      p3 = NX - p2;
      
      stimindx = [stimindx; [frame p1 p2 p3]];
      %if(frame+1 <= frm2 )%&& p2 ~= 0)
      %   uim1 = [shiftdim(u_norm(frame+1,p1:p3,:),1);  shiftdim(u_norm(frame,p1:p2,:),1); uim1];
      %   vim1 = [shiftdim(v(frame+1,p1:p3,:),1);  shiftdim(v(frame,p1:p2,:),1); vim1];
      %   xim1 = [xim1; xim1(size(xim1,1),1) + x(:,:) ];
      %   yim1 = [yim1; y(:,:)];
      %
      %elseif(frame+1 <= frm2)
      %   uim1 = [shiftdim(u_norm(frame+1,p1:p3,:),1); uim1];
      %   vim1 = [shiftdim(v(frame+1,p1:p3,:),1); vim1];
      %   xim1 = [xim1; xim1(size(xim1,1),1) + x(:,:) ];
      %   yim1 = [yim1; y(:,:)];
      %else
         uim1 = [shiftdim(u_norm(frame,p1:p2,:),1); uim1];
         vim1 = [shiftdim(v(frame,p1:p2,:),1); vim1];
         xim1 = [xim1; xim1(size(xim1,1),1) + x(p1:p2,:) ];
         yim1 = [yim1; y(p1:p2,:)];
      %end
      
      % Increment the frames
      k      = k + 1;
      a      = frm1 + k*imstep;
      frame  = floor(a);
   end

   % Display the stiched image
   figure;
   pcolor(xim1*u_tau/nu, yim1*u_tau/nu, uim1) 
   caxis([-3*piv_ustd 3*piv_ustd])                 

   shading interp;  
   lighting phong;   
   daspect([1 1 1]); 
   hold on
   %quiver(xim1, yim1, uim1, vim1, 1,'k') 
   hold off

   xlabel('Streamwise distance normalized by \delta_{99} ->');
   ylabel('Spanwise distance, normalized by \delta_{99} ->');
   
   xlabel('x^{+} ->');
   ylabel('y^{+} ->');

   title(['Stiched Image (Frame range = ',num2str(frm1),'-',num2str(frm2),', skipping ',num2str(imstep),' images, images stitched ',num2str(k),', Flow is from left to right)']);
   drawnow;
   
   stimindx; 
end

Contact us at files@mathworks.com