Home > wafo > spec > covinterp.m

covinterp

PURPOSE ^

Interpolation of covariance function and derivatives

SYNOPSIS ^

Rout=covinterp(R,t,vari)

DESCRIPTION ^

  COVINTERP Interpolation of covariance function and derivatives
  
  CALL: Rout = covinterp(Rin,t,vari);
 
        Rout = covariance structure with new grid
        Rin  = covariance structure
        t    = vector of new grid points 
               OR t=[dt N] (used if length(t)=2)
               OR t=dt, with N such that not interpolation out of range
                  (used if length(t)=1)
               (default no change of input)
        vari = 'x', 'y' OR 't', dimension to interpolate in 
               (defualt 't', or if no t-variable then 'x')
 
  Interpolates all the matrices in the input covariance structure  
  (i.e. covariance function and all given derivatives)
  w.r.t dimension given by 'vari' such that the output is given at specified 
  points. If input t=[dt N], then output t=(0:N-1)*dt.
  If input t=dt, then N=length(Rin.t), and  output t=(0:N-1)*dt.
       
  See also  spec2cov

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

001 function Rout=covinterp(R,t,vari)
002 % COVINTERP Interpolation of covariance function and derivatives
003 % 
004 % CALL: Rout = covinterp(Rin,t,vari);
005 %
006 %       Rout = covariance structure with new grid
007 %       Rin  = covariance structure
008 %       t    = vector of new grid points 
009 %              OR t=[dt N] (used if length(t)=2)
010 %              OR t=dt, with N such that not interpolation out of range
011 %                 (used if length(t)=1)
012 %              (default no change of input)
013 %       vari = 'x', 'y' OR 't', dimension to interpolate in 
014 %              (defualt 't', or if no t-variable then 'x')
015 %
016 % Interpolates all the matrices in the input covariance structure  
017 % (i.e. covariance function and all given derivatives)
018 % w.r.t dimension given by 'vari' such that the output is given at specified 
019 % points. If input t=[dt N], then output t=(0:N-1)*dt.
020 % If input t=dt, then N=length(Rin.t), and  output t=(0:N-1)*dt.
021 %      
022 % See also  spec2cov
023 
024 % tested on: Matlab 5.3
025 % History: 
026 % revised by es 30.01.00   
027 % by es 13.10.1999  
028   
029 if nargin < 2
030   return
031 end
032 onedim=0;
033 Nin=length(R.R);
034 if prod(size(R.R))==Nin, % one-dim cvf
035   onedim=1;
036 end
037 names=fieldnames(R);
038 if nargin<3
039   if onedim
040     ind=find(strcmp(names,'x')+strcmp(names,'t')); %options are 't' and 'x'
041     if length(ind)>1
042       if length(R.t)>1
043     vari='t';
044       else
045     vari='x';
046       end
047     else
048       vari=lower(names{ind});
049     end
050   else
051     vari='t';
052   end
053 end
054 
055 tin=getfield(R,vari);  %tin is either R.t or R.x
056 tin=tin(:)'; % make it row
057 if min(tin)>=0
058   tin=[-tin(4:-1:2) tin];
059 end
060 if length(t)<=2
061   if length(t)<2
062     N=floor(tin(end)/t);
063   else
064     N=t(2);
065   end
066   t=(0:N-1)*t(1);
067 end
068 if t(end)>tin(end)
069   disp('Warning: interpolation outside range, NaN in output')
070 end
071 
072 ind=find(strncmp(names,'R',1)); 
073 d=ndims(R.R);
074 if d==3
075   error('Three-dimensional interpolation not available yet')
076 end
077 Rout=R;
078 for j=1:length(ind)
079   Y=getfield(R,names{ind(j)});
080   if onedim
081     Y=Y(:)'; % make sure it is a row
082     Y=[Y(:,4:-1:2) Y]';
083   elseif strcmp(vari,'t')
084     Y=[Y(:,4:-1:2) Y]';
085   end
086   if rem(length(names{ind(j)}),2)==1 %even order derivative
087     Y=interp1(tin,Y,t,'cubic*')';
088   else
089     Y=interp1(tin,Y,t,'cubic*')';
090   end
091   if  strcmp(vari,'x')&isfield(R,'t')
092     Y=Y';
093   end
094   Rout=setfield(Rout,names{ind(j)},Y);
095 end
096 Rout=setfield(Rout,vari,t);
097

Mathematical Statistics
Centre for Mathematical Sciences
Lund University with Lund Institute of Technology

Comments or corrections to the WAFO group


Generated on Thu 06-Oct-2005 02:21:16 for WAFO by m2html © 2003