I made irregular wave consisting of 16 regular waves with random phase difference. In addition, I tried to divide the irregular wave to several waves which are forms of fourier series. So I made the code below line 11. But when I ran this code, I couldn't get the result even after 20 minutes. Taking a long time to get the result also worries me, but the bigger problem is that I'm not sure whether the result is correct or not. How can I convert 'irregular wave' to 'fourier series'?
function regular
t = (0 : 0.01 : 300); %% time
w = (0.25:0.05:1); %% wave frequency
A = [0 0.14 0.45 0.8 0.95 0.95 0.88 0.77 0.67 0.6 0.53 0.45 0.4 0.36 0.32 0.28]; %% wave amplitude
phase1 = 2*pi*rand(1,length(w)); %% phase difference
for ii = 1:length(w)
for jj = 1:length(t)
elev(ii,jj) = (A(ii)*cos(-w(ii)*t(jj)+phase1(ii))); %% wave elevation
end
end
syms t
T0 = 125;
w0 = 2*pi/T0;
a0 = (2/T0)*int(sum(elev),t,-T0/2,T0/2);
for k = 1:5
a(k)=(2/T0)*int(sum(elev)*cos(k*w0*t),t,-T0/2,T0/2);
b(k)=(2/T0)*int(sum(elev)*sin(k*w0*t),t,-T0/2,T0/2);
F1(k) = a(k)*cos(k*w0*t)+b(k)*sin(k*w0*t);
end
figure;
plot(t,a0/2+sum(F1));
end