csv to fft matlab

2 visualizaciones (últimos 30 días)
tim
tim el 9 de Jun. de 2024
Comentada: Star Strider el 9 de Jun. de 2024
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

Respuestas (1)

Star Strider
Star Strider el 9 de Jun. de 2024
Editada: Star Strider el 9 de Jun. de 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}
ans = 10000x1
-0.0456 2.3588 3.1085 3.7611 4.6293 6.3481 7.5509 8.0792 8.1042 9.3831
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
T{2}
ans = 10000x1
0.0882 0.9211 1.4539 1.5864 1.8279 2.4375 2.7633 3.1545 3.7334 3.8463
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
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 comentarios
tim
tim el 9 de Jun. de 2024
Thanks a lot for your answers !!
Star Strider
Star Strider el 9 de Jun. de 2024
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

Iniciar sesión para comentar.

Categorías

Más información sobre Get Started with Signal Processing Toolbox en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by