matlab - Accelerometer with FFT - strange output -
after reading lot of research , works on subject still have got problems applying fft accelerometer data. of code taken official matlab example: fft 1 dimension. after more reading i've found question: fft , accelerometer data: why getting output? there suggestion use windowing. after more reading i've added hamming window code.
my data looks on plot:
and code using fft:
fs = 1/0.02; %0.02 comes 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 plot code looks that:
can tell me wrong code? honest i'd excepted better (something this:http://imgur.com/wgs43) that's why asking question.
edit: data can found here: https://dl.dropboxusercontent.com/u/58774274/exp.txt
your fs
50
highest frequency in data can fs/2 = 25hz
.
see if 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 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 data in frequency domain.
there peak @ 3.3 hz
.
as proof plotted sinusoidal frequency of 3.3 hz
along data,
as can see, totally matches data.
Comments
Post a Comment