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

28 views (last 30 days)
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.

Accepted Answer

Star Strider
Star Strider on 10 Apr 2024 at 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.
.

More Answers (0)

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!