This is my code to generate random time series and to plot it. I want my code to do the same operations n times and then average Yn arrays of different repetitions and give me Yaverage array. I cant figure it out. .

2 views (last 30 days)
close all;
numofrep=input('number of repetitions:');
dw=0.02; %Frequency resolution
w=dw:dw:10; %Frequencies
Hs=1; %Significant wave height
Tp=6; %Peak period
wp=6.28/Tp; %Peak frequency
S=w; %Initialise vector to hold Energy Spectrum
H=w; %Initialise vector to hold Amplitude spectrum
for i =1:length(w)
S(i)=5/16*wp^4/w(i)^5*Hs^2*exp(-1.25*(wp/w(i))^4); %Pierson-Moskowitz Energy Spectrum
H(i)=sqrt(2*S(i)*dw); %Calculate amplitude spectrum from energy spectrum
end
t=0:0.01:200; %Create time vector
Y=t*0; %Initialise Wave height vector
for i =1:length(w)
Y=+H(i)*sin(w(i)*t+rand()*6.28); %Create Wave height time series from amplitude spectrum
end
figure, plot(t,Y);

Answers (0)

Categories

Find more on Fourier Analysis and Filtering in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!