Azzera filtri
Azzera filtri

How to convert Time domain to frequency domain?

14 visualizzazioni (ultimi 30 giorni)
Karthik Murugesh
Karthik Murugesh il 17 Giu 2022
Commentato: Walter Roberson il 6 Set 2024 alle 9:18
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 Commento
Karthik Murugesh
Karthik Murugesh il 17 Giu 2022
i tried that fft function but it didnt work out
by the way iam new to matlab i usualy use VS c++

Accedi per commentare.

Risposte (1)

arushi
arushi il 6 Set 2024 alle 7:03
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 Commento
Walter Roberson
Walter Roberson il 6 Set 2024 alle 9:18
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)

Accedi per commentare.

Categorie

Scopri di più su Fourier Analysis and Filtering in Help Center e File Exchange

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by