How to aplly a function to all columns?

3 Ansichten (letzte 30 Tage)
Gabriel Aguirre
Gabriel Aguirre am 22 Jan. 2023
Beantwortet: dpb am 22 Jan. 2023
Hi guys, i have a code which do fft, however are so many columns to apply this code i need a way to do it faster, i already see something about cellfun, but this did't work. my data comes from vibration, I have a column of time and the rest of vibration data.
the following function makes the fft, psd now i want to apply to all columns of an excel table (csv).
function [freq_ax,fft_ax, psd_ax] = my_fft(t,ax)
%% computando fft
dt = mean(diff(t));
n = length(t);
L = 1:floor(n/2);
freq = 1/(dt*n)*(0:n-1);
fhat = (fft(ax,n)*1/(n-1));
fft_ax = abs(fhat(L));
freq_ax = (freq(L));
psd = fhat.*conj(fhat);
psd_ax = psd(L);
end

Antworten (1)

dpb
dpb am 22 Jan. 2023
See fft -- in particular, note the first comment...
"fft(X) is the discrete Fourier transform (DFT) of vector X. For matrices, the fft operation is applied to each column."
Hence, you get the operations applied to all columns for free; just pass the vibration data array (without augmenting it with the time which is of no import for the FFT, all you need is the sample rate) to FFT and operate by column for the rest. You'll get N PSDs; one per column.

Kategorien

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

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by