FFT from time domain in excel

I am trying to get Frequency domain results from my Time domain analysis data regarding a floating offshore wind turbine responses.
I have learnt that I can use FFT in Matlab to perform this action. Can anybody suggest me how to do FFT and plots with excel file which has over 50000 lines of data?
I have attached one of the xlsx files that I need to FFT. Thank you.

 Accepted Answer

There is not much to see in the plot:
D1 = readmatrix('PlatformHeave.xlsx');
t = D1(:,1); % Time Vector
Fs = 1/mean(diff(t)); % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
y = D1(:,2:end); % Signal Matrix
ym = y - mean(y); % Subtract Column Means From All Columns (Eliminates D-C Offset Effect)
L = numel(t); % Signal Lengths
FTy = fft(y)/L; % Fourier Transform (Scaled For Length)
Fv = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector
Iv = 1:numel(Fv); % Index Vector
sep = ones(numel(Fv),1) * (1:size(FTy,2)); % 'Separation Matrix' — Plots Each Record In Its Column Locatioln
Fm = ones(numel(size(FTy,2)),1) * Fv; % Frequency Matrix
figure
plot3(Fm, sep, abs(FTy(Iv,:))*2)
grid on
xlabel('Frequency (Hz)')
ylabel('Record (Column #)')
zlabel('Amplitude')
set(gca, 'ZScale','log')
.

4 Comments

Hello,
Thank you so much for your reply. The responses between 0 to 1Hz is very important for this kind of results. That is why for 40Hz curve, it looks simple.
And also I need to refine my parameters and run more simulation. Hopefully the curve will look better.
Can I also ask you one more question? What is the main difference between Power Spectral Density(PSD) and FFT for matlab? Can I add more script lines to your above code and get PSD curves?
I appreciate your time and answers.
As always, my pleasure!
To more easily see the spectrum between 0 Hz and 1 Hz, add this line after the plot3 call:
xlim([0 1])
The normal Fourier transform depicts amplitude as a function of frequency. Power is amplitude squared, and that is the essence of the PSD, and there are many ways to calculate it to get robust results. See for example: Power Spectral Density Estimates Using FFT as well as Measure Power of Deterministic Periodic Signals and functions such as pwelch. Explore the documentation for other examples and functions.
Hello Sir,
Thank you for your reply on PSD info. Let's say I want to produce both FFT and PSD plots from using the same excel file. Can I extend the code you wrote with more PSD scripts;
psdx = (1/(Fs*N)) * abs(xdft).^2;
psdx(2:end-1) = 2*psdx(2:end-1);
freq = 0:Fs/length(x):Fs/2;
and use subplot to produce multiple plots?
Can you suggest me about PSD scripts for my case?
Have a good day.
Regards,
Arkar
As always, my pleasure!
There are several ways to compute the PSD. I generally use pwelch and leave the details to the function. That is compatible with the code I already wrote for the Fourier transforms and the plots, including the subplots. You would need to change the code slightly to plot the pwekch PSD estimates, since ‘Fv’ and ‘Iv’ are not necessary with it.
To use the subplot function (with the Fourier transforms), I would do something like this:
figure
splim = size(FTy,2);
for k = 1:splim
subplot(splim,1,k)
loglog(Fv, abs(FTy(Iv,k)))
grid
xlim([0 1])
end
The loglog plot is the best way to see the details. I used xlim here to restrict the frequency axis.
The code to plot the pwelch PSD estimates would be similar. Make appropriate changes to get the result you want.
:

Sign in to comment.

More Answers (0)

Products

Release

R2019b

Tags

Community Treasure Hunt

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

Start Hunting!