Ошибка при вычислении фазового угла с использованием графика углового угла.Python

Программы на Python
Ответить Пред. темаСлед. тема
Anonymous
 Ошибка при вычислении фазового угла с использованием графика углового угла.

Сообщение Anonymous »

Я пытаюсь вычислить фазовый угол между двумя временными рядами по двум известным сигналам (двум синусоидальным волнам) с фазой 24 градуса. Однако, когда я вычисляю фазовый угол между этими сигналами, я не получаю ожидаемого результата по кадрам (24 градуса). Вот мой сценарий:

Код: Выделить всё

def coupling_angle_joints(proximal_joint_angle, distal_joint_angle, tolerance, datatype="degs"):
"""
Compute coupling angle in degrees between proximal and distal joint angles.
Based on the article:
"Analysing patterns of coordination and patterns of control using novel data
visualisation techniques in vector coding" Robert A. Needham, Roozbeh Naemi,
Joseph Hamill, Nachiappan Chockalingam, The Foot 44 (2020) 101678 "

Parameters:
proximal_joint_angle:   numpy array
Proximal joint angle.
distal_joint_angle:     numpy array
Distal joint angle.
tolerance:              float
Tolerance level.
datatype:               str
type of input data (degrees or radians)
Returns:
phase_angles :      numpy array
Coupling angle in degrees between proximal and distal joint angle.

"""
if datatype.lower().strip() == "degs":
proximal_joint_angle = np.radians(proximal_joint_angle)
distal_joint_angle = np.radians(distal_joint_angle)

elif datatype.lower().strip() == "rads":
proximal_joint_angle = proximal_joint_angle
distal_joint_angle = distal_joint_angle

# Calculate the difference between consecutive elements for proximal and distal joint angles
proximal_joint_angle_diff = np.diff(proximal_joint_angle)
distal_joint_angle_diff = np.diff(distal_joint_angle)

# Initialize arrays to store coupling angles and their x and y components
phase_angles = np.zeros(proximal_joint_angle_diff.shape[0])

# Iterate over the differences to calculate the coupling angles
for idx in range(proximal_joint_angle_diff.shape[0]):

# Assign 90 degrees when proximal joint angle difference is 'zero' and distal is positive
if np.abs(proximal_joint_angle_diff[idx]) < tolerance and distal_joint_angle_diff[idx] > 0:
phase_angle = 90

# Assign - 90 degrees when proximal joint angle difference is 'zero' and distal is negative
elif np.abs(proximal_joint_angle_diff[idx]) < tolerance and distal_joint_angle_diff[idx] < 0:
phase_angle = -90

# Assign -180 degrees when proximal joint angle difference is negative and distal differences is 'zero'
elif np.abs(proximal_joint_angle_diff[idx]) < 0 and np.abs(distal_joint_angle_diff[idx]) <  tolerance:
phase_angle = -180

# Assign 'nan' when proximal and distal joint angle difference is 'zero'
elif np.abs(proximal_joint_angle_diff[idx]) < tolerance and np.abs(distal_joint_angle_diff[idx]) < tolerance:
phase_angle = np.nan

# Calculate phase  angle when proximal joint angle difference is positive
if proximal_joint_angle_diff[idx] > 0:
phase_angle = np.arctan(distal_joint_angle_diff[idx] / proximal_joint_angle_diff[idx]) * 180/np.pi

# Calculate phase angle when proximal joint angle difference is negative
elif proximal_joint_angle_diff[idx] < 0:
phase_angle = np.arctan(distal_joint_angle_diff[idx] / proximal_joint_angle_diff[idx]) * 180/np.pi + 180 / np.pi

# Ensure phase  angle is within the range [0, 360)
if phase_angle < 0:
phase_angle = phase_angle + 360

# Store the calculated phase angle
phase_angles[idx] = phase_angle

# Return the calculated phase angles
return phase_angles
Заранее благодарим за любую помощь.

Подробнее здесь: https://stackoverflow.com/questions/791 ... angle-plot
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Python»