问题描述
在阅读了许多研究和针对该主题的著作之后,在将FFT应用于加速度计数据时,我仍然遇到问题.我的大部分代码来自官方的MATLAB示例:一维FFT .经过更多阅读后,我发现了以下问题: FFT和加速度计数据:为什么我会得到此输出?哪里有使用开窗的建议.因此,在进行更多阅读之后,我在代码中添加了汉明窗.
After reading a lot of research and works on subject I still have got problems applying FFT to my accelerometer data. Most of my code is taken from official MATLAB example: FFT for one dimension. After more reading I've found this question: FFT and accelerometer data: why am I getting this output? where there was suggestion to use windowing. So after some more reading I've added hamming window to my code.
我的数据如下图所示:
My data looks like that on plot:
这是我用于FFT的代码:
And this is the code that I am using for FFT:
fs = 1/0.02; %0.02 comes from picking sample each 20ms
m = size(data,1);
w = hanning(m);
yw = w.*data;
n = pow2(nextpow2(yw));
y = fft(yw,size(n,1));
f = (0:size(n,1)-1)*(fs/size(n,1));
power = y.*conj(y)/size(n,1);
figure
plot(f,power)
问题是我从这段代码中得出的情节看起来像这样:
The problem is that my plot from this code looks like that:
有人可以告诉我我的代码有什么问题吗?老实说,我希望它看起来会更好(例如: http://imgur.com/wGs43)所以这就是为什么我问这个问题.
Can someone tell me what is wrong with my code? To be honest I'd excepted it would look better (something like this:http://imgur.com/wGs43) so that's why I am asking this question.
我的数据可以在这里找到: https://dl.dropboxusercontent.com/u/58774274 /exp.txt
My data can be found here: https://dl.dropboxusercontent.com/u/58774274/exp.txt
推荐答案
您的Fs
是50
,因此数据中的最高频率可以是Fs/2 = 25Hz
.
Your Fs
is 50
so the highest frequency in your data can be Fs/2 = 25Hz
.
看看此代码是否有帮助.
See if this code helps.
fid = fopen('1.txt','r');
C = textscan(fid, '%f');
fclose(fid);
data = C{1};
fs = 50;
m = length(data);
nfft = 2^nextpow2(m);
y = fft(data,nfft)/m;
f = fs/2 * linspace(0,1,nfft/2+1);
power = abs(y);
subplot(211)
plot(f,power(1:nfft/2+1))
t = (0 : m-1)/fs;
s0 = .8*fs : 3.2*fs; % .8 sec to 3.2 sec
p(s0) = .5*cos(2*pi*3.3*t(s0)+.25*pi);
p = p + mean(data);
subplot(212)
plot(t,data);hold on
plot(t,p,'r')
这是您在频域中的数据.
This is your data in frequency domain.
在3.3 Hz
处有一个峰.
作为证明,我绘制了频率为3.3 Hz
的正弦曲线以及您的数据,
As a proof I plotted a sinusoidal with frequency of 3.3 Hz
along with your data,
如您所见,它与您的数据完全匹配.
As you can see, it totally matches your data.
这篇关于带FFT的加速度计-奇怪的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!