how to plot time and frequency domain by using FFT from CSV file?
20 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
Star Strider
on 10 Apr 2024
Try this —
A = readmatrix('FILE060.CSV');
Asz = size(A)
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 Comments
More Answers (0)
See Also
Categories
Find more on Spectral Measurements 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!