Вы находитесь на странице: 1из 21

Technical University of Denmark

Wind energy:
Generation of time series from a spectrum:
Generation of Wind times series from the Kaimal spectrum
Generation of wave times series from the JONSWAP spectrum
Emmanuel Branlard
February 2010
CONTENTS

Contents

Introduction and definition of the problem 1

I Wind time series generation 1

1 Kaimal spectrum 1

2 Wind Time series generations 1

3 Final verifications 2

II Wave time series generation 4

4 JONSWAP spectrum 4

5 Wave time series generation 5

6 Final verification 6

Conclusion 6

References 7

Appendix 8

A R code 9
A.1 Main Source code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
A.2 Sample generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

B Matlab code 10
B.1 Mains . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
B.2 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

February 2010 i
2 WIND TIME SERIES GENERATIONS

Introduction

In this report, stochastic wind and wave times series are generated from a given spectrum. The
Kaimal spectrum is used for wind times series, and the JONSWAP spectrum is used for wave times
series. After presenting the models, the generation of times series from these spectra will be discussed.
Eventually, the spectra of the time series will be calculated in order to check that it indeed matches
the input spectra, thus validating the algorithm employed.

Part I

Wind time series generation


1 Kaimal spectrum

The Kaimal spectrum will be used as it is a simple approximation for the wind spectrum[2]. This model
contain the typical −5/3 power law for high frequencies, and it introduces a relation ship between
the spectrum amplitude and three parameters relevant for the wind : the height above ground z, the
mean wind speed U and the friction velocity u∗ . The expression of the Kaimal spectrum is as follow:
52.5z/U 52.5z/U
Suu (f ) = u2∗ 5/3
or Suu (ω) = u2∗ (1)
(1 + 33n) (1 + 33 × 2πn)5/3
where n = f z/U . The set of parameters used in this report is: z = 70m, U = 20m/s and u∗ = 1m/s.
The spectrum for a sampling frequency of fs = 10Hz and N = 105 values is displayed on figure 1.
103
102
Energy Density S [ m2 s−2 Hz−1 ]
101
100
10−1
10−2
10−3

24h 12h 1h 10' 1' 1'' fN


10−4

10−5 10−4 10−3 10−2 10−1 100 101


Frequency f [Hz]

Figure 1: The Kaimal spectrum with the typical −5/3 power law at high frequencies

2 Wind Time series generations

First approach No direct relationship exists to determine the Fourier coefficients from the spectrum
so that these coefficients have to be generated randomly. Nevertheless, the standard deviation of each
coefficient is determined by the spectrum, that is:
2 T
σX l
= Suu (ωl ) (2)

February 2010 1
3 FINAL VERIFICATIONS

where T = N/fs . As a results of this, each Fourier coefficient Xl is generated using a normal distribu-
tion of mean 0 and standard deviation σXl . The mean value of the time series is entirely determined
by the first Fourier coefficient. Indeed, this coefficient corresponds to a frequency of 0, and is thus
not multiplied by any sine or cosine function. For this reason, the first Fourier coefficient is set to
the value c0 = T2πU . The inverse Fourier transform is then applied on the series of randomly generated
Fourier coefficients to determine the series in the time domain:
−1
1 NX 2πlm 1
 
xm = 2πfs Xl exp i = 2πfs ifftR (X) = 2πfs ifftM (X) (3)
N l=0 N N

where ifftR and ifftM are the inverse Fourier transformation respectively in R and Matlab. Nevertheless,
this method will return time series of complex coefficients. Taking the real part will solve this issue,
or, one can use the second approach suggested below.

Second Approach The method above can be made more realistic by using complex numbers for
the Fourier coefficients, so that the time series is actually expressed in real numbers. For this matter
N/2 coefficients an and N/2 coefficients bn are generated to compose the Fourier coefficients vector
cn of length N as:
TU
(cn )0..N −1 = [ ; a1 + ib1 ; ... ; aN/2−1 + ibN/2−1 ; aN/2 + 0 ; aN/2−1 − ibN/2−1 ; ... ; a1 − ib1 ] (4)

The generation of the random numbers an and bn is such that the standard deviation is distributed
equally among the real and imaginary part(no systematic time lag):
1 2
σa2n = σb2n = σX (5)
2 n

Examples Four different 10 minutes samples at 10Hz generated from this method is displayed on
figure 2. Their mean is exactly U = 20 m/s, whereas their standard deviation varies between 0.90 and
1.23 m/s. The samples resemble quite well real wind time series.

3 Final verifications

It is expected that the spectrum calculated from the generated time series matches the Kaimal spec-
trum from which they were derived. For a 10 minutes sample, result are displayed on figure 3a. Good
agreement is found with the Kaimal spectrum, and with a higher number of points, the match is even
clearer (see figure 3b).

February 2010 2
3 FINAL VERIFICATIONS

23
22

22
21

21
Wind Speed [m/s]

Wind Speed [m/s]


20
20

19
19

18
18

17

00:00 02:00 04:00 06:00 08:00 10:00 00:00 02:00 04:00 06:00 08:00 10:00
Time [m:s] Time [m:s]

(a) (b)
23

22
22

21
Wind Speed [m/s]

Wind Speed [m/s]


21
20

20
19

19
18

18
17

00:00 02:00 04:00 06:00 08:00 10:00 00:00 02:00 04:00 06:00 08:00 10:00
Time [m:s] Time [m:s]

(c) (d)

Figure 2: Four examples of time series generated from the Kaimal spectrum. The samples seem to reproduce
realistic wind signals

February 2010 3
4 JONSWAP SPECTRUM

102

104
+ Binned spectrum + + Binned spectrum
Kaimal spectrum Kaimal spectrum
+ + +
101

+
Energy Density S [ m2 s−2 Hz−1 ]

Energy Density S [ m2 s−2 Hz−1 ]


+ + + + +
+ ++ +

102
+ + ++ +++ +
++ + + +++++ +
100

+ + +
+ + +++ ++
++
+ + ++ + +
+ ++++++ +
10−1

100
+ ++ ++
+ +++
+
++ +++++
+ + +++
10−2

+ +++ ++
+++ +++

10−2
+++
+ ++
+ +++ +++
10−3

