how to plot time and frequency domain by using FFT from CSV file?

28 ビュー (過去 30 日間)
Shwe
Shwe 2024 年 4 月 10 日 19:47
回答済み: Star Strider 2024 年 4 月 10 日 21:00
Hi,
Hello,
I have a CSV file.How to plot time and frequency domain using Fast-Fourier Transform (FFT)?
I would be delighted to any help.

採用された回答

Star Strider
Star Strider 2024 年 4 月 10 日 21:00
Try this —
A = readmatrix('FILE060.CSV');
Asz = size(A)
Asz = 1x2
729 258
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
t = A(:,1);
s = A(:,2:end-1);
figure
plot(t, s)
grid
xlim([min(A(:,1)) max(A(:,1))])
xlabel('Time (Units)')
ylabel('Amplitude (Units)')
[FTs1, Fv] = FFT1(s,t);
figure
plot(Fv, abs(FTs1)*2)
grid
xlabel('Frequency (Units)')
ylabel('Magnitude (Units)')
xlim([0 0.1])
figure
tiledlayout(4,4)
for k = 1:16:size(FTs1,2)
nexttile
plot(Fv, abs(FTs1(:,k))*2)
grid
Ax = gca;
Ax.XMinorGrid = 'on';
Ax.YMinorGrid = 'on';
xlim([0 0.05])
title("Col "+k)
end
sgtitle('Fourier Transform Array (Subset)')
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
The complete set of 256 individual plots do not display well here, so I only plotted 16 of them individually. .
I created ‘FFT1’ for my own use, to make my life easier. Feel free to use it.
.

その他の回答 (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