how to create FFT diagramm from acceleration measurements? (using xlsread)

1 次查看(过去 30 天)
I took some measurements of acceleration with its respective time. How can i create the FFT diagram now using "xls read"? I read the instructions of matlab but i got confused. Can anyone post me the code that i have to use? Here,i also post my measurements.
Also, i need to know the title of each axe (so i can know the unit) and by giving me the code, i can understand how and where the "fft" command is used. thank you.

回答(1 个)

Ced
Ced 2016-4-6
编辑:Ced 2016-4-6
xlsread reads a file, it has nothing to do with your diagram.
Since you have a csv file, why not use csvread?
All I see from your data file are positions.... but let's say you want the second column (without the header row), then it's
xx = csvread('lol.csv',1,1);
Now that you have the data, you can compute the fft, and then use plot to display the results. You can then name the axes using xlabel and ylabel.
There are also some inbuilt functions to plot spectra though, like periodogram and spectrum. You will need the respective toolboxes though ( System Identification for spectrum, Signal processing for periodogram ).
PS: Note that unlike the usual matlab convention, csvread is zero-indexed
  2 个评论
tupac1971ful
tupac1971ful 2016-4-7
from my data i have acceleration with each respective time. what i wanted to ask wasn't how to read my data but what command should i use to create FFT using all of my data from acceleration and time. Then plotting FFT should come easy
Ced
Ced 2016-4-8
编辑:Ced 2016-4-8
Ah, my bad. There is a function called fft. The only information you will need from your time data is the sampling frequency.
By default, fft returns a two-sided frequency spectrum. There is an example in the fft doc on how to extract the one-sided spectrum and plot it. It also shows you how to get the correct frequency axis.
I usually do something like this:
N = length(signal); % length of signal
fs = 1000; % <-- Plug in your sampling frequency here in [Hz]
df = fs/N; % frequency resolution
fn = fs/2; % nyquist frequency
% frequency vector (only half)
if mod(N,2) == 0
frequencies = linspace(0,fn,N/2+1);
else
frequencies = linspace(0,fn,(N+1)/2);
end
% compute fft (matlab fft returns ceil((N+1)/2) unique values)
Y = fft(signal);
% extract magnitude and only take half (fft is mirrored)
if ( mod(N,2) == 0 )
Ymag = abs(Y/N);
Ymag = Ymag(1:N/2+1);
Ymag(2:end-1) = 2*Ymag(2:end-1); % double magnitudes except c0
Yphase = unwrap(angle(Y(1:N/2+1)));
else
Ymag = abs(Y/N);
Ymag = Ymag(1:(N+1)/2);
Ymag(2:end-1) = 2*Ymag(2:end-1); % double magnitudes except c0
Yphase = unwrap(angle(Y(1:(N+1)/2)));
end
% Plot
figure
subplot(2,1,1)
plot(frequencies,Ymag)
set(gca,'XScale','log')
xlabel('frequency [Hz]')
ylabel('magnitude')
grid on
subplot(2,1,2)
plot(frequencies,Yphase)
set(gca,'XScale','log')
xlabel('frequency [Hz]')
ylabel('phase [rad]')
grid on
Note that the frequencies are in Hz and not rad/s. The if/else statements are just to handle even/odd signal lengths.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Fourier Analysis and Filtering 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by