++ +++
++ ++
+++ +++
++
+++ f
10' + 1' 1'' +++fN 24h 12h 1h 10' 1' 1'' +++N
−4

−4
+
10

10
−3 −2 −1 0 1 −5 −4 −3
10 10 10 10 10 10 10 10 10−2 10−1 100 101
Frequency f [Hz] Frequency f [Hz]

(a) (b)
Figure 3: Comparison between the time series spectrum and the Kaimal spectrum from which they were
generated. (a) 10 minutes sample of N = 6.103 points - (b) Sample of 2.105 points

Part II

Wave time series generation


4 JONSWAP spectrum

The JONSWAP spectrum is implemented following the guidance in the IEC 61400-3 standard[p. 82][4]:
" !2 #
f
−1
!−5  !−4  fp
exp −0.5 σ
f f
SJS (f ) = 0.3125 · Hs2 · TP · · exp −1.25 ·  · (1 − 0.287 log γ) · γ (6)
fp fp

Where the peak-shape parameter γ is assumed to be equal to 3.3, and σ = 0.07 for frequencies below
the peak frequency fp = 1/Tp and σ = 0.09 in the opposite case. The values for Tp , the wave peak
period and Hs , the significant wave height, are obtained from measurements. The statistical moments
from the spectra are defined as: Z inf
mi = SJS (f )f i df (7)
0
The spectral moment of order 0 is related with the standard deviation as:

σ 2 = m0 (8)

If the above parameters are not used, and a simpler JONSWAP formula is used, a scaling factor
can be derived to normalize the spectra. For a 50-year sea state spectra, the significant wave height
approximation Hs ≈ 4σ can be used. The normalization coefficient k (if required) is consequently:
Hs 2
4
k = R fcut (9)
0 SJS (f )df

In this report, 50 years extreme values obtained from measurements at a specific locations are
used: Hs,50 = 8.1m and Tp,50 = 12.70

February 2010 4
5 WAVE TIME SERIES GENERATION

5 Wave time series generation

The following decomposition is applied to simulate a wave elevation time series η(t) from a spectrum:
X
η(t) = ap cos (ωp t − kp x + p ) (10)
p
q
ap = 2Sη (fp )∆f (11)
p = rand(0, 2π) (12)

The amplitude of the Fourier Component derived from the JONSWAP spectrum are found in Figure 4.

WaveAmplitude
0.35
Wave Amplitude Spectrum sqrt(2 S df) [m]

0.3

0.25

0.2

0.15

0.1

0.05

0
0 0.1 0.2 0.3 0.4 0.5
Frequency (Hz)

Figure 4: Amplitude of Fourier component ap

If position different than x = 0 have to be used, then the dispersion relation

ω 2 = gk tanh(kh) (13)

is solved for each wave component as shown in Figure 5. Resulting time series are displayed in Figure 6.

1000

900

800

700
Wave length [m]

600

500

400

300

200

100

0
0 0.1 0.2 0.3 0.4 0.5
Frequency [s]

Figure 5: Dispersion Relation.

February 2010 5
CONCLUSION

4
Elevation [m]

−2

−4

−6

−8
0 500 1000 1500 2000 2500 3000 3500
Time t [s]

Figure 6: Example of simulated time series for Wave Elevation.

6 Final verification

The input spectra (JONSWAP) and the time series spectra are compared in Figure 7. The agreement
is complete showing that the procedure of generation of time series from the spectra is valid. As a
result of this the time series will satisfy the expected statistics.

20
FFT Time series
18 JONSWAP spectrum

16
Amplitude Spectrum of eta(t)

14

12

10

0
0 0.1 0.2 0.3 0.4 0.5
Frequency (Hz)

Figure 7: Spectrum Comparison.

Conclusion

In this short analysis, we have been introduced to the generation of time series from a spectrum,
which is a method commonly used in wind energy. One can use the Kaimal spectrum as in this
report, nevertheless, is has been previously seen, that a real wind sample does not follow the Kaimal
spectrum exactly. Thus this method will generate signals which are really close to real signals but
still not perfect. Real spectrum can also be used to generate time series. But of course, if a real wind
spectrum is available it means that time series are already available so the interest of the method
seem limited in this case. The generation of time series from a spectrum can be used while performing
statistics on extreme gusts for instance, and assessment of mean gust shapes[3][7]. Another application
could be generation of data when not enough measurements are available for assessments of 50 year
extremes, nevertheless, this method would be rather uncertain[1]. Eventually, a main application is for
aeroelastic code such as FLEX[8] that require different wind input to test the wind turbine response.

February 2010 6
CONCLUSION

For this matter the Kaimal spectrum is really useful as it is a function of a site-specific parameter u∗
as well as the height and the main wind speed.

References

[1] Po Wen Cheng. A reliability based methodology for extreme responses of offshore wind turbines.
DU Wind, Delft University wind Energy Research Institute, 2002.

[2] C Dyrbye and S. O. Hansen. Wind loads on structures. John Wiley & Sons, 1997.

[3] W. Bierbooms G.Cr. Larsen and K.S. Hansen. Mean Gust Shapes. Risø-R-1133(EN) - Risø National
Laboratory, Roskilde, Denmark, December 2003.

[4] IEC. IEC 61400-3 Wind turbines Part 3: Design requirements for offshore wind turbines. 2009.

[5] J. Mann. Wind profiles and turbulence spectra. Risø DTU - Course 45701, 2010.

[6] Nick Jenkins Tony Burton, David Sharpe and Ervin Bossanyi. Wind Energy Handbook. J. Wiley
& Sons, 2001.

[7] Po-Wen Cheng W. Bierbooms. Stochastic gust model for design calculation of wind turbines.
Journal of wind energineering and industrial aerodynamics, Vol.90 Pages 1237-1251, 2002.

[8] S. Øye. Fix Dynamisk, aeroelastisk beregning af vindmøllevinger. Report AFM83-08, Fluid Me-
chanics, DTU, 1983.

February 2010 7
APPENDIX

APPENDIX

February 2010 8
APPENDIX

A R code

A.1 Main Source code

