Home > wafo > spec > private > spa2time.m

spa2time

PURPOSE ^

Transform of spectrum from wave no. to frequency (used in spec2spec)

SYNOPSIS ^

Sf=spa2time(S,w,theta,g),

DESCRIPTION ^

  SPA2TIME Transform of spectrum from wave no. to frequency (used in spec2spec)
 
  CALL:  Sf = spa2time(S,w,theta,g)
 
    Sf = frequency or directional spectrum, which depends on input
    S  = spectrum struct
   w,theta = lag of output (default depending on input spectrum)
    g  = constant of gravity (default see gravity)
 
  Transforms a wave number spectrum to a frequency or directional spectrum 
  Input 1D gives output 1D, input 2D gives output 2D
  Rotation, transformation etc is preserved
 
  See also definitions, spec2spec

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

001 function Sf=spa2time(S,w,theta,g),
002 % SPA2TIME Transform of spectrum from wave no. to frequency (used in spec2spec)
003 %
004 % CALL:  Sf = spa2time(S,w,theta,g)
005 %
006 %   Sf = frequency or directional spectrum, which depends on input
007 %   S  = spectrum struct
008 %  w,theta = lag of output (default depending on input spectrum)
009 %   g  = constant of gravity (default see gravity)
010 %
011 % Transforms a wave number spectrum to a frequency or directional spectrum 
012 % Input 1D gives output 1D, input 2D gives output 2D
013 % Rotation, transformation etc is preserved
014 %
015 % See also definitions, spec2spec
016 
017 % Tested on Matlab 5.3
018 % History: revised by es 29.11.1999: norm. in both x and y (length(g) 1 OR 2)
019 %          by es 99.08.17
020 
021 if nargin<3
022   if isfield(S,'g')
023     g=S.g;
024   else
025     g=gravity;
026   end
027 end
028 
029 if ~(strcmpi(S.type(end-2:end),'k1d')|strcmpi(S.type(end-2:end),'k2d'))
030   error('Spectrum already in time domain')
031 end
032 Sf=S;
033 k=S.k(:)';
034 Sk=S.S;
035 Sf=rmfield(Sf,'k');
036 %if isfield(Sf,'phi')
037 %  Sf=rmfield(Sf,'phi'); % a rotation has no sense in freq-spectrum
038 %end
039 if nargin<2|isempty(w)
040   w=linspace(0,k2w(k(end),0,S.h,g),length(k))';
041 else
042   if length(w)==1 % then interpret w as dw (step length)
043     w=(0:length(k)-1)*w;
044   end
045 end
046 w=w(:)'; % row vector
047 Sf.w=w;
048 
049 if strcmpi(S.type(end-2:end),'k1d')
050 
051   kw=w2k(w,0,S.h,g(1));
052   in=(kw>k(1))&(kw<=k(end));
053   Gf=zeros(size(k));
054   Gf(in)=interp1(k,Sk,kw(in));
055   Sf.S=zeros(size(w));
056   Sf.S=Gf.*dkdw(w,kw,S.h,g(1));
057   Sf.type='freq';
058 else
059   if S.h<inf
060     disp('This transformation for finite depth is not available yet')
061     return
062   end
063   if nargin<3|isempty(theta)
064     if S.k(1)<0
065       theta=linspace(-pi,pi,2^7+1);
066     else
067       theta=linspace(-pi/2,pi/2,2^6+1);
068     end
069   end
070   theta=theta(:);
071   Sf.theta=theta;
072   W=ones(size(theta))*w;
073   TH=theta*ones(size(w));
074   KW=W.^2;
075   K=KW.*cos(TH)/g(1);  % non-equidistant K derived from (W,TH)
076   K2=KW.*sin(TH)/g(end); % non-equidistant K2 derived from (W,TH)
077   Gk=zeros(size(W));
078   in=(K>k(1))&(K<=k(end))&(K2>S.k2(1))&(K2<=S.k2(end));
079   Gk(in)=interp2(k,S.k2,Sk,K(in),K2(in),'*linear');
080   Sf.S=Gk.*W.^3*2/g(1)/g(end);  % directional spectrum
081   Sf=rmfield(Sf,'k2');
082   if strcmpi(S.type,'rotk2d')
083     Sf.type='rotdir';
084   else
085     Sf.type='dir';
086   end
087 end
088 return
089 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
090 
091 function dk=dkdw(w,k,h,g)
092 
093 if h==inf
094   dk=2*w/g;
095 else
096   dk=zeros(size(w));
097   dk(k>0)=2*w(k>0)./(g*tanh(k(k>0)*h)+g*h*k(k>0).*(1-tanh(k(k>0)*h).^2));
098 end
099 return
100

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