Fix one-bin frequency shift in get_response (fixes #3) - #5
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. The 0 Hz FRF is computed where it is defined and left at zero where the impedance matrix is singular (unconstrained systems), so get_response never fails at 0 Hz while still reproducing get_FRF_matrix at every other bin. The 'f' and 't' domains share the same frequency handling. test_response is updated to align its reference grid and to exclude the 0 Hz bin from the comparison (by removing the time-domain mean).
jankoslavic
force-pushed
the
fix/get_response-freq-vector
branch
from
July 27, 2026 19:01
e38c710 to
c852829
Compare
Author
|
Closing for now — nothing actually depends on this. The pyFRF tests that surfaced it compare against get_response(return_matrix=True) (the exact FRF used to synthesise the data), so they pass with or without this change. The underlying one-bin inconsistency between get_response and get_FRF_matrix is left documented in #3 for whenever it's worth addressing. |
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:
The 0 Hz FRF is kept where it is defined (grounded systems →
inv(K)) and left at zero where the impedance matrix is singular (unconstrained / free systems,frf_method="f"), soget_responsenever fails at 0 Hz while reproducingget_FRF_matrixat every other bin:The
"f"and"t"domains share this handling.Verification
get_response(return_matrix=True)equalsget_FRF_matrixat every bin, DC included.both/left/right/free, bothfrf_methods, both domains all run and stay finite (previouslyfree+"f"raisedLinAlgErrorat DC).domain="f"anddomain="t"responses agree.test_responsenow aligns its reference grid and excludes the 0 Hz bin from the comparison (by removing the time-domain mean, which zeros exactly the DC bin).Found while adding pyLump-based cross-validation tests to pyFRF.