Integrating accelerometer and gyroscope using complementary filter
Hello, i am having difficulty trying to combine accelerometer and gyroscope in matlab. I am unsure that the graph that i got is correct because the gyroscope waveform and complementary waveform is similar. Can help me check if the codings ive done is right?
This is what ive done:
graceAcc = xlsread('graceAcc.csv');
X= graceAcc(:,2);
Y= graceAcc(:,3);
Z= graceAcc(:,4);
graceGyro = xlsread('graceGyro.csv');
T= graceGyro(:,1);
X1= graceGyro(:,2);
Y1= graceGyro(:,3);
Z1= graceGyro(:,4);
hpf = 0.98;
lpf = 0.02;
TX = atand((X)./sqrt(Y.^2 + Z.^2));
TY = atand((Y)./sqrt(X.^2 + Z.^2));
TZ = atand(sqrt(Y.^2 + X.^2)./(Z));
X2 = 0;
Y2 = 0;
Z2 = 0;
X3 = X2 + (X1.*T);
for a = 1:length(X1)
if a == 1
X2 = ((X1.*T).*hpf) + (TX(1:110).*lpf);
Y2 = (Y1.*T).*hpf + (TY(1:110).*lpf);
Z2 = (Z1.*T).*hpf + (TZ(1:110).*lpf);
else
X2 = (X3).*hpf + (TX(1:110).*lpf);
Y2 = (Y2 + (Y1.*T)).*hpf + (TY(1:110).*lpf);
Z2 = (Z2 + (Z1.*T)).*hpf + (TZ(1:110).*lpf);
end
end
plot(TX,'g');
hold on
plot(TY,'r');
hold on
plot(TZ,'b');
title('Change in Angle of Accelerometer and Gyroscope')
xlabel('samples')
ylabel('tilt angle')
legend('Complementary filter X','Accelerometer X','Gyroscope X')
This discussion has been closed.
Comments