Analysis¶
Auto-generated documentation for musicalgestures._analysis module.
General-purpose signal and statistics utilities for analysing rhythmic and periodic structure in motion and audio signals.
- Mgt-python / Modules / Musicalgestures / Analysis
These helpers are independent of the MgVideo/MgAudio classes and can be used on any 1-D numpy signal (e.g. quantity-of-motion curves, body-part speeds, audio onset envelopes).
bandpass¶
Apply a zero-phase Butterworth band-pass filter to a signal.
Arguments¶
signalnp.ndarray - Input signal.lofloat - Lower cutoff frequency (Hz).hifloat - Upper cutoff frequency (Hz).fsfloat - Sampling rate of the signal (Hz).orderint, optional - Filter order. Defaults to 4.
Returns¶
np.ndarray- The filtered signal. Returns the input unchanged if the requested band is invalid for the given sampling rate.
circular_stats¶
Compute circular mean direction and resultant vector length of a set of phases.
Arguments¶
phasesnp.ndarray - Phase angles in radians.
Returns¶
tuple-(R, mean_angle_deg)whereRis the mean resultant length in [0, 1] (1 = perfectly concentrated, 0 = uniform) andmean_angle_degis the mean direction in degrees [0, 360).
dominant_frequency¶
Find the dominant frequency of a signal within a frequency band using the FFT.
Useful for estimating, e.g., the dominant oscillation rate of a body part's speed signal (steps per second in a dance).
Arguments¶
signalnp.ndarray - Input signal.fpsfloat - Sampling rate of the signal (Hz, e.g. frames per second).fminfloat, optional - Lowest frequency to consider (Hz). Defaults to 0.5.fmaxfloat, optional - Highest frequency to consider (Hz). Defaults to 8.0.
Returns¶
float- The dominant frequency (Hz) within [fmin, fmax], or 0.0 if the band contains no frequency bins.
rayleigh_test¶
Rayleigh test for non-uniformity of circular data.
Tests the null hypothesis that the phases are uniformly distributed around the circle. A small p-value indicates significant phase concentration (i.e. consistent timing).
Arguments¶
phasesnp.ndarray - Phase angles in radians.
Returns¶
tuple-(Z, p)whereZis the Rayleigh statistic andpis the approximate p-value.
smooth¶
Smooth a 1-D signal with a moving average.
Arguments¶
xnp.ndarray - Input signal.wint, optional - Window size in samples. Defaults to 5.
Returns¶
np.ndarray- Smoothed signal of the same length as the input.
synchrony¶
Pearson correlation between two signals after alignment and normalisation.
If time vectors are supplied, signal_b is linearly resampled onto the
time base of signal_a before correlating. Both signals are min-max
normalised to [0, 1]. Useful for quantifying audio–motion synchrony (e.g.
audio onset strength vs. overall motion energy).
Arguments¶
signal_anp.ndarray - First signal (reference time base).signal_bnp.ndarray - Second signal.times_anp.ndarray, optional - Time stamps forsignal_a. Defaults to None.times_bnp.ndarray, optional - Time stamps forsignal_b. Defaults to None.
Returns¶
float- Pearson correlation coefficient in [-1, 1].