Calculating Vibrational frequency with MPU 6050

56 views (last 30 days)
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
for i = 1:1000
%c = clock
acc = readAcceleration(imu);
x(i) = (acc(1)/9.80665);
y(i) = (acc(2)/9.80665);
z(i) = (acc(3)/9.80665);
time(i) = toc;
f1 = figure;
f2 = figure;
f3 = figure;
f4 = figure;
f5 = figure;
f6 = figure;
ylabel('y,Acceleration (g)')
xlabel('x,Time (MilliSeconds)')
title('X Accel')
ylabel('y,Acceleration (g)')
xlabel('x,Time (MilliSeconds)')
title('Y Accel')
ylabel('y,Acceleration (g)')
xlabel('x,Time (MilliSeconds)')
title('Z Accel')
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
plot(Fv, abs(FTv(Iv))*2)
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
plot(Fv2, abs(FTv2(Iv2))*2)
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
plot(Fv3, abs(FTv3(Iv3))*2)
xlabel('Frequency (Hz)')
ylabel('Amplitude (g)')
title('Z Frequency')
writePWMDutyCycle(a,'D3', 0);
  1 Comment
pvsk Reddy
pvsk Reddy on 9 Dec 2020
Hello Mr. Alexander,
Are able to sort this out? by chance.

Sign in to comment.

Answers (1)

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

Community Treasure Hunt

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

Start Hunting!