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.
0 个评论
回答(1 个)
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 个评论
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 Center 和 File Exchange 中查找有关 Fourier Analysis and Filtering 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!