Я пытаюсь вычислить фазовый угол между двумя временными рядами по двум известным сигналам (две синусоидальные волны с фазой 24 градуса). Однако, когда я вычисляю фазовый угол между этими сигналами, я не получаю ожидаемого результата по кадрам (24 градуса). Вот мой сценарий:
def coupling_angle_joints(x, y, epsilon=0.05, datatype="degs"):
"""
Calculate coupling angles between two joint angle signals.
Parameters:
x: numpy array
First angle signal (e.g., proximal joint angle).
y: numpy array
Second angle signal (e.g., distal joint angle).
epsilon: float, optional (default=0.05)
Tolerance level. Values below this threshold are considered close to zero.
datatype: str, optional (default="degs")
Specifies the unit of the input data: "degs" for degrees, "rads" for radians.
Returns:
phase_angles: numpy array
Array of coupling phase angles (in degrees) between 'x' and 'y' signals.
"""
# Convert angles from radians to degrees if necessary
# This ensures that all angles are in degrees before processing
if datatype.lower().strip() == "rads":
x = np.degrees(x)
y = np.degrees(y)
# Compute the difference between consecutive elements in each signal
# This captures the rate of change in the proximal (x) and distal (y) angles
x_diff = np.diff(x)
y_diff = np.diff(y)
# Initialize an array to store the calculated phase angles
# The shape matches the number of computed differences (len(x) - 1)
phase_angles = np.zeros(x_diff.shape[0])
# Iterate over each pair of consecutive differences to calculate coupling angles
for idx in range(len(x_diff)):
xi_diff = x_diff[idx] # Change in the proximal angle (x) between two consecutive points
yi_diff = y_diff[idx] # Change in the distal angle (y) between two consecutive points
# Handle cases where both differences are close to zero, using the tolerance 'epsilon'
if np.abs(xi_diff) < epsilon and np.abs(yi_diff) < epsilon:
# If both changes are negligible, set the phase angle to NaN
phase_angle = np.nan
# Handle cases where only proximal change is negligible
elif np.abs(xi_diff) < epsilon:
# Proximal joint is essentially static; angle depends on distal joint movement
# If distal change is positive, set to 90 degrees; if negative, set to -90 degrees
phase_angle = 90 if yi_diff > 0 else -90
# Handle cases where only distal change is negligible
elif np.abs(yi_diff) < epsilon:
# Distal joint is essentially static; angle depends on proximal joint movement
# If proximal change is positive, set to 0 degrees; if negative, set to -180 degrees
phase_angle = 0 if xi_diff > 0 else 180
else:
# Calculate phase angle using arctan2, which handles the signs of both `yi_diff` and `xi_diff`
# to place the angle correctly within all four quadrants
phase_angle = np.degrees(np.arctan2(yi_diff, xi_diff))
# Ensure phase angle is within the range [0, 360) by adding 360 if it's negative
if phase_angle < 0:
phase_angle += 360
# Store the calculated phase angle in the output array
phase_angles[idx] = phase_angle
return phase_angles
Я пытаюсь вычислить фазовый угол между двумя временными рядами по двум известным сигналам (две синусоидальные волны с фазой 24 градуса). Однако, когда я вычисляю фазовый угол между этими сигналами, я не получаю ожидаемого результата по кадрам (24 градуса). Вот мой сценарий: [code] def coupling_angle_joints(x, y, epsilon=0.05, datatype="degs"): """ Calculate coupling angles between two joint angle signals.
Parameters: x: numpy array First angle signal (e.g., proximal joint angle). y: numpy array Second angle signal (e.g., distal joint angle). epsilon: float, optional (default=0.05) Tolerance level. Values below this threshold are considered close to zero. datatype: str, optional (default="degs") Specifies the unit of the input data: "degs" for degrees, "rads" for radians.
Returns: phase_angles: numpy array Array of coupling phase angles (in degrees) between 'x' and 'y' signals. """
# Convert angles from radians to degrees if necessary # This ensures that all angles are in degrees before processing if datatype.lower().strip() == "rads": x = np.degrees(x) y = np.degrees(y)
# Compute the difference between consecutive elements in each signal # This captures the rate of change in the proximal (x) and distal (y) angles x_diff = np.diff(x) y_diff = np.diff(y)
# Initialize an array to store the calculated phase angles # The shape matches the number of computed differences (len(x) - 1) phase_angles = np.zeros(x_diff.shape[0])
# Iterate over each pair of consecutive differences to calculate coupling angles for idx in range(len(x_diff)):
xi_diff = x_diff[idx] # Change in the proximal angle (x) between two consecutive points yi_diff = y_diff[idx] # Change in the distal angle (y) between two consecutive points
# Handle cases where both differences are close to zero, using the tolerance 'epsilon' if np.abs(xi_diff) < epsilon and np.abs(yi_diff) < epsilon: # If both changes are negligible, set the phase angle to NaN phase_angle = np.nan
# Handle cases where only proximal change is negligible elif np.abs(xi_diff) < epsilon: # Proximal joint is essentially static; angle depends on distal joint movement # If distal change is positive, set to 90 degrees; if negative, set to -90 degrees phase_angle = 90 if yi_diff > 0 else -90
# Handle cases where only distal change is negligible elif np.abs(yi_diff) < epsilon: # Distal joint is essentially static; angle depends on proximal joint movement # If proximal change is positive, set to 0 degrees; if negative, set to -180 degrees phase_angle = 0 if xi_diff > 0 else 180
else: # Calculate phase angle using arctan2, which handles the signs of both `yi_diff` and `xi_diff` # to place the angle correctly within all four quadrants phase_angle = np.degrees(np.arctan2(yi_diff, xi_diff))
# Ensure phase angle is within the range [0, 360) by adding 360 if it's negative if phase_angle < 0: phase_angle += 360
# Store the calculated phase angle in the output array phase_angles[idx] = phase_angle
return phase_angles [/code] Заранее благодарим за любую помощь.
Я пытаюсь вычислить фазовый угол между двумя временными рядами по двум известным сигналам (двум синусоидальным волнам) с фазой 24 градуса. Однако, когда я вычисляю фазовый угол между этими сигналами, я не получаю ожидаемого результата по кадрам (24...
Я пытаюсь вычислить фазовый угол между двумя временными рядами действительных чисел. Чтобы проверить, работает ли моя функция без ошибок, я создал две синусоидальные волны с фазой 17 градусов. Однако, когда я вычисляю фазовый угол между этими двумя...
Я пытаюсь вычислить фазовый угол между двумя временными рядами действительных чисел. Чтобы проверить, работает ли моя функция без ошибок, я создал две синусоидальные волны с фазой 17 градусов. Однако, когда я вычисляю фазовый угол между этими двумя...
Я пытаюсь вычислить фазовый угол между двумя временными рядами действительных чисел. Чтобы проверить, работает ли моя функция без ошибок, я создал две синусоидальные волны с фазой 17 градусов. Однако, когда я вычисляю фазовый угол между этими двумя...
Я сделал собственный 2D-позвонок на основе этого видео: Простая техника процедурной анимации — Youtube
Я попытался реализовать это здесь (ограничения угла между звеньями позвоночника) ), но каждое решение, которое я придумал, привязывалось к порогу...