Home > wafo > multidim > dspec2spreading.m

## PURPOSE

Returns the directional spreading function D of S

## DESCRIPTION

``` DSPEC2SPREADING Returns the directional spreading function D of S

S = Directional spectrum structure with at least the fields:
.S     Spectrum values (size= [nt nf]).
.w OR .f  Frequency, length nf.
.theta Angular lags, length nt.
D  = Directional spreading structure with the same fields as S.

Let S(w,theta) = S(w)*D(w,theta), then D(w,theta) is the
directional spreading function of S, if int D(w,theta) dtheta = 1 for
each w.

## CROSS-REFERENCE INFORMATION

This function calls:
 error Display message and abort function. isfield True if field is in structure array. trapz Trapezoidal numerical integration.
This function is called by:

## SOURCE CODE

```001 function D = dspec2spreading(S)
003 %
004 %  CALL: D = dspec2spreading(S);
005 %
006 %  S = Directional spectrum structure with at least the fields:
007 %      .S     Spectrum values (size= [nt nf]).
008 %      .w OR .f  Frequency, length nf.
009 %      .theta Angular lags, length nt.
010 % D  = Directional spreading structure with the same fields as S.
011 %
012 % Let S(w,theta) = S(w)*D(w,theta), then D(w,theta) is the
013 % directional spreading function of S, if int D(w,theta) dtheta = 1 for
014 % each w.
015 %
017
018
019 % Tested on: Matlab 6
020 % History
021 % by pab 13.10.2002
022 error(nargchk(1,1,nargin))
023
024 if (~isfield(S,'S'))
025   error('S is missing from the spectrum structure!')
026 end
027
028 if (~isfield(S,'theta'))
029   error('theta is missing from the spectrum structure!')
030 end
031
032 D   = S;
033 nt  = length(D.theta);
034 ind = find(D.S<0 | isnan(D.S));
035 if any(ind),
036 %  disp(['Negative directional distribution. Setting negative values to zero. min(DS) = '  num2str(min(DS(ind)))])
037   D.S(ind) = 0;
038 end
039
040 %Normalize so that int D(theta,f) dtheta = 1 for each f
041 %~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
042
043 %Sf2      = simpson(D.theta,D.S);
044 Sf2       = trapz(D.theta,D.S);
045 k         = find(Sf2);
046 D.S(:,k)  = S.S(:,k)./Sf2(ones(nt,1),k);
047 %plot(Sf2)
048 %pause
049 return
050```

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