Effacer les filtres
Effacer les filtres

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

11 vues (au cours des 30 derniers jours)
Shwe
Shwe le 10 Avr 2024
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.

Réponse acceptée

Star Strider
Star Strider le 10 Avr 2024
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.
.

Plus de réponses (0)

Catégories

En savoir plus sur Fourier Analysis and Filtering dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by