csv to fft matlab
Afficher commentaires plus anciens
Hello everybody,
I'm trying to convert two csv files to fft and I looked on different forums and tried a few solutions but nothing conclusive.
Someone could help me please.
Thanks
Réponses (1)
Star Strider
le 9 Juin 2024
Modifié(e) : Star Strider
le 9 Juin 2024
You cannot calculate the Fourier transfomors without a corresponding sampling frequency or time vector.
Assuming the sampling frequency is 1 kHz, try this —
files = dir('*.csv');
Fs = 1E+3;
for k = 1:numel(files)
fn = files(k).name;
T{k} = readmatrix(fn);
t{k} = linspace(0, size(T{k},1)-1, size(T{k},1)).'/Fs;
[FTs1{k},Fv{k}] = FFT1(T{k},t{k});
figure
plot(t{k}, T{k})
xlabel('Time')
ylabel('Amplitude')
title(fn)
figure
plot(Fv{k}, abs(FTs1{k})*2)
grid
xlabel('Frequency')
ylabel('Magnitude')
title(fn)
Ax = gca;
Ax.XScale = 'log';
end
T{1}
T{2}
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 = Fs*(0:(NFFT/2))/NFFT;
% Fv = linspace(0, 1, NFFT/2+1)*Fn;
Iv = 1:numel(Fv);
FTs1 = FTs(Iv,:);
end
EDIT — Added time-domain plots.
.
2 commentaires
tim
le 9 Juin 2024
Star Strider
le 9 Juin 2024
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.
Catégories
En savoir plus sur Get Started with Signal Processing Toolbox dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



