FFT function in matlab

2 次查看(过去 30 天)
siyu lin
siyu lin 2018-3-12
if true
% close all;clear all;clc
load('short_6washer')
t = data(:,1);
Amp = data(:,2);
Fs = 1/(t(2) - t(1)); % Sampling frequency
L = length(data(:,1)); % Length of signal
f = Fs*(0:(L/2))/L;
figure subplot(2,1,1) plot(t,Amp) xlabel('t (seconds)') ylabel('X(t) [V]') Y = abs(fft(Amp)); % f = (0:length(Y)-1)*10000/length(Y); P = 2*abs(Y(1:length(f)))/L; subplot(2,1,2) plot(f,P) axis([-5 15 0 6]) xlabel('f (Hz)') ylabel('amplitude [V]')% end
I am doing the FFT of the attached file in matlab. The image is what I got but it seems wrong to me. If it is wrong, can someone debug the code for me? The sample frequency is 10000Hz and the data was collected in 10 seconds.
  2 个评论
Joost Meulenbeld
Joost Meulenbeld 2018-3-12
编辑:Joost Meulenbeld 2018-3-12
With no attached code, it's hard to debug your code; what exactly seems wrong to you? How did you compute the real one-sided fourier spectrum?
siyu lin
siyu lin 2018-3-12
I have attached the code. Since the spike is not clear and hard to determine.

请先登录,再进行评论。

回答(1 个)

David Goodmanson
David Goodmanson 2018-3-12
编辑:David Goodmanson 2018-3-12
Hi siyu,
Things are actually working correctly, and the only real problem is that your wave is oscillating about the value 2.5. That means that there is a large DC component of that size. (It also means that if you are going to be doubling the size of Y array elements, you should not double the size of the first array element. That element corresponds to frequency = 0, i.e. DC. That peak was the correct size, 2.5, before it got doubled).
Assuming you are not particularly interested in the DC component, then you will get better results by taking it out, with
Y = abs(fft(Amp-mean(Amp)));

Community Treasure Hunt

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

Start Hunting!

Translated by