def _compute_natural_frequencies(freqs, n, t, avg = False): ''' Computes the natural frequencies omega_0 of a matrix of frequencies. In this calculation, we assume the natural frequency is that which is maximal. Arguments ========= freqs: The M x N frequency data matrix. n: Number of frames. t: Framerate. avg: Boolean flag indicating whether we want to average the columns of "freqs" together into a single vector, or compute the parameters for all the rows. Returns ======= natural_frequencies: Natural frequencies of each pixel (either length M or 1) nu: Indices at which the natural frequencies are found in the FFT data. (M or 1) ''' # Do some indexing voodoo to prevent the 0th index from ever being # the maximum frequency of the entire dataset (since it never should be!). nu = None if avg: nu = np.argmax(frequency.average_frequencies(np.absolute(freqs))[1:]) else: nu = np.argmax(np.absolute(freqs[:, 1:]), axis = 1) nu += 1 natural_frequencies = 2 * np.pi * (nu / (n * t)) return [natural_frequencies, nu]
def _compute_force_avg(freqs, n, t): ''' Averages the frequencies of each component together before performing the force analysis. Arguments ========= frequencies: Frequency embedding of the original displacement data. M x N. n: Number of frames. t: Framerate. Returns ======= natural_frequencies: 1 natural frequency. damping_coefficients: 1 damping coefficient. F_mvs: N force/mass ratios (freq domain). phase: N force/mass phase angles. f_mvs: N force/mass ratios (time domain). ''' # First, compute the natural frequency. natural_frequency, index = _compute_natural_frequencies(freqs, n, t, avg = True) # Next, compute the damping coefficient. avg_freqs = frequency.average_frequencies(freqs) damping_coefficient = _compute_damping_coefficient(avg_freqs, index, n, t) # Then, compute the force for each point in the dataset. F_mv = _force_equation(avg_freqs, natural_frequency, damping_coefficient, n, t) # Compute the phase angle associated with each force in the dataset. phase = _phase_angle_equation(avg_freqs, natural_frequency, damping_coefficient, n, t) # Finally, compute the time domain representation of force of contractility f_mv = _time_domain(F_mv, phase, n) # All done. return [natural_frequency, damping_coefficient, F_mv, phase, f_mv]