How can I fix the X-Axis plot flipping when 180° are reached?

5 ビュー (過去 30 日間)
Nicolò Dall'Acqua
Nicolò Dall'Acqua 2021 年 3 月 20 日
編集済み: Nicolò Dall'Acqua 2021 年 9 月 9 日
Hello everybody,
I am using accelerometer and gyroscope data from an unknown brand IMU, acquired at 833Hz.
I'm trying to represent the IMU orientation during the trial using the imufilter command. When I plot the orientation data, the overall output seems reasonable, but the X-axis has ~20 samples flipped of 180°, and I don't know how to fix this.
I tried to use the unwrap command, but with no success so far.
Could you please help me?
I attach a ZIP with an image of the aforementioned plot and the data matrix.
Thank you,
Nico
close all
clear all %#ok<CLALL>
clc
%% LOAD DATA
dataA = load('accelReadings.mat');
accelReadings = dataA.accelReadings;
dataG = load('gyroReadings.mat');
gyroReadings = dataG.gyroReadings;
%% INSERT Fs AND TIME
Fs = 833; % SAMPLING FREQ [Hz]
time = linspace(0,7850,7851)/833; % TIME VECTOR [s]
Ts = mean(diff(time)); % SAMPLING INTERVAL
%% KALMAN
accelReadings = sgolayfilt(accelReadings,3,11); % FILTER
gyroReadings= sgolayfilt(gyroReadings,3,11); % FILTER
%gyroReadings = unwrap(gyroReadings);
FUSE = imufilter('SampleRate',Fs);
q = FUSE(accelReadings, gyroReadings);
figure
plot(time,eulerd(q,'ZYX','frame')) % PLOT ANGLES
title('3^{rd} Bike Stunt: ESTIMATED ORIENTATION')
legend('Z-axis', 'Y-axis', 'X-axis')
xlabel('Time [s]')
ylabel('Rotation [°]')
grid on
clearvars dataA dataG

採用された回答

Ananya Tewari
Ananya Tewari 2021 年 3 月 23 日
I understand you want to unwrap the flipped samples on X-axis.
The unwrap function accepts the threshold in radians. So converting the x-axis samples into radians and then using unwrap for π radians should resolve the issue
q = FUSE(accelReadings, gyroReadings);
% converting quaternions to euler angles
k = eulerd(q,'ZYX','frame');
% converting x-axis angles to radian for using unwrap
x = unwrap(deg2rad(k(:,3)),pi);
% converting radians back to degrees
x = rad2deg(x);
% updating the orientation angles
k(:,3) = x;
% PLOT ANGLES
figure
plot(time,k)
title('3^{rd} Bike Stunt: ESTIMATED ORIENTATION')
legend('Z-axis', 'Y-axis', 'X-axis')
xlabel('Time [s]')
ylabel('Rotation [°]')
grid on
The output of the following code :
  1 件のコメント
Nicolò Dall'Acqua
Nicolò Dall'Acqua 2021 年 3 月 23 日
編集済み: Nicolò Dall'Acqua 2021 年 9 月 9 日
Thank you, Ananya!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by