Home > wafo > spec > spec2bw.m

# spec2bw

## PURPOSE

Evaluates some spectral bandwidth and irregularity factors

## SYNOPSIS

bw = spec2bw(S,fact)

## DESCRIPTION

``` SPEC2BW Evaluates some spectral bandwidth and irregularity factors

CALL:  bw = spec2bw(S,factors)

bw = vector of factors
S  = spectrum struct
factors = vector with integers, see below. (default [1])

If input spectrum is of wave-number type, ouput are factors for
corresponding 'k1D', else output are factors for 'freq'.
Input vector 'factors' correspondence:
1 alpha=m2/sqrt(m0*m4)                        (irregularity factor)
2 eps2 = sqrt(m0*m2/m1^2-1)                   (narrowness factor)
3 eps4 = sqrt(1-m2^2/(m0*m4))=sqrt(1-alpha^2) (broadness factor)
4 Qp=(2/m0^2)int_0^inf f*S(f)^2 df            (peakedness factor)
Order of output is the same as order in 'factors'

Example:
S=demospec;
bw=spec2bw(S,[1 2 3 4]);```

## CROSS-REFERENCE INFORMATION

This function calls:
 simpson Numerical integration with the Simpson method spec2mom Calculates spectral moments from spectrum spec2spec Transforms between different types of spectra error Display message and abort function. getfield Get structure field contents. isfield True if field is in structure array. lower Convert string to lowercase. strcmp Compare strings.
This function is called by:
 Chapter3 % CHAPTER3 Demonstrates distributions of wave characteristics

## SOURCE CODE

```001 function bw = spec2bw(S,fact)
002 %SPEC2BW Evaluates some spectral bandwidth and irregularity factors
003 %
004 % CALL:  bw = spec2bw(S,factors)
005 %
006 %        bw = vector of factors
007 %        S  = spectrum struct
008 %   factors = vector with integers, see below. (default [1])
009 %
010 % If input spectrum is of wave-number type, ouput are factors for
011 % corresponding 'k1D', else output are factors for 'freq'.
012 % Input vector 'factors' correspondence:
013 %    1 alpha=m2/sqrt(m0*m4)                        (irregularity factor)
014 %    2 eps2 = sqrt(m0*m2/m1^2-1)                   (narrowness factor)
015 %    3 eps4 = sqrt(1-m2^2/(m0*m4))=sqrt(1-alpha^2) (broadness factor)
016 %    4 Qp=(2/m0^2)int_0^inf f*S(f)^2 df            (peakedness factor)
017 % Order of output is the same as order in 'factors'
018 %
019 % Example:
020 %   S=demospec;
021 %   bw=spec2bw(S,[1 2 3 4]);
022
023 % References:
024 %
025
026 % Tested on: Matlab 5.3
027 % History:
028 % Revised by jr 26.11.01
029 % - The variable vari was not assigned a value in the
030 %   case of .type='freq'. Added an else statement in
031 %   the second if sequence.
032 % Revised by es 23.05.00
033 % - do not call spec2spec if already .type='freq'
034 % By es 23.09.1999
035
036 if nargin<2|isempty(fact)
037   fact=1;
038 end
039
040 if isfield(S,'k')
041   S=spec2spec(S,'k1d');
042   vari='k';
043 elseif ~strcmp(lower(S.type),'freq')
044   S=spec2spec(S,'freq');
045   vari='w';
046 else
047   vari = 'w';
048 end
049
050 m=spec2mom(S,4,[],0);
051 bw=zeros(size(fact));
052 for j=1:length(fact)
053   switch fact(j)
054     case 1
055       bw(j)=m(3)/sqrt(m(1)*m(5));
056     case 2
057       bw(j)=sqrt(m(1)*m(3)/m(2)^2-1);
058     case 3
059       bw(j)=sqrt(1-m(3)^2/m(1)/m(5));
060     case 4
061       f=getfield(S,vari);
062       bw(j)=2/m(1)^2*simpson(f,f(:).*S.S(:).^2);
063     otherwise
064       error('Factor outside range (1,...,4)')
065   end
066 end
067
068
069
070```

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