1 ###########################################################
2 # Initialization
3 ###########################################################
4 s e t P l o t t i n g M e t h o d ( " pdf " )
5 setFigsPath ( " f i g s /" )
6 setwd ( " /media/Work/Wind R e s s o u r c e s and l o a d s / E x e r c i s e 4 / " )
7 source ( " code /MyWTlib . r " )
8 source ( " code /Spectrum . r " )
9 source ( " code /MyLegend . r " )
10 library ( s f s m i s c )
11
12 ###########################################################
13 # Numerical v a l u e s
14 ###########################################################
15 U=20 # a v e r a g e wind s p e e d
16 u f=1 # f r i c t i o n v e l o c i t y
17 z=70 # h e i g h t
18
19 ###########################################################
20 # Kaimal spectrum
21 ###########################################################
22 f s =10 #s a m p l i n g f r e q u e n c y i n Hz
23 N=6∗10^3 #l e n g t h o f t h e time s e r i e s
24 f <−( 1 : f l o o r (N/ 2 ) ) ∗ f s /N;
25 t=seq ( 0 , (N) / f s , 1 / f s )
26 T=N/ f s ;
27 n=f ∗z/U
28 S=u f ^2∗ ( 5 2 . 5 ∗z/U) /(1+33∗2∗ p i ∗z/U∗ f ) ^(5 / 3 )
29 S2=T/ ( 2 ∗ p i ) ∗ u f ^2∗ ( 5 2 . 5 ∗z/U) /(1+33∗2∗ p i ∗z/U∗ f ) ^(5 / 3 )
30
31 ###########################################################
32 # Samples g e n e r a t i o n
33 ###########################################################
34 x1=generateWSFromSpectrum2 ( S , N, f s ,U)
35 b e g i n P l o t ( " sample1 " , s h o w T i t l e=F) ;
36 plotWSSample ( f s=f s ,WS=x1 ) ;
37 e nd Pl o t ( )
38
39 ###########################################################
40 # c a l c u l a t i n g spectrum b a c k
41 ###########################################################
42 R1=getAveragedSpectrum ( t ( x1 ) , f s )
43 b e g i n P l o t ( " SpecBackShort " , s h o w T i t l e=F)
44 plot . l o g l o g (R1$fb , R1$Sb , type=" o " , col =4, pch="+" , xaxs=" i " , yaxs=" i " ,
45 x l a b=" Frequency f [ Hz ] " ,
46 y l a b=expression ( " Energy D e n s i t y S [ " ~m^2~ s^−2~Hz^−1~ " ] " ) )
47 plot . add( f , S , pch=" " , type=" o " , col =1)
48 axis . f r e q ( f s ) ;
49 legend ( " t o p r i g h t " , c ( " Binned spectrum " , " Kaimal spectrum " ) , col=c
( 1 , 4 ) , pch=c ( "+" , " " ) , l t y =1,bg=" w h i t e " , i n s e t =0.015 , cex =0.85)
50 e nd Pl o t ( )

February 2010 9
APPENDIX

A.2 Sample generation

