Converting xlsx files to frequency domains using the fft algorithm
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시

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.
채택된 답변
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
Wow, thank you so much. I'll bring you as a big brother. However, I need to divide the Var2_1~Var2_5 and Var3_1~Var3_5 graphs in order to organize the experimental data, so can I get one more help?
As always, my pleasure!
I will be happy to help you, however I am not certain what you want. What do you intend by ‘... I need to divide the Var2_1~Var2_5 and Var3_1~Var3_5 graphs in order to organize the experimental data ...’? How do you want to divide them?
Perhaps 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 = fix(1/Ts)
Fs = 1024
[sr, tr] = resample(s, t, Fs);
[FTs1,Fv] = FFT1(sr,tr);
figure
tiledlayout(5,1)
for k = 1:5
nexttile
plot(Fv, mag2db(abs(FTs1(:,k))*2))
title(strrep(VN{k+1},'_','\_'))
grid
axis([0 max(Fv) -100 10])
end

figure
tiledlayout(5,1)
for k = 1:5
nexttile
plot(Fv, mag2db(abs(FTs1(:,k+5))*2))
title(strrep(VN{k+6},'_','\_'))
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
.
Thanks for help, But what i want is your 1st graph(Frequency-Magnitude graph including Var2_1~Var3_5) i need 2 Frequency-Magnitude graph. One is Var2_1~2_5. Other is 3_1~3_5. Again, thanks for help
As always, my pleasure!
O.K.
Try this —
T1 = readtable('120mm.xlsx');
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(:,1:5))*2))
grid
xlim([0 max(Fv)])
xlabel('Frequency')
ylabel('Magnitude (dB)')
legend(strrep(VN(2:6),'_','\_'), 'Location','best')

figure
plot(Fv, mag2db(abs(FTs1(:,6:end))*2))
grid
xlim([0 max(Fv)])
xlabel('Frequency')
ylabel('Magnitude (dB)')
legend(strrep(VN(7:end),'_','\_'), 'Location','best')

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
.
Thanks!!! I really appreciate
As always, my pleasure!
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Vibration Analysis에 대해 자세히 알아보기
태그
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
