Converting xlsx files to frequency domains using the fft algorithm

3 ビュー (過去 30 日間)
호태 강
호태 강 2024 年 3 月 20 日
コメント済み: Star Strider 2024 年 3 月 20 日
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.

採用された回答

Star Strider
Star Strider 2024 年 3 月 20 日
Try this —
T1 = readtable('120mm.xlsx')
T1 = 10240×13 table
Var1_Time Dev3_ai0 Dev3_ai1 Var2_1 Var2_2 Var2_3 Var2_4 Var2_5 Var3_1 Var3_2 Var3_3 Var3_4 Var3_5 __________ __________ __________ __________ __________ __________ __________ __________ __________ ___________ _________ _________ __________ 0 -0.078707 0.052439 -0.043113 -0.015541 0.033087 0.015541 -0.078707 0.0090577 0.022406 0.036231 0.016685 0.052439 0.00097656 -0.074696 -0.038138 -0.0035092 -0.012032 0.01905 0.023061 -0.074696 0.068171 -0.00095344 0.016685 0.031464 -0.038138 0.0019531 0.069182 0.050056 -0.038602 -0.087229 -0.0095251 -0.01905 0.069182 0.030033 0.028126 0.024789 -0.041951 0.050056 0.0029297 0.066174 0.14254 0.037599 -0.076702 -0.054644 0.011029 0.066174 0.0553 -0.0042905 0.0066741 -0.012395 0.14254 0.0039062 -0.036095 0.036231 -0.030079 -0.014538 0.037098 -0.052137 -0.036095 0.082473 0.018115 0.03194 -0.03051 0.036231 0.0048828 -0.030079 0.024313 0.0035092 0.027573 -0.013034 0.00050132 -0.030079 0.036231 0.038138 0.054823 -0.023836 0.024313 0.0058594 0.014538 0.030033 -0.030079 -0.051135 -0.0070185 -0.066174 0.014538 0.054346 0.018115 -0.013348 -0.017162 0.030033 0.0068359 0.0095251 0.017162 -0.01153 0.015541 -0.04562 -0.051135 0.0095251 -0.022883 0.040044 -0.02765 -0.054823 0.017162 0.0078125 0.016544 0.023836 -0.01153 0.012032 -0.0085224 0.037098 0.016544 0.057206 0.057206 -0.011441 0.048149 0.023836 0.0087891 -0.052137 -0.008581 -0.048628 -0.041108 -0.09124 0.015541 -0.052137 0.035277 0.013348 -0.06245 0.014778 -0.008581 0.0097656 0.0020053 -0.0057206 0.0035092 -0.048628 -0.023061 0.0080211 0.0020053 0.080566 -0.0023836 -0.03194 0.078659 -0.0057206 0.010742 -0.0035092 0.051009 0 0.089736 -0.026069 0.0030079 -0.0035092 0.064834 0.0028603 -0.065311 0.055776 0.051009 0.011719 0.014538 0.044335 0.0381 0.0050132 0.041609 0.055145 0.014538 0.067218 -0.02765 0.051486 0.043382 0.044335 0.012695 0.0090237 0.031464 -0.05314 0.0025066 -0.0040105 0.028074 0.0090237 -0.0014302 -0.00095344 -0.016685 0.051009 0.031464 0.013672 -0.012032 0 -0.046623 -0.0040105 -0.025567 -0.050132 -0.012032 0.010488 -0.018115 -0.022883 0.053869 0 0.014648 -0.001504 -0.046719 -0.015541 0.016544 0.021055 -0.047124 -0.001504 0.0052439 0.029557 0.023359 0.074845 -0.046719
VN = T1.Properties.VariableNames([1 4:end]);
t = T1{:,1};
s = T1{:,4:end};
Ts = mean(diff(t))
Ts = 9.7656e-04
Tsd = std(diff(t))
Tsd = 4.0216e-05
Fs = 1/Ts
Fs = 1.0240e+03
[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 件のコメント
호태 강
호태 강 2024 年 3 月 20 日
Thanks!!! I really appreciate
Star Strider
Star Strider 2024 年 3 月 20 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFourier Analysis and Filtering についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by