Clear Filters
Clear Filters

matlab does not plot the time series

2 views (last 30 days)
Hello everyone,
I am trying to generate velocity from JONSWAP spectrum.However, when the depth of is higher than 20 m, MATLAB does not plot anything
I did not succeed to figure out the problem. The code is the following:
x=0;
depth=50;
mean_wind_speed=11.5;
gamma_jonswap=3.3;
f_p=0.208;
Tp=1/f_p;
t=linspace(0,1000,5000);
fs=length(t)/t(end);
delta_f=fs/length(t); % frequency step
g=9.81; % gravity
f=linspace(1e-3,(fs-delta_f)/2,length(t));
fetch=40e+3;
alpha_p=0.076*(fetch*g/(mean_wind_speed)^2)^(-0.22);
k=(2*pi*f).^2/g; % wave number
sigma_jonswap=zeros(1,length(f));
for j=1:length(f)
if f(j)<=f_p
sigma_jonswap(j)=0.07;
else
sigma_jonswap(j)=0.09;
end
end
pm_spectrum= alpha_p*g^2*(2*pi)^(-4).*f.^(-5).*exp(-(5/4)*(f_p./f).^4);
jonswap_spectrum=pm_spectrum.*gamma_jonswap.^exp(-((f-f_p*ones(1,length(f))).^2)./((2*sigma_jonswap.^2).*((f_p*ones(1,length(f))).^2)));
a=sqrt(2*jonswap_spectrum*delta_f);
phi=2*pi*rand(1,length(a));
%% velocity from JONSWAP spectrum
velocity_jonswap=zeros(1,length(t));
for j=1:length(t)
velocity_jonswap(j)=sum(2*pi*f.*(cosh(k*(depth))./(Tp*sinh(k*depth))).*a.*sin(k*x-2*pi*f*t(j)+phi));
end
figure(1)
plot(t,velocity_jonswap)
xlabel('time(s)')
ylabel('velocity of the wave')
title('velocity of the wave generated using JONSWAP spectrum at z=0 and x=0')
grid on
Could anyone help ?
Best Regards

Accepted Answer

Star Strider
Star Strider on 22 Feb 2023
Moved: Walter Roberson on 22 Feb 2023
The problem is that ‘velocity_jonswap’ is uniformaly NaN. This is causec by a ‘0/0’ , ‘Inf/Inf’ or NaN values in the data used to calculate that variable (that are caused by the same sorts of divisions). You will need to search to find out where the problem is, and then correct it.
  3 Comments
Star Strider
Star Strider on 22 Feb 2023
My pleasure!
If my Answer helped you solve your problem, please Accept it!
Walter — Thank you!
.
Walter Roberson
Walter Roberson on 22 Feb 2023
I can allieviate the input-too-large problem by switching to symbolic work, as the cosh() and sinh() cancel each other out to reasonable degrees. However, the resulting code is pretty slow in calculating velocity_jonswap because it is using 5000 different frequencies (length(t) of them.)
It is not immediately obvious to me why the number of frequencies should be the same as the number of time points. If you had used half as many frequencies as time points then I might have said, "Oh, that's sort of fourier transform kind of thing, going up to the nyquist frequency."

Sign in to comment.

More Answers (0)

Categories

Find more on Programming 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!