Modal Analysis Module¶
Modal analysis tools for mode fitting and modal parameter extraction.
A fit is stored as a ModalData (see Data Structures),
whose matrix M has one row per mode: the natural frequency fn and
damping ratio zn, then the modal-constant amplitude an, phase pn
and residual terms rk, rm for each channel.
Fitting¶
modal_fit_single_channel ¶
Fit one mode to one channel of a transfer function.
Fits the single-mode model (see f_TF) to the TF samples strictly
inside freq_range, starting from a half-power-bandwidth guess,
using scipy.optimize.least_squares. The fitted values are
printed, with a warning when the phase exceeds 60 degrees (which
suggests the wrong measurement_type). Unlike
modal_fit_all_channels, the TF is used uncalibrated
(channel_cal_factors are not applied).
Parameters:
-
tf_data(TfData) –The transfer function to fit.
-
freq_range(list, default:None) –[f_min, f_max]in Hz around one peak. None (the default) uses the whole frequency axis. -
channel(int, default:0) –Column of
tf_data.tf_datato fit (default 0). -
measurement_type(str, default:'acc') –What the TF's output measures:
'acc'(acceleration, the default),'vel'(velocity) or'dsp'(displacement).
Returns:
-
result(OptimizeResult) –The optimiser's result;
result.xis[fn, zn, an, pn, rk, rm]: natural frequency (Hz), damping ratio, modal-constant amplitude and phase (radians), and the two local residual terms.
modal_fit_all_channels ¶
Fit one mode, with shared frequency and damping, to every TF channel.
Every column of every TfData in tf_data_list that is not a
modal reconstruction is fitted at once: the natural frequency and
damping ratio are shared, while each column gets its own
modal-constant amplitude and phase and its own local residual
terms. The TFs are calibrated first (multiplied by their
channel_cal_factors), so the fitted constants are in engineering
units.
The TFs need not share a frequency axis. Each is fitted on its own
frequency points strictly inside freq_range, so captures at
different sample rates or frame lengths, a stepped sine beside a
noise test, or the separate measurements of a Vibration Apps CSV
can be fitted together. Each column counts equally in the fit,
however many points it has in the band: its residual is weighted by
sqrt(n_ref / n_c), where n_c is its number of points and
n_ref the most any column has (so all weights are 1 when the
axes agree). The starting guess is taken from each column on its
own axis too.
A summary is printed and kept in modal.MESSAGE, with warnings
when any phase exceeds 60 degrees (check measurement_type) or
the fit is poor (try another freq_range). The fit quality is
judged with the same equal weighting of the columns.
Parameters:
-
tf_data_list(TfDataList) –The transfer functions to fit. A list of one fits one set on its own.
-
freq_range(list, default:None) –[f_min, f_max]in Hz around one peak. None (the default) spans every TF in the list, from the lowest first frequency to the highest last one. -
measurement_type(str, default:'acc') –What the TFs' outputs measure:
'acc'(acceleration, the default),'vel'(velocity) or'dsp'(displacement). It sets the power of(i*omega)applied to the receptance model.
Returns:
-
modal_data(ModalData) –One mode, with
Mof shape(1, 2 + 4*n_columns)(columns in list order, set by set) andid_linklisting the fitted TFs'id_linkvalues.
Raises:
-
ValueError–tf_data_listholds no TF that is not a modal reconstruction, or one of its TFs has no frequency points insidefreq_range(the message names it by its index in the list and itstest_name).
modal_refine ¶
Refine all fitted modes together against the measured transfer functions.
Starts from the current fit. The nonlinear search runs over the
natural frequencies and damping ratios only (two parameters per
mode); at every candidate set of poles the modal constants and one
pair of global residual terms per channel are re-solved linearly
(estimate_global_constants). Like modal_fit_all_channels, the
measured TFs are calibrated first, so the seed and the result are in
the same units.
The refined rows hold the new poles and the re-estimated constants
(an = |A|, pn = angle(A)), with the local residual terms
(rk, rm) set to zero: after a joint refinement they have no meaning,
and reconstruct_transfer_function_global estimates its own
residual terms from the data.
The TFs need not share a frequency axis. As in
modal_fit_all_channels, each is used on its own frequency points
inside the band, the poles are shared, and each column counts
equally however many points it has there (its residual is weighted
by sqrt(n_ref / n_c); the costs reported are of this weighted
residual).
Convergence is reported, not enforced: the refined model is returned
even when it did not converge, and the caller decides whether to
keep it. If the input data make the solve fail (for example a NaN
sample), the seed poles are returned with converged False.
Parameters:
-
modal_data(ModalData) –The fit to refine; it must hold at least one mode.
-
tf_data_list(TfDataList) –The measured TFs, in the fit's column order; their total column count must match the fit's channel count.
-
freq_range(list, default:None) –[f_min, f_max]in Hz to refine over, clamped to the span of the TFs' axes. None (the default) uses the modes' natural-frequency span, padded to include each peak's half-power skirts. A band too narrow to constrain the parameters (every TF has fewer thanmax(4, 2*n_modes + 2)points in it) is widened to every TF's whole axis. -
measurement_type(str, default:'acc') –'acc'(the default),'vel'or'dsp', as used for the fit.
Returns:
-
modal_data(ModalData) –The refined modes, with the same settings,
id_linkandtest_nameprovenance asmodal_fit_all_channelsgives. -
info(dict) –{'converged': bool, 'cost_before': float, 'cost_after': float}. Both costs are the least-squares cost of the same projected model (at the seed poles and at the refined poles), so they can be compared directly.
Raises:
-
ValueError–modal_datahas no modes,tf_data_listholds no measured (non-reconstruction) TF, the channel counts do not match, or one TF has no frequency points inside the band while another has enough (the message names it).
Reconstruction¶
reconstruct_transfer_function ¶
Rebuild transfer functions from fitted modes, summing each mode's local fit.
Each row of modal_data.M is evaluated with f_TF_all_channels,
including its local residual terms (rk, rm), and the modes are
summed. modal_data is not modified.
Parameters:
-
modal_data(ModalData) –The fitted modes.
-
f(ndarray) –Frequency axis in Hz on which to evaluate.
-
measurement_type(str, default:'acc') –'acc'(the default),'vel'or'dsp', as used for the fit.
Returns:
-
tf_data(TfData) –The reconstruction, one column per channel, with
flag_modal_TF = True, no coherence and unit calibration factors (the fitted constants are already in engineering units).
reconstruct_transfer_function_global ¶
reconstruct_transfer_function_global(modal_data, f, measurement_type='acc', tf_data_list=None, fade_residues=True)
Rebuild transfer functions from all fitted modes together, as one global model.
With tf_data_list (the measured TFs), the modal constants
(amplitude and phase, per channel) and one pair of global residual
terms per channel (a constant RH and RL/omega**2) are
re-solved linearly against the measured data over the modes' padded
band, with the stored natural frequencies and damping ratios held
fixed (see estimate_global_constants). This avoids counting each
mode's neighbours twice, as a sum of separately fitted local modes
does. Each TF's columns are solved on that TF's own frequency points
inside the band, so the TFs need not share an axis; a TF with too
few points in the band to determine its constants (fewer than
max(4, n_modes + 2), as on a coarse frame-averaged axis) uses
that many of its points nearest the band instead. A TF with fewer
than 2*(n_modes + 2) points there
(RESIDUE_MIN_POINTS_PER_UNKNOWN) gets no residual terms: so few
points would let the residues take up the noise.
The residual terms stand for modes outside that band, so they hold
only near it. Evaluated far from it they run away: RL/omega**2
grows without limit towards 0 Hz, and RH grows as omega**p
once the (j*omega)**p of an 'acc' or 'vel' TF is applied,
while the modes fall away. On a clean single-mode mobility fitted with
the right TF type, the residues that a little noise leaves put the
reconstruction some 75 dB off at the ends of a 0-1000 Hz axis. So by
default (fade_residues=True) each column's residues apply in full
inside the band its constants were solved on, and fade smoothly to
zero over the octave beyond each edge (RESIDUE_FADE_OCTAVES), never
exceeding their band-edge size on the way. Far from the modes the
reconstruction is then the modes alone, with no step at the band
edges. The web app's global fit lines are drawn this way.
fade_residues=False applies them on the whole of f, as
before.
Without tf_data_list (for example a ModalData loaded on its
own), if it holds no measured TF, or if the channel counts do not
match, the stored modes are summed with their local residual terms
(rk, rm) set to zero, over the whole of f. modal_data is not
modified.
Parameters:
-
modal_data(ModalData) –The fitted modes.
-
f(ndarray) –Frequency axis in Hz on which to evaluate. It need not be any TF's own axis.
-
measurement_type(str, default:'acc') –'acc'(the default),'vel'or'dsp', as used for the fit. -
tf_data_list(TfDataList, default:None) –The measured TFs the modes were fitted to, in the fit's column order.
-
fade_residues(bool, default:True) –With
tf_data_list, fade the residual terms out beyond the band they were solved on (default True); False applies them on the whole off.
Returns:
-
tf_data(TfData) –The reconstruction, one column per channel, with
flag_modal_TF = True, no coherence and unit calibration factors.
estimate_global_constants ¶
Re-estimate the COMPLEX modal constants and per-channel GLOBAL residual terms for FIXED poles — the linear half of the global fit.
With the poles {fn, zn} held fixed, the modal model is LINEAR in the
remaining parameters, so they solve in one least-squares with no
convergence risk. The model is the receptance form times (jw)^p:
``G0_c ~= (jw)^p * (sum_n A_nc * phi_n(w) + RH_c - RL_c/w^2)``
with phi_n = 1/(wn^2 + 2j*wn*zn*w - w^2), and the least squares
minimises the error in the MEASURED units, as the local fit and
modal_refine do. (Solving the receptance form G0_c/(jw)^p instead
would weight each point by 1/w^(2p): for an 'acc' TF the noise
near 0 Hz, amplified by 1/w^2, would outweigh the modes.)
RH (stiffness-like
constant) and RL/w^2 (mass-like) are ONE pair of GLOBAL residues per
channel, standing for above-band and below-band modes respectively —
unlike the local fits' per-mode rk/rm, which are mutually
redundant in a joint model (each mode's residues can impersonate a
neighbour's tail: flat cost directions that let refinement drag poles
without penalty). The constants that emerge are the GLOBALLY consistent
ones: neighbour interaction is explained by the neighbours themselves,
so any remaining phase in A is genuine mode complexity, not
circle-rotation leakage from nearby modes.
Every column of G0 is sampled on the one axis f. Columns from
sets on different axes are solved set by set (each column's solve is
independent of the others once the poles are fixed); modal_refine
and reconstruct_transfer_function_global do that for you.
Parameters:
-
fn(array_like) –pole natural frequencies (Hz), length N — held fixed during the solve
-
zn(array_like) –pole damping ratios, length N — held fixed
-
f(ndarray) –frequency axis (Hz); rows with
f <= 0are excluded (the1/w^2term and the(jw)^pdivision are singular at DC) -
G0(ndarray) –measured complex columns, shape
(len(f), n_cols), cal-scaled -
measurement_type(str, default:'acc') –'acc' | 'vel' | 'dsp' (the
(jw)^pconvention) -
residues(bool, default:True) –solve the residual terms too (default True); False solves the modal constants alone and returns
RHandRLas zeros
Returns (A, RH, RL, cost): A complex (N, n_cols), RH and
RL complex (n_cols,), and cost = 0.5*sum(|model - G0|^2) over
the used rows in MEASURED space (identical to the stacked real/imag
least-squares cost convention used by modal_refine).
Helpers¶
unpack_matrix ¶
Unpack a modal matrix into one array per parameter.
X holds one packed mode per row,
[fn, zn, an_0..an_C, pn_0..pn_C, rk_0..rk_C, rm_0..rm_C] for
N = C+1 channels; the channel count is taken from the column count.
An empty (0, 2 + 4*N) matrix (every mode deleted) is allowed and
gives empty arrays.
Parameters:
-
X(ndarray) –The modal matrix, shape
(n_modes, 2 + 4*N), such asModalData.M. A single row may be 1-D.
Returns:
-
fn(ndarray) –Natural frequencies in Hz, shape
(n_modes,). -
zn(ndarray) –Damping ratios, shape
(n_modes,). -
an(ndarray) –Modal-constant amplitudes, shape
(n_modes, N). -
pn(ndarray) –Modal-constant phases in radians, shape
(n_modes, N). -
rk(ndarray) –Local stiffness-like residual terms, shape
(n_modes, N). -
rm(ndarray) –Local mass-like residual terms, shape
(n_modes, N).