csv to fft matlab
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
Star Strider
2024-6-9
编辑:Star Strider
2024-6-9
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with Signal Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



