matlab – Conversion of time domain resposne to frequency domain

I would like to convert time-domain wave elevation (sea waves) for irregular waves to the frequency domain to get Jonswap Spectrum. I got the time-domain response from open software by giving the appropriate parameters. After using FFT commands and smoothening function in MATLAB I got the spectrum which is attached below. I should be getting a very smooth curve instead of fluctuations in the plot. I’ll be grateful if you could let me know the mistake or missing things in my code attached below.

Obtained wave spectrum

clear;
clc;
Wave1= xlsread('WaveElev_Time_LC1.xlsx');
Wave=Wave1(:,2);
figure();
plot(Wave1(:,1),Wave);
title("Wave elevation in Time Domain");
xlabel('Time(s)','linewidth',3);
ylabel('Wave Elevation(m)','linewidth',3);
xlim([0 3600]);

Ns=length(Wave);
fs=1/0.0125;

fft_Wave=fft(Wave);
fft_Wave = fft_Wave(1:Ns/2+1);


psdx = (1/(fs*Ns)) * abs(fft_Wave).^2;
psdx(2:end-1) = 2*psdx(2:end-1);
freq = 0:fs/Ns:fs/2;

y = smooth(freq, psdx);
figure();
plot(freq,y,'linewidth',2);

Read more here: Source link