Fix one-bin frequency shift in get_response (fixes #3) - #4
Closed
jankoslavic wants to merge 1 commit into
Closed
Conversation
get_response built its frequency vector as `arange(1, len_freq+1) * df` (starting at df to "avoid zero frequency"), offset by one bin from the rfft bins of the excitation. Multiplying `H(freq[i])` by `rfft(exc)[i]` therefore paired the FRF at (i+1)*df with the spectrum at i*df, shifting the synthesised FRF by one bin relative to get_FRF_matrix. Use the aligned grid `np.fft.rfftfreq(N, 1/fs)`, which includes the 0 Hz (rigid-body / static) term, and compute the FRF at every bin. get_response now reproduces get_FRF_matrix bin-for-bin, including DC. Updates test_response, which previously encoded the shifted grid in its reference.
jankoslavic
force-pushed
the
fix/get_response-frequency-alignment
branch
from
July 27, 2026 18:47
23fceb7 to
ae49591
Compare
Author
|
Superseded by #5, which contains the same reviewed fix (aligned rfftfreq grid including 0 Hz) from a clean branch. |
Author
|
This does not make sense. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #3 —
get_response(domain="f")synthesised responses using an FRF shifted by one frequency bin relative toget_FRF_matrix.Root cause
get_responsebuilt its frequency vector asi.e.
[1·df, 2·df, …], starting atdf. ButEXC = np.fft.rfft(exc)has its bins at[0, df, 2·df, …]. The response loop then multipliesmatrix[..., i](the FRF at(i+1)·df) byEXC[:, i](the spectrum ati·df), so the synthesised transfer function is shifted up by one bin:H_used[k] == get_FRF_matrix[k+1].Fix
Use the aligned rfft grid, which includes the 0 Hz (rigid-body / static) term, and compute the FRF at every bin — this is the previously commented-out
# oldline:get_responsenow reproducesget_FRF_matrixbin-for-bin, DC included.Verification
get_response(return_matrix=True)now equalsget_FRF_matrixat every bin, including DC.domain="f"anddomain="t"responses agree.test_responseupdated — it previously encoded the shifted grid, minus 0 Hz, in its reference).Note on unconstrained ("free") systems at 0 Hz
Because 0 Hz is now included,
get_response/get_FRF_matrixbehave identically at DC — which for afreesystem means the impedance-inverse method (frf_method="f") raisesLinAlgErrorthere (the stiffness matrix is singular for the rigid-body mode;H(0)is theoretically infinite). The state-space method (frf_method="s") computes it fine. This matchesget_FRF_matrix's existing behaviour, so the two are consistent. If you'd like the"f"method to also return something usable at 0 Hz for unconstrained systems (e.g. via a pseudo-inverse), that would be a separate change toget_FRF_matrix— happy to follow up.Found while adding pyLump-based cross-validation tests to pyFRF.