MATLAB: How to use fft to find the motor acceleration’s frequency

electric_motor_controlfftpower_electronics_control

hi, I'm new in using matlab, i was tried to find my motor's frequency by using fft, but i got in trouble, i tried lot of examples on the internet but it didn't work, if somebody can give my some tips i will be so appreciate!!!
my sampling rate is about 8hz, and in txt is the acceleration of motor about 1024,and this code is one of example i copy from internet,even it doesn't works.
c=textread('C:\Users\wkj88\Desktop\11.txt', '%f') ;
T=1/250;
L=length(c);
Fs=1/T;
t=(0:L-1)*T;
Y = fft(c);
mag1 = abs(Y/L);
mag = mag1(1:L/2+1);
mag(2:end-1) = 2*mag(2:end-1);
ph1 = rad2deg(Y/L);
ph = ph1(1:L/2+1);
ph(2:end-1) = 2*ph(2:end-1);
f=Fs*(0:(L/2))/L;
subplot(2,2,[1,2])
plot(t,c);
title('Vibration Signal');
xlabel('Time (seconds)');
ylabel('Amplitude (voltage)');
subplot(2,2,3)
plot(f,mag);
title('Magnituge Plot');
xlabel('Frequency (Hz)');
ylabel('Amplitude');
subplot(2,2,4)
plot(f,ph);
title('Phase Plot');
xlabel('Frequency (Hz)');
ylabel('Phase (degree)');

Best Answer

Your signal is contaminated with broadband noise, so a frequency-selective filter will not remove it.
I believe this is what you want:
c = load('11.txt');
N = numel(c);
Fs = 8; % Sampling Frequency (Hz)
Fn = Fs/2; % Nyquist Frequency (Hz)
Ts = 1/Fs; % Sampling Interval (s)
t = linspace(0, 1, numel(c))*Ts; % Time Vector
cn = c - mean(c); % Remove D-C Offset
Y = fft(cn)/N;
Fv = linspace(0, 1, fix(numel(Y)/2)+1)*Fn; % Frequency Vector
Iv = 1:numel(Fv); % Index Vector
figure
plot(t, c)
grid
xlabel('t')
ylabel('c')
figure
subplot(2,1,1)
plot(Fv, abs(Y(Iv))*2)
grid
ylabel('Amplitude')
subplot(2,1,2)
plot(Fv, angle(Y(Iv)))
grid
xlabel('Frequency (Hz)')
ylabel('Phase (rad)')