FFT from CSV data file

63 visualizaciones (últimos 30 días)
Mathias Braun
Mathias Braun el 15 de Dic. de 2023
Comentada: William Rose el 20 de Dic. de 2023
Hello guys,
I have a .csv data from a distance laser. The laser measured an amplitude of a swinging modul for drilling and now I need to find out what the main frequency of the swinging is. The tool rotated with n=500 1/min and the sampling frequency was 20000 Hz. Could anyone help me how to find out what the frequency is?
Thank you for any solution.
Best regards
Mathias
  1 comentario
William Rose
William Rose el 15 de Dic. de 2023
Editada: William Rose el 15 de Dic. de 2023
@Mathias Braun, what have you tried so far?
[edit: correct typo in my comments]
First, you need to get your data into the Matlab workspace:
data=importdata('test_amplitude_50.2 (1).csv');
y=data.data;
How long is the vector of measurements?
N=length(y); disp(N)
120349
Now you know the length of the data.
You know the sampling rate. Let's call it fs:
fs=20000;
What will be the frequency vector associated with the fft?

Iniciar sesión para comentar.

Respuestas (3)

Star Strider
Star Strider el 18 de Dic. de 2023
This corroborates previous analyses.
What other information do you want from the data?
% S = fileread('test_amplitude_50.2 (1).csv')
T1 = readtable('test_amplitude_50.2 (1).csv', 'HeaderLines',2, 'VariableNamingRule','preserve');
VN = T1.Properties.VariableNames;
T1.('Protocol TimeStamp').Format = 'yyyy-MM-dd HH:mm:ss.SSSSSS'
T1 = 120349×2 table
Protocol TimeStamp Sensor1 Distance1 (scaled) __________________________ __________________________ 2023-11-30 15:53:30.146061 7.0187 2023-11-30 15:53:30.146111 7.0188 2023-11-30 15:53:30.146161 7.0188 2023-11-30 15:53:30.146211 7.0187 2023-11-30 15:53:30.146261 7.019 2023-11-30 15:53:30.146311 7.019 2023-11-30 15:53:30.146361 7.019 2023-11-30 15:53:30.146411 7.019 2023-11-30 15:53:30.146461 7.0191 2023-11-30 15:53:30.146511 7.0193 2023-11-30 15:53:30.146561 7.0194 2023-11-30 15:53:30.146611 7.0196 2023-11-30 15:53:30.146661 7.0194 2023-11-30 15:53:30.146711 7.0194 2023-11-30 15:53:30.146761 7.0194 2023-11-30 15:53:30.146811 7.0193
t = T1{:,1};
s = T1{:,2};
figure
plot(t, s)
grid
Fs = 1/mean(seconds(diff(T1{:,1})));
Fn = Fs/2;
L = numel(t);
L = 120349
NFFT = 2^nextpow2(L);
FTs = fft((s-mean(s)).*hann(L), NFFT)/L;
Fv = linspace(0, 1, NFFT/2+1)*Fn;
Iv = 1:numel(Fv);
[pks,locs] = findpeaks(abs(FTs(Iv))*2, 'MinPeakProminence',0.025);
figure
plot(Fv, abs(FTs(Iv))*2)
grid
xlim([0 100])
text(Fv(locs), pks, sprintf('\\leftarrow Magnitude = %.4f Scaled Distance Units\n Frequency = %.4f Hz\n Period = %.4f s', pks,Fv(locs),1/Fv(locs)), 'Vert','top')
.
  2 comentarios
Mathias Braun
Mathias Braun el 20 de Dic. de 2023
Thank you for this great answer :)
Star Strider
Star Strider el 20 de Dic. de 2023
My pleasure!

Iniciar sesión para comentar.


William Rose
William Rose el 17 de Dic. de 2023
data=importdata('test_amplitude_50.2 (1).csv');
y=data.data; % signal
N=length(y); % length of signal
fs=20000; % sampling rate (Hz)
f=fs*(0:N-1)/N; % vector of frequencies
Y=fft(y-mean(y)); % Y=Fourier transform of y
[~,ind]=max(abs(Y(1:round(N/2)))); % index of max value of Y in the lower half of the 2-sided spectrum
fmaxpow=f(ind);
fprintf('Frequency of max. power=%.1f Hz.\n',fmaxpow)
Frequency of max. power=13.0 Hz.
Plot the FFT and highlight the peak. I will plot the full FFT and I will zoom in on the frequencies of interest.
figure; subplot(211); semilogy(f,abs(Y),'-r',f(ind),abs(Y(ind)),'b*');
grid on; xlabel('Frequency (Hz)');
subplot(212); plot(f,abs(Y),'-r',f(ind),abs(Y(ind)),'b*');
grid on; xlabel('Frequency (Hz)'); xlim([0 50])
This is not the frequency I expected, based on your description ("500 cycles/minute", which equals 8.3 Hz). Therefore let us plot the original signal, to see the oscillation in the time domain. Plot one-second-long segments of y(t), at the start and the middle. Plot final 2 seconds.
t=(1:N)/fs;
figure; subplot(311), plot(t,y,'-r'); grid on; xlim([0 1]); xlabel('Time (s)');
subplot(312), plot(t,y,'-r'); grid on; xlim([(N/2)/fs, (N/2)/fs+1]); xlabel('Time (s)');
subplot(313), plot(t,y,'-r'); grid on; xlim([4 6.1]); xlabel('Time (s)');
The time domain plots confirm that the oscillation frequency is 13 Hz.
Good luck.
  2 comentarios
Mathias Braun
Mathias Braun el 20 de Dic. de 2023
Thank you too for your answer. This is all right because i wanted a Frequenz of 13 Hz. The Tool I'm using does 1,5 oscillation per rotation of 360°.
William Rose
William Rose el 20 de Dic. de 2023
@Mathias Braun, you are welcome.

Iniciar sesión para comentar.


Harald
Harald el 15 de Dic. de 2023
Hi Mathias,
after you have imported the signal using readmatrix, readtable, or readtimetable, you can calculate the fft of the amplitude. The documentation of fft has nice examples. You can then, in the easiest case, just look at the frequency with maximum power.
You may find some of the Onramps helpful: https://matlabacademy.mathworks.com/#getting-started, especially the Signal Processing Onramp.
Best wishes,
Harald

Etiquetas

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by