1 ###########################################################
2 # F i r s t approach
3 ###########################################################
4 generateWSFromSpectrum=function ( S , N, f s ,U) {
5 T=N/ f s ;
6 X=numeric (N)
7 f o r ( l i n 1 : (N/ 2 ) ) {
8 X[ l ]=rnorm( 1 ,mean = 0 , sd = sqrt (T/ ( 2 ∗ p i ) ∗S [ l ] ) );
9 }
10 x= Re( ( f f t ( c (T∗U/ ( 2 ∗ p i ) ,X) , inverse=T) /N ) ) ∗2∗ p i ∗ f s
11 print ( c (mean( x ) , sd ( x ) )
12 return ( x )
13 }
14

15 ###########################################################
16 # Second approach
17 ###########################################################
18 generateWSFromSpectrum2=function ( S , N, f s ,U) {
19 T=N/ f s ;
20 I=complex ( r e a l =0, i m a g i n a r y =1)
21 a=numeric (N/ 2 )
22 b=numeric (N/ 2 )
23 f o r ( l i n 1 : (N/ 2 ) ) {
24 a [ l ]=rnorm( 1 ,mean = 0 , sd = sqrt (T/ ( 2 ∗ p i ) ∗S [ l ] ) /sqrt ( 2 ) ) ;
25 b [ l ]=rnorm( 1 ,mean = 0 , sd = sqrt (T/ ( 2 ∗ p i ) ∗S [ l ] ) /sqrt ( 2 ) ) ;
26 }
27 X=numeric (N)
28 X [ 2 : ( N/ 2 ) ]=( a+I∗b ) [ 1 : ( N/2−1) ] /2
29 X [ ( ( N/2+2) :N) ]=( a−I∗b ) [ ( N/2−1) : 1 ] /2
30 X[ 1 ] =T∗U/ ( 2 ∗ p i ) ;
31 X[N/2+1]=a [N/ 2 ]
32 x= Re( ( f f t (X, inverse=T) /N ) ) ∗2∗ p i ∗ f s
33 print (mean( x ) )
34 print ( sd ( x ) )
35 return ( x )
36 }

B Matlab code

B.1 Mains

1 InitClear
2
3 %% Wind spectrum
4 vt=linspace ( 0 , 3 6 0 0 , 3 6 0 1 )
5 % −−−−−−−−−−−−−−−−−−− Kaimal spectrum
6 [ vUw_Kaimal , fraw , Sraw , fKailman , SKailman , fBin , SBin , fWelch , SWelch ] =
fStocWind ( 2 ∗ vt ( end ) ) ;
7 vUw_Kaimal=vUw_Kaimal ( 1 : length ( vt ) ) ;
8

9
10 % −−−−−−−−− S t o c h a s t i c Times s e r i e s
11 figure , plot ( vt , vUw_Kaimal , ’ C o l o r ’ , [ 0 0 0 . 7 ] ) , box on , grid on , t i t l e ( ’ Wind
Time S e r i e s ’ ) , xlabel ( ’ t [ s ] ’ ) , ylabel ( ’ Wind s p e e d [m/ s ] ’ ) ;

February 2010 10
APPENDIX

12
13 % −−−−−−−−− S p e c t r a o f S t o c h a s t i c Times s e r i e s
14 figure ,
15 loglog ( fraw , Sraw , ’− ’ , ’ C o l o r ’ , [ 0 . 6 6 0 . 6 6 0 . 6 6 ] )
16 hold on , % s t u p i d m a t l a b
17 loglog ( fWelch , SWelch , ’− ’ , ’ C o l o r ’ , [ 0 . 3 5 0 . 3 5 0 . 3 5 ] )
18 loglog ( fKailman , SKailman , ’ k− ’ , ’ l i n e w i d t h ’ , 2 )
19 loglog ( fBin , SBin , ’ r− ’ )
20 t i t l e ( ’ GeneratedTimeSeriesKaimalSpectrum ’ )
21 xlabel ( ’ Frequency [ Hz ] ’ )
22 ylabel ( ’PSD o f Uw [m^2/ s ^2 s ] ’ )
23 grid on
24 l g=legend ( ’Raw spectrum ’ , ’ pWelch spectrum ’ , ’ Kaimal spectrum ’ , ’ Bin−a v e r a g e d
spectrum ’ ) ;
25 set ( l g , ’ l o c a t i o n ’ , ’ s o u t h w e s t ’ )

1 InitClear
2
3
4 dt =0.1 % s h o u l d be 1/ (2 d f )
5 vt =0: dt : 6 0 0 ;
6 %% wave s p e c t r a
7 % −−−−−−−−−−−−−−−−−−− Jonswap spectrum
8 Hs=6;
9 Tp=10;
10 SigmaApprox=Hs/ 4 ;
11

12 % Here f r e q u e n c i e s a r e p r e s c r i b e d i n d e p e n b d e n t l y o f time v e c t o r , I t ’ s b e s t
t o d e c l a r e time v e c t o r f i r s t and use a N y q u i s t cut−o f f
13 % I t ’ s l i k e l y t h a t t h e r e w i l l be p e r i o d i c i t y i t t h e time v e c t o r i s l o n g e r
14 df =0.005; % smallest frequency
15 fHighCut = 0 . 2 ;
16 [ v f_Jonswap , S_Jonswap ] = fJonswap ( Hs , Tp , df , fHighCut ) ; % r e t u r n s v e c t o s
o f wave f r e q u e n c i e s and a m p l i t u d e s
17 N = length ( v f_Jonswap ) ; % number o f component f o r t h e sum
t h a t w i l l be used t o compute e t a ( t ) s e e s l i d e s 02 page 10
18 v p h a s e s_Jonswap = rand ( 1 ,N) ∗2∗pi ; % random p h a s e s b e t w e e n [ 0 2∗ p i ]
19 vA_Jonswap = sqrt ( 2 ∗S_Jonswap∗ d f ) ; % scaled amplitudes according
t o Jonswap spectrum
20
21 % D i s p e r s i o n f o r a l l f r e q u e n c i e s ( o n l y u s e f u l i f x !=0)
22 [ vk ] = f g e t D i s p e r s i o n ( v f_Jonswap ( i p ) , h , g ) ;
23
24 % −−−−−−−−− S t o c h a s t i c Times s e r i e s
25 e t a=zeros ( 1 , length ( vt ) ) ;
26 f o r i t =1: length ( vt )
27 e t a_Jonswap ( i t ) = sum(vA_Jonswap . ∗cos ( ( 2 ∗pi∗ v f_Jonswap ) ∗ vt ( i t ) − vk∗x
+v p h a s e s_Jonswap ) ) ; % w a t e r e l e v a t i o n , summation o f waves
28 end
29 figure , plot ( vt , e t a_Jonswap , ’ C o l o r ’ , [ 0 0 0 . 7 ] ) , box on , grid on , t i t l e ( ’Wave
Time S e r i e s ’ ) , xlabel ( ’ t [ s ] ’ ) , ylabel ( ’ Water e l e v a t i o n [m] ’ ) ;
30 [ SBin_eta , f B i n_eta , Sraw_eta , fraw_e t a ] = fSpectrum ( vt , e t a_Jonswap , 0 ) ;
31
32 % −−−−−−−−− S p e c t r a o f S t o c h a s t i c Times s e r i e s
33 figure ,
34 Ikp=S_Jonswap >10^−5;
35 loglog ( fraw_eta , Sraw_eta , ’− ’ , ’ C o l o r ’ , [ 0 . 6 6 0 . 6 6 0 . 6 6 ] )
36 hold on , % s t u p i d m a t l a b
37 % l o g l o g ( fWelch , SWelch , ’ − ’ , ’ Color ’ , [ 0 . 3 5 0 . 3 5 0 . 3 5 ] )

February 2010 11
APPENDIX

38 loglog ( v f_Jonswap ( Ikp ) , S_Jonswap ( Ikp ) , ’ k ’ , ’ l i n e w i d t h ’ , 2 )


39 loglog ( f B i n_eta , SBin_eta , ’ r− ’ )
40 t i t l e ( ’ GeneratedTimeSeriesJonswapSpectrum ’ )
41 xlabel ( ’ Frequency [ Hz ] ’ )
42 ylabel ( ’PSD o f e t a [m^2 s ] ’ )
43 grid on
44 l g=legend ( ’Raw spectrum ’ , ’ Jonswap spectrum ’ , ’ Bin−a v e r a g e spectrum ’ ) ;
45 set ( l g , ’ l o c a t i o n ’ , ’ s o u t h w e s t ’ )% a x i s t i g h t
46
47
48
49
50
51 %% Jonswap f o r 50 y e a r s e a s t a t e
52 Hs = 8 . 1 ;
53 Tp= 1 2 . 7 0 ;
54 SigmaApprox=Hs/ 4 ;
55
56 nt =3601;
57 vt=linspace ( 0 , 3 6 0 0 , nt ) ; % time v e c t o r [ s ]
58 T = vt ( 2 )−vt ( 1 ) ; % Sample time
59 Fs = 1/T ; % Sampling f r e q u e n c y [ Hz}
60 d f=1/max( vt ) ; % smallest frequency
61 fHighCut=Fs/ 2 ; % Nyquist
62 [ v f_Jonswap , S_Jonswap ] = fJonswap ( Hs , Tp , df , fHighCut ) ;
63

64 % i n t e g r a t i o n o f t h e spectrum
65 Area=trapz ( v f_Jonswap , S_Jonswap ) ;
66 n o r m a l i z a t i o n_f a c t o r =(Hs/ 4 ) ^2/Area ;
67 S_Jonswap_=n o r m a l i z a t i o n_f a c t o r ∗S_Jonswap ;
68 Area_=trapz ( v f_Jonswap , S_Jonswap_) ;
69 figure (222)
70 plot ( v f_Jonswap , S_Jonswap , ’ k− ’ ) , hold a l l
71 plot ( v f_Jonswap , S_Jonswap_, ’ b . ’ )
72 grid on
73 xlim ( [ 0 0 . 3 ] )
74 legend ( ’ Function ’ , ’ Normalized ’ )
75 xlabel ( ’ F r e q u e n c i e s [ Hz ] ’ )
76 ylabel ( ’JONSWAP S p e c t r a l d e n s i t y S [ m2 . s ] ’ )
77
78
79 %% Summation o f v a r i o u s wave components u s i n g Jonswap spectrum
80 N = length ( v f_Jonswap ) ; % number o f component f o r t h e sum
t h a t w i l l be used t o compute e t a ( t ) s e e s l i d e s 02 page 10
81 v p h a s e s_Jonswap = rand ( 1 ,N) ∗2∗pi ; % random p h a s e s b e t w e e n [ 0 2∗ p i ]
82 vA_Jonswap = sqrt ( 2 ∗S_Jonswap∗ d f ) ; % scaled amplitudes according
t o Jonswap spectrum
83 % Dispersion for a l l frequencies
84 [ vk_Jonswap ] = f g e t D i s p e r s i o n ( v f_Jonswap , h , g ) ;
85 vf = v f_Jonswap ; % vector of frequencies
86 v p h a s e s = v p h a s e s_Jonswap ; % random p h a s e s b e t w e e n [ 0 2∗ p i ]
87 vA = vA_Jonswap ;
88 vk = vk_Jonswap ;
89 % param
90 nz =10;
91 [ e t a Ftot Mtot Fdrag F i n e r t i a vz S t o r e d_u S t o r e d_dudt dFtot dMtot dFdrag
d F i n e r t i a ]= f H y d r o C a l c F i n a l ( vt , q , vf , vk , vA , vphases , g , rhow , h , zBot , D,Cm,
CD, nz , bWheeler , b F l o a t i n g , bVzTo0 ) ;
92

February 2010 12
APPENDIX

93 %% V e r i f i c a t i o n o f s p e c t r a
94 % Fs = 1/T; % Sampling f r e q u e n c y [ Hz}
95 % d f =1/max( v t ) ; % smallest frequency
96 % fHighCut=Fs/ 2 ; % Nyquist ?
97 % Matlab method
98 nt=length ( vt ) ; % Length o f s i g n a l
99 NFFT = 2^nextpow2 ( nt ) ; % Next power o f 2 from l e n g t h o f y
100 Y = f f t ( eta ,NFFT) /nt ;
101 Ab=2∗abs (Y( 1 :NFFT/2+1) ) ; % S i n g l e s i d e d Amplitude spectrum
102 f b = Fs/2∗ linspace ( 0 , 1 ,NFFT/2+1) ;
103 psb=Ab. ^ 2 /2/ d f ;
104 % Areab=t r a p z ( f b , Sb ) ;
105 % Area=t r a p z ( f , S ) ;
106

107 % Double S i d e d −> t i m e s 2


108 fB2 = [ 1 : nt ] ∗df−d f ;
109 aB2=abs ( f f t ( e t a ) ) /nt ; % d o u b l e s i d e d a m p l i t u d e spectrum
110 psEtaBo2=aB2 . ^ 2 / d f ; psEta2 ( 1 ) =0;
111
112 figure , hold a l l
113 plot ( fb , psb )
114 plot ( fB3 , psEtaB2∗ 2 )
115 plot ( v f_Jonswap , S_Jonswap , ’ k ’ )
116 legend ( ’ Matlab ’ , ’PSD∗2 ’ , ’ Jonswap S ’ )
117 xlim ( [ 0 0 . 3 ] ) ;
118 ylabel ( ’PSD o f \ e t a [m^2/Hz ] ’ ) ,
119 xlabel ( ’ Hz ’ ) ;
120
121
122 %%
123 % P l o t s i n g l e −s i d e d a m p l i t u d e spectrum .
124 figure , grid on , hold a l l , box on
125 hold a l l
126 plot ( fb , Ab)
127 plot ( fB2 , aB2∗ 2 )
128 plot ( v f_Jonswap , vA_Jonswap , ’ k ’ , ’ LineWidth ’ , 2 )
129 xlim ( [ 0 0 . 5 ] )
130 ylabel ( ’ S i n g l e S i d e d Amplitude Spectrum o f e t a ( t ) − a ’ )
131 xlabel ( ’ Frequency ( Hz ) ’ )
132 legend ( ’ From Time s e r i e s ’ , ’ From JONSWAP spectrum ’ )
133 t i t l e ( ’ SpectrumComparison ’ )

B.2 Functions

1 function [ f , S , a ] = fJonswap ( Hs , Tp , df , fHighCut )


2 %Returns t h e Jonswap spectrum
3 %
4 % −−−−−−−−−− I n p u t s
5 % Hs : s i g n i f i c a n t wave h e i g h t
6 % Tp : peak p e r i o d
7 % df : frequency resolution
8 % fHightCut : Highest frequency
9 % −−−−−−−−−− Outputs
10 % f : frequencies
11 % S : spectrum
12 % a : s c a l e d a m p l i t u d e s f o r c o s i n e F o u r i e r S e r i e s o f t h e form a . ∗cos (
omega t + p h i )

February 2010 13
APPENDIX

13
14

15 f p=1/Tp ; % from p r e v i o u s q u e s t i o n
16
17 %% get gamma v a l u e a c c o r d i n g t o s t a n d a r d s
18
19 i f (Tp/sqrt ( Hs ) <=3.6)==1
20 gamm=5;
21 e l s e i f (Tp/sqrt ( Hs ) >=3.6)==1 && (Tp/sqrt ( Hs )<=5)==1
22 gamm=exp ( 5 . 7 5 − 1 . 1 5 ∗ (Tp/sqrt ( Hs ) ) ) ;
23 e l s e i f (Tp/sqrt ( Hs ) >3.6)==1
24 gamm=1;
25 else
26 disp ( ’ Something i s wrong with your i n p u t s , model not v a l i d ’ )
27 end
28
29 %% or , p r e s c r i b e i t
30 % gamm= 3. 3 ;
31
32

33 %% sigma
34 vFreq=d f : d f : fHighCut ;
35 f o r i F r e q =1: length ( vFreq )
36 f r e q=vFreq ( i F r e q ) ;
37 i f ( f r e q <=f p )==1
38 sigma = 0 . 0 7 ;
39 e l s e i f ( f r e q >f p )==1
40 sigma = 0 . 0 9 ;
41 end
42 S ( i F r e q ) =0.3125∗Hs^2∗Tp∗ ( ( f r e q / f p ) ^( −5) ) ∗exp( −1.25∗ ( f r e q / f p ) ^( −4) ) ∗
(1 −0.287∗log (gamm) ) ∗ (gamm) ^(exp( −0.5∗ ( ( ( f r e q / f p ) −1)∗ ( 1 /sigma ) ) ^2) ) ;
43 end
44
45 % outputs
46 f=vFreq ;
47 a= sqrt ( 2 ∗S∗ d f ) ; % s c a l e d a m p l i t u d e s a c c o r d i n g t o Jonswap spectrum

1 function [ Uw, fraw , Sraw , fKailman , SKailman , fBin , SBin , fWelch , SWelch ] =
fStocWind ( Tend )
2 % G e n e r a t e s a wind s p e e d time s e r i e s from Kaimal spectrum , t a k i n g as i n p u t
t h e l e n g t h o f t h e time s e r i e s
3 % This f u n c t i o n ne e ds some c l e a n u p
4
5 %% Get t h e o r e t i c a l Kaimal spectrum
6 % i n p u t s t o t h e spectrum
7 V10=8;
8 I =0.14;
9 l =340.2;
10
11 % Tmanu= 0 : 0 . 1 : 5 0 0
12 T=Tend ; % d u r a t i o n o f time s e r i e i n s e c
13 % d f =1/ d t ;
14 fHighCut= 1 0 ; % c u t o f f f r e q u e n c y i n Hz
15 d f=1/T ;
16 f = 0 : d f : fHighCut ; % f r e q . v e c t o r [ Hz ]
17
18 % k a i m a l spectrum
19 Sw = 4∗ I ^2∗V10∗ l . / (1+(6∗ f ∗ l ) /V10 ) . ^ ( 5 / 3 ) ;
20

February 2010 14
APPENDIX

21 %% Generate time s e r i e
22 % C r e a t e two random normal d i s t r i b u t e d v a r i a b l e s
23 N=T∗fHighCut +1;
24 a_m=0;
25 a_std =1;
26 a=a_m+a_std∗randn ( f l o o r (N/ 2 ) +1 ,1) ;
27
28 b_m=0;
29 b_std =1;
30 b=b_m+b_std∗randn ( f l o o r (N/ 2 ) +1 ,1) ;
31
32 % C r e a t e f i r s t p a r t o f t h e complex v e c t o r
33 x l h a l f 1 =a+b∗ j ;
34 x l h a l f 1 ( 1 ) =0;
35
36 f o r i =1:N/2
37 wj=2∗pi∗ f ( i ) / 2 ; % omega
38 S_Kaimal_j = 4∗ I ^2∗V10∗ l . / (1+(6∗wj∗ l ) /V10 ) . ^ ( 5 / 3 ) ; % t h e o r e t i c a l
spectrum S ( omega )
39 sigma_K_j=sqrt (T/ ( 2 ∗pi ) ∗S_Kaimal_j ) ;
40 x l h a l f 1 ( i )=x l h a l f 1 ( i ) ∗sigma_K_j ;
41 end
42
43 % C r e a t e second p a r t o f t h e complex v e c t o r
44 x l h a l f 2=flipud ( x l h a l f 1 ( 2 : end ) ) ;
45

46 % T o t a l complex v e c t o r
47 x l =[ x l h a l f 1 ; x l h a l f 2 ] ;
48
49 % Fourier inverse
50 Uw=i f f t ( x l ) ;
51

52 % Remove z e r o i m a g i n a i r y p a r t and n o r m a l i z e
53 Uw=sqrt ( 2 ) ∗pi∗fHighCut∗ r e a l (Uw) ;
54
55 %% P l o t spectrum and v e r i f y agreement
56 [ Sm, F1 ] = spectrum (Uw, fHighCut , 1 , 2 ∗pi∗fHighCut ) ;
57 % [ S_q26 , F1_q26 ] = spectrum_ewma( u , Fsu ,K, omegau ) ;
58 NN = length (Sm) ;
59 [ Smav , F1av]= spectrum_a v e r a g e (Sm( 2 :NN/ 2 ) , F1 ( 2 :NN/ 2 ) ) ;
60
61 A=trapz ( F1av , Smav ) ∗2∗pi∗ 2 ;
62 B=var (Uw) ;
63 C=mean(Uw) ;
64 v e r i f=A−B ; % c h e c k d i f f i n t e g r a t e w i t h v a r
65
66
67 % o t h e r method u s i n g p w e l c h
68 fN= length (Uw) / ( 2 ∗T) ; % f r e q u e n c y
69 nw = 1 6 ; % Number o f windows ( a d j u s t u n t i l n o i s e i s removed s u f f i c i e n t l y )
70 n f f t = round ( length (Uw) . /nw) ; % Choose window l e n g t h
71 [ p a l t , f a l t ] = pwelch (Uw, n f f t ) ; % Normalized r e s u l t s b a s e d on Welch ’ s
method
72 n f a c = fN . /pi ; f a l t = f a l t . ∗ n f a c ; p a l t = p a l t . / n f a c ; % De−n o r m a l i z e
results
73

74 % figure
75 % l o g l o g ( F1 ( 2 : f l o o r (NN/ 2) ) ,2 ∗ p i ∗2∗Sm( 2 : f l o o r (NN/ 2) ) , ’ − ’ , ’ Color ’ , [ 0 . 6 0 . 6
0 . 6 ] ) % used t o be y

February 2010 15
APPENDIX

76 % h o l d on
77 % l o g l o g ( f a l t , p a l t , ’ − ’ , ’ Color ’ , [ 0 . 2 5 0 . 2 5 0 . 2 5 ] ) % used t o be g
78 % l o g l o g ( f , Sw , ’ k − ’ , ’ l i n e w i d t h ’ , 2 ) % used t o be b
79 % l o g l o g ( F1av , 2 ∗ p i ∗2∗Smav , ’ − ’ , ’ l i n e w i d t h ’ , 1 . 5 , ’ Color ’ , f C o l r s ( 2 ) ) % used t o
be k
80 % t i t l e ( ’ GeneratedTimeSeriesKaimalSpectrum ’ )
81 % x l a b e l ( ’ Frequency [ Hz ] ’ )
82 % y l a b e l ( ’PSD’ )
83 % g r i d on
84 % l g=l e g e n d ( ’Raw spectrum ’ , ’ pWelch spectrum ’ , ’ Kaimal spectrum ’ , ’ Bin−
a v e r a g e d spectrum ’ ) ;
85 % s e t ( lg , ’ location ’ , ’ southwest ’ )
86 % % axis tight
87

88
89 %% P r e p a r i n g o u t p u t s
90 fraw=F1 ( 2 : f l o o r (NN/ 2 ) ) ;
91 Sraw=2∗pi∗2∗Sm( 2 : f l o o r (NN/ 2 ) ) ;
92 fKailman=f ;
93 SKailman=Sw ;
94 f B i n=F1av ;
95 SBin=2∗pi∗2∗Smav ;
96 fWelch=f a l t ;
97 SWelch=p a l t ;
98
99

100 end
101
102
103
104
105

106
107 function [ S , F1 ] = spectrum ( u , f s , K, omega )
108 n=f l o o r ( length ( u ) /K) ; % compute t h e s i z e o f t h e sample
109 j =1;
110 F1 = [ 0 : n−1]/n∗ f s ; % N y q u i s t f r e q u e n c y
111 %−−−−−−−−−−−S p l i t t i n g t h e time s e r i e s −−−−−−−−−−−−−−−−−−−−−
112 f o r i =1:K
113 x ( 1 : length ( u ( j : j+n−1) ) , i )=u ( j : j+n−1) ’ ;
114 j=j+n ;
115 end
116 %−−−−−−−−−−−−−−−−−c a l c u l a t i n g t h e spectrum−−−−−−−−−−−−−−−−−
117 f o r i =1: length ( x ( 1 , : ) )
118 X1 ( 1 : length ( x ( : , i ) ) , i ) =(abs ( ( f f t ( x ( : , i ) ) ’ ) ) . ^ 2 ) / ( omega∗length ( x ( : , 1 ) ) )
;
119 end
120 %−−−−−−−−−−−−−−− mean o f X1 −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
121 f o r i =2: length ( x ( : , 1 ) )
122 S ( i )=nanmean (X1( i , : ) ) ;
123 end
124 end
125
126
127
128 function [ S_average , f_a v e r a g e ]= spectrum_a v e r a g e ( S , F1 )
129 % Average n e i g h b o r i n g f r e q u e n c y b i n s .
130 % INPUTS : Power spectrum and N y q u i s t Frequency

February 2010 16
APPENDIX

131 % OUTPUTS: Power spectrum and N y q u i s t Frequency a f t e r a v e r a g i n g


neighboring
132 % frequency bins .
133
134
135 b i n s = 1 5 ; % t i p i c a l l y b e t w ee n 10 and 20
136 a = 10^(1 / b i n s ) ; % d i s t a n c e b e t w e e n n e i g h b o u r s
137 x_x=log10 ( F1 ( 2 ) ) ;
138 f o =10^( f l o o r ( x_x ) ) ; %d e t e c t i o n o f t h e l o w e s t bound o f t h e range
139 F_Lower = F1 ( 1 ) ;
140 F_Higher = a∗ f o ; % h i g h e r l i m i t o f t h e f i r s t b i n
141 j =0;
142 while (F_Lower<F1 ( length ( F1 ) ) )
143 f i =F1 ( ( F1>=F_Lower )&( F1<F_Higher ) ) ;
144 S i=S ( ( F1>=F_Lower )&( F1<F_Higher ) ) ;
145 i f ( ~isempty ( S i ) )
146
147 j=j +1;
148 S_a v e r a g e ( j )=mean( S i ) ;
149 f_a v e r a g e ( j )=mean( f i ) ;
150 end
151 F_Lower=F_Higher ;
152 F_Higher =a∗F_Lower ;
153 end
154
155 end

1 function [ vk]= f g e t D i s p e r s i o n ( vf , h , g )
2 % S o l v e s f o r t h e d i s p e r s i o n r e l a t i o n once and f o r a l l
3 % h : w a t e r d e p t h >0
4 % g : g r a v i t y 9.81
5
6 f o r i p =1: length ( v f ) % l o o p on f r e q u e n c i e s
7 i f h<100
8 [ vk ( i p ) ] = f k S o l v e ( v f ( i p ) , h , g ) ;
9 else
10 % Not s o l v i n g t h e d i s p e r s i o n r e l a t i o n s i n c e we a r e i n deep w a t e r
11 vOmega=2∗pi∗ v f ;
12 vk=vOmega . ^ 2 /g ;
13 end
14 end
15 end
16
17
18 function [ k ] = f k S o l v e ( f , h , g )
19 warning o f f
20
21 omega=2∗pi∗ f ;
22 eq=@( k ) −omega^2+g∗k . ∗tanh ( k∗h ) ;
23 % k=f s o l v e ( eq , ( omega ^2)/g ) ;
24 k=fzero ( eq , [ 0 1 0 0 ] ) ; % seems a b i t f a s t e r
25
26

27 warning on
28 end

1 function [ SBin , fBin , Sraw , fraw ] = fSpectrum ( t , q , bP lo t )


2 %r e t u r n s t h e spectrum o f a time s e r i e s
3 % This f u n c t i o n ne e ds a l o t o f c l e a n u p

February 2010 17
APPENDIX

4
5 i f t ( 1 ) ~=0
6 t=t−t ( 1 ) ;
7 end
8
9 N_s a m p l e s= length ( q ) ; % number o f s a m p l e s
10 dt= t ( end ) ; % time i n c r e m e n t o f 10 minutes (600 s e c o n d s )
11 Fs= N_s a m p l e s / ( dt ) ; % f r e q u e n c y y
12 % f o r t h e annual p a t t e r n
13 K=1; % s p l i t t i n g f a c t o r
14
15 omega=2∗pi∗Fs ;
16
17 [ S_,F_] = spectrum ( q , Fs , K, omega ) ;
18 NN = length ( S_) ;
19 % b i n n i n g t h e spectrum
20 [ S , f ]= spectrum_a v e r a g e ( S_( 2 : f l o o r (NN/ 2 ) ) ,F_( 2 : f l o o r (NN/ 2 ) ) ) ;
21
22
23 %%
24 i f b Pl ot==1
25 figure ( )
26 loglog (F_( 2 : f l o o r (NN/ 2 ) ) , 2 ∗pi∗2∗S_( 2 : f l o o r (NN/ 2 ) ) , ’− ’ , ’ C o l o r ’ , [ 0 . 6 6
0.66 0 . 6 6 ] )
27 hold on
28 loglog ( f , 2 ∗pi∗2∗S , ’ k− ’ , ’ l i n e w i d t h ’ , 2 )
29 xlabel ( ’ Frequency [ Hz ] ’ )
30 grid on
31 legend ( ’Raw PSD ’ , ’ Average PSD ’ )
32 end
33
34 % Outputs
35 SBin=2∗pi∗2∗S ;
36 f B i n=f ;
37 Sraw=2∗pi∗2∗S_( 2 : f l o o r (NN/ 2 ) ) ;
38 fraw=F_( 2 : f l o o r (NN/ 2 ) ) ;
39 end
40

41 %
42 % s i g=q ;
43 % figure ; subplot (2 ,1 ,1)
44 % plot ( t , sig , ’ r ’)
45 % % y l a b e l ( ’ \ e t a [m] ’ ) ; l e g e n d ( ’ \ e t a [m] ’ )
46 % xlabel ( ’ t [ s ] ’)
47 % % Fast F o u r i e r Transform
48 % dfFFT=1/ t ( end ) ;
49 % fFFT = [ 1 : l e n g t h ( t ) ] ∗dfFFT−dfFFT ;
50 % a=a b s ( f f t ( s i g ) ) / l e n g t h ( t ) ;
51 % p s S i g=a . ^ 2 /dfFFT ; p s S i g ( 1 ) =0;
52 % subplot (2 ,1 ,2) , hold a l l
53 % p l o t ( fFFT , p s S i g )
54 % p l o t (F_( 2 : f l o o r (NN/ 2) ) ,2 ∗ p i ∗2∗S_( 2 : f l o o r (NN/ 2) ) , ’m− ’)
55 % s e t ( gca , ’ xlim ’ , [ 0 0 . 3 ] )
56 % % y l a b e l ( ’PSD, \ e t a [m^2/Hz ] ’ ) ,
57 % % l e g e n d ( ’PSD, \ e t a [m^2/Hz ] ’ )
58 % x l a b e l ( ’ Hz ’ ) ;
59
60
61

February 2010 18
APPENDIX

62 function [ S , F1 ] = spectrum ( u , f s , K, omega )


63 n=f l o o r ( length ( u ) /K) ; % compute t h e s i z e o f t h e sample
64 j =1;
65 F1 = [ 0 : n−1]/n∗ f s ; % N y q u i s t f r e q u e n c y
66 %−−−−−−−−−−−S p l i t t i n g t h e time s e r i e s −−−−−−−−−−−−−−−−−−−−−
67 f o r i =1:K
68 x ( 1 : length ( u ( j : j+n−1) ) , i )=u ( j : j+n−1) ’ ;
69 j=j+n ;
70 end
71 %−−−−−−−−−−−−−−−−−c a l c u l a t i n g t h e spectrum−−−−−−−−−−−−−−−−−
72 f o r i =1: length ( x ( 1 , : ) )
73 X1 ( 1 : length ( x ( : , i ) ) , i ) =(abs ( ( f f t ( x ( : , i ) ) ’ ) ) . ^ 2 ) / ( omega∗length ( x ( : , 1 ) ) )
;
74 end
75 %−−−−−−−−−−−−−−− mean o f X1 −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
76 f o r i =2: length ( x ( : , 1 ) )
77 S ( i )=nanmean (X1( i , : ) ) ;
78 end
79 end
80

81
82
83 function [ S_average , f_a v e r a g e ]= spectrum_a v e r a g e ( S , F1 )
84 % Average n e i g h b o r i n g f r e q u e n c y b i n s .
85 % INPUTS : Power spectrum and N y q u i s t Frequency
86 % OUTPUTS: Power spectrum and N y q u i s t Frequency a f t e r a v e r a g i n g
neighboring
87 % frequency bins .
88
89
90 b i n s = 1 5 ; % t i p i c a l l y b e t w ee n 10 and 20
91 a = 10^(1 / b i n s ) ; % d i s t a n c e b e t w e e n n e i g h b o u r s
92 x_x=log10 ( F1 ( 2 ) ) ;
93 f o =10^( f l o o r ( x_x ) ) ; %d e t e c t i o n o f t h e l o w e s t bound o f t h e range
94 F_Lower = F1 ( 1 ) ;
95 F_Higher = a∗ f o ; % h i g h e r l i m i t o f t h e f i r s t b i n
96 j =0;
97 while (F_Lower<F1 ( length ( F1 ) ) )
98 f i =F1 ( ( F1>=F_Lower )&( F1<F_Higher ) ) ;
99 S i=S ( ( F1>=F_Lower )&( F1<F_Higher ) ) ;
100 i f ( ~isempty ( S i ) )
101
102 j=j +1;
103 S_a v e r a g e ( j )=mean( S i ) ;
104 f_a v e r a g e ( j )=mean( f i ) ;
105 end
106 F_Lower=F_Higher ;
107 F_Higher =a∗F_Lower ;
108 end
109

110 end

February 2010 19

Оценить