K2W Translates from wave number to frequency using the dispersion relation CALL: [w,theta]=k2w(k,k2,h,g) w = angular frequency (rad/s) theta = direction (rad) k = wave numbers (rad/m) k2 = second dimension wave number (default 0) h = water depth (m) (default Inf) g = constant of gravity (default see gravity) Dispersion relation: w = sqrt(g*K*tanh(K*h)) ( 0 < w < inf) theta = atan2(k2,k) (-pi < theta < pi) where K = sqrt(k^2+k2^2) The size of w,theta is the common size of k and k2 if they are matrices, OR length(k2) x length(k) if they are vectors. If k or k2 is scalar it functions as a constant matrix of the same size as the other. See also w2k
Spectral simulation of a Gaussian sea, 2D (x,t) or 3D (x,y,t) | |
Transform of spectrum from wave no. to frequency (used in spec2spec) | |
Transform of spectrum from frequency to wave no. (used in spec2spec) |
001 function [w,th]=k2w(k,k2,h,g,u,u2) 002 % K2W Translates from wave number to frequency 003 % using the dispersion relation 004 % 005 % CALL: [w,theta]=k2w(k,k2,h,g) 006 % 007 % w = angular frequency (rad/s) 008 % theta = direction (rad) 009 % k = wave numbers (rad/m) 010 % k2 = second dimension wave number (default 0) 011 % h = water depth (m) (default Inf) 012 % g = constant of gravity (default see gravity) 013 % 014 % Dispersion relation: 015 % w = sqrt(g*K*tanh(K*h)) ( 0 < w < inf) 016 % theta = atan2(k2,k) (-pi < theta < pi) 017 % where 018 % K = sqrt(k^2+k2^2) 019 % 020 % The size of w,theta is the common size of k and k2 if they are matrices, 021 % OR length(k2) x length(k) if they are vectors. If k or k2 is scalar 022 % it functions as a constant matrix of the same size as the other. 023 % 024 % See also w2k 025 026 % secret options: 027 % u = current velocity (default 0) 028 % u2 = second dimension current velocity (default 0) 029 % note: when u~=0 | u2~=0 then th is not calculated correctly 030 031 032 % Tested on: Matlab 5.3, 5.2 033 % History: 034 % revised by es 25.05.00, made 'If k or k2...' in help really true 035 % revised by es 24.01.2000 036 % revised pab 15.02.2000 - added current u,u2 037 %by es 13.08.99 038 039 040 if nargin<1|isempty(k) 041 w=[];th=[]; 042 return 043 end 044 if nargin<2|isempty(k2) 045 k2=0; 046 end 047 if nargin<3|isempty(h) 048 h=inf; 049 end 050 if nargin<4|isempty(g) 051 g=gravity; 052 end 053 054 if nargin<5|isempty(u) 055 u=0; 056 end 057 if nargin<6|isempty(u2) 058 u2=0; 059 end 060 % Control of dimension of k and k2 061 ktype=0; 062 if prod(size(k2))>1 % non-scalar 063 if size(k2,1)==1|size(k2,2)==1 % k2 vector 064 k2=k2(:); 065 ktype=1; 066 end 067 if size(k,1)==1|size(k,2)==1 % k vector or scalar 068 if ktype==1 % k2 also vector 069 k2=k2(:,ones(1,length(k))); 070 k=k(:); 071 k=k(:,ones(1,size(k2,1)))'; 072 else 073 error('Input dimensions do not match') 074 end 075 else % both matrices 076 if any(size(k)~=size(k2)) 077 error('Input dimensions do not match') 078 end 079 end 080 end 081 082 ku=k.*u; 083 ku2=k2.*u2; 084 085 if nargout>1 086 th=atan2(k2,k); 087 end 088 k=sqrt(k.^2+k2.^2); 089 w=zeros(size(k)); 090 ix=find(k>0); 091 if length(ku2)==1 & length(k)>1 092 ku2=ku2*ones(size(k)); 093 end 094 if any(ix) 095 w(ix)=ku(ix)+ku2(ix)+sqrt(g*k(ix).*tanh(k(ix)*h)); 096 end 097 iy=find(w<0); 098 if any(iy) 099 disp('Warning: waves and current are in opposite directions') 100 disp(' making some of the frequencies negative.') 101 disp(' Here we are forcing the negative frequencies to zero') 102 w(iy)=0; % force w to zero 103 end 104
Comments or corrections to the WAFO group