How to convert Time domain to frequency domain?

16 Ansichten (letzte 30 Tage)
Karthik Murugesh
Karthik Murugesh am 17 Jun. 2022
Kommentiert: Walter Roberson am 6 Sep. 2024
i have attached my torque data obtained from robot simulation program for all the joints.
Data need to be analyised in frequency domain, but presently it is in the time domain. It would be great if someone send me the code that actual works to convert the attached file.
I have also tried many online mat lab code which didnt work as i required.
other spec:
Sampling time - 20hz=0.05
data sets - 300
  1 Kommentar
Karthik Murugesh
Karthik Murugesh am 17 Jun. 2022
i tried that fft function but it didnt work out
by the way iam new to matlab i usualy use VS c++

Melden Sie sich an, um zu kommentieren.

Antworten (1)

arushi
arushi am 6 Sep. 2024
Based on my understanding, you have time domain data in an Excel sheet and you would like to convert it to the frequency domain. However, the Excel file contains NaN values, which can cause issues when using the “fft” function. To resolve this, it is necessary to remove the NaN values from the data before applying the fft function.
Here is the code to remove NANs and convert data to frequency domain using fft function.
file = CF_0.1 - Copy.xls;
% Read the data from the Excel file
data = readmatrix(file); % For MATLAB R2019b or later
matrix = data;
matrixWithoutNaNs = matrix;
matrixWithoutNaNs(isnan(matrixWithoutNaNs)) = 0;
% Display the matrix without NaNs
disp(matrixWithoutNaNs);
% using fft function
torque_fft = fft(matrixWithoutNaNs);
N = length(matrixWithoutNaNs);
fs = 20; % Sampling rate in Hz
f = (-N/2:N/2-1)*(fs/N);
% Plotting
magnitude_spectrum = abs(fftshift(torque_fft));
plot(f, magnitude_spectrum);
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('Magnitude Spectrum');
Please find the links of documentation to “isnan”, “fft” and “fftshift” functions.
  1 Kommentar
Walter Roberson
Walter Roberson am 6 Sep. 2024
zeroing the NaN is probably the wrong thing to do. You want to skip the nan, not treat it as zero.
file = CF_0.1 - Copy.xls;
% Read the data from the Excel file
data = readmatrix(file); % For MATLAB R2019b or later
Fs = 20;
n = length(data);
t = (0:n-1)/Fs;
mask = isfinite(data);
matrixWithoutNaNs = data(mask);
t_withoutNaNs = t(mask);
f = (0:n-1)/n*Fs;
F = nufft(matrixWithoutNaNs, t_withoutNaNs, f);
magnitude_spectrum = abs(F);
plot(f, magnitude_spectrum)

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Fourier Analysis and Filtering finden Sie in Help Center und File Exchange

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by