Converting xlsx files to frequency domains using the fft algorithm
3 views (last 30 days)
Show older comments
The above graph is a graph using Var1_Time and Hammer (input) data Var2_1 through Var2_5, the time data of the referenced file 120mm.xlsx.
>> plot(Var1_Time,Var2_1)
>> hold on
>> plot(Var1_Time,Var2_2)
>> plot(Var1_Time,Var2_3)
>> plot(Var1_Time,Var2_4)
>> plot(Var1_Time,Var2_5)
But I want to make a graph about Hammer (input) data by changing Var1_Time, which is time data, to frequency domain using the fft algorithm, but I don't know how. I'd really appreciate your help.
0 Comments
Accepted Answer
Star Strider
on 20 Mar 2024
Try this —
T1 = readtable('120mm.xlsx')
VN = T1.Properties.VariableNames([1 4:end]);
t = T1{:,1};
s = T1{:,4:end};
Ts = mean(diff(t))
Tsd = std(diff(t))
Fs = 1/Ts
[sr, tr] = resample(s, t, Fs);
[FTs1,Fv] = FFT1(sr,tr);
figure
plot(Fv, mag2db(abs(FTs1)*2))
grid
xlim([0 max(Fv)])
xlabel('Frequency')
ylabel('Magnitude (dB)')
legend(strrep(VN(2:end),'_','\_'), 'Location','NE', 'NumColumns',2)
idx = reshape([1:5; 6:10], [],1);
figure
tiledlayout(5,2)
for k = 1:size(FTs1,2)
nexttile
plot(Fv, mag2db(abs(FTs1(:,idx(k)))*2))
title(strrep(VN{idx(k)+1},'_','\_'))
grid
axis([0 max(Fv) -100 10])
end
function [FTs1,Fv] = FFT1(s,t)
t = t(:);
L = numel(t);
if size(s,2) == L
s = s.';
end
Fs = 1/mean(diff(t));
Fn = Fs/2;
NFFT = 2^nextpow2(L);
FTs = fft((s - mean(s)) .* hann(L).*ones(1,size(s,2)), NFFT)/sum(hann(L));
Fv = linspace(0, 1, NFFT/2+1)*Fn;
Iv = 1:numel(Fv);
FTs1 = FTs(Iv,:);
end
Your data are not regularly sampled, so it is necessary to use the resample function here to produce reliable results, since fft and nearly every other signal processing function require regularly-sampled data.
I created the ‘FFT1’ function for my convenience. Feel free to use it.
.
6 Comments
More Answers (0)
See Also
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!