# Calculating Vibrational frequency with MPU 6050

75 views (last 30 days)
Alexander Tan on 3 Mar 2020
Commented: pvsk Reddy on 9 Dec 2020
Hello I am trying to calculate the vibrational frequency of a motor. I am using an arduino to power a motor, 10mm Vibration Motor - 3mm Type Model: 310-122 by percision microdriver. Using a duty cycle of .54 i epxect a vibrational frequency of 190hz but when i plot it i only get to 40hz i beleive. My current script uses the ardunio and mpu 6050 library to loop reading the values then storing them into an array. I plot acceleration vs time and use the fft to get magnitude vs frequency. Is it my sampling frequency that may be wrong? I have based my code off other examples I have seen on MathWorks. Also would it be better if i recorded the data to an excel then read that in a different script? I have seen a lot of examples that read from excel and then fft.
clear all
close all
a = arduino('COM3', 'Uno', 'Libraries', 'I2C');
imu = mpu6050(a);
%pause on
writePWMDutyCycle(a,'D3', .24);
format shortg
tic
for i = 1:1000
%c = clock
x(i) = (acc(1)/9.80665);
y(i) = (acc(2)/9.80665);
z(i) = (acc(3)/9.80665);
toc
time(i) = toc;
%pause(0.1);
end
%toc
f1 = figure;
f2 = figure;
f3 = figure;
f4 = figure;
f5 = figure;
f6 = figure;
plot(time,x,'.-')
ylabel('y,Acceleration (g)')
xlabel('x,Time (MilliSeconds)')
title('X Accel')
figure(f5)
plot(time,y,'.-')
ylabel('y,Acceleration (g)')
xlabel('x,Time (MilliSeconds)')
title('Y Accel')
figure(f4)
plot(time,z,'.-')
ylabel('y,Acceleration (g)')
xlabel('x,Time (MilliSeconds)')
title('Z Accel')
%0.015
t = (time)*1E-1; % time to miliseconds, maybe no conversion?
v = x; % accel values of x axis (g)
L = length(t);
Ts = mean(diff(t));
Fs = 1/Ts;
Fn = Fs/2;
vc = v - mean(v);
FTv = fft(vc)/L; % Fourier Transform
Fv = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector (Hz)
Iv = 1:length(Fv); % Index Vector
figure(f3)
plot(Fv, abs(FTv(Iv))*2)
grid
xlabel('Frequency (Hz)')
ylabel('Amplitude (g)')
title('X Frequency')
v2 = y;
vc2 = v2 - mean(v2);
FTv2 = fft(vc2)/L; % Fourier Transform
Fv2 = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector (Hz)
Iv2 = 1:length(Fv2); % Index Vector
figure(f2)
plot(Fv2, abs(FTv2(Iv2))*2)
grid
xlabel('Frequency (Hz)')
ylabel('Amplitude (g)')
title('Y Frequency')
v3 = z;
vc3 = v3 - mean(v3);
FTv3 = fft(vc3)/L; % Fourier Transform
Fv3 = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector (Hz)
Iv3 = 1:length(Fv3); % Index Vector
figure(f1)
plot(Fv3, abs(FTv3(Iv3))*2)
grid
xlabel('Frequency (Hz)')
ylabel('Amplitude (g)')
title('Z Frequency')
writePWMDutyCycle(a,'D3', 0);
pvsk Reddy on 9 Dec 2020
Hello Mr. Alexander,
Are able to sort this out? by chance.

Gayatri Menon on 21 Apr 2020
Hi,
Could you try setting the SampleRate of the imu object and use read()
>> imu = mpu9250(a,"SampleRate",190);
>> tt.Acceleration
Hope this helps
Thanks
Gayatri

### Categories

Find more on Spectral Measurements in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by