Repository navigation
Conversation
Adds to pytta.functions three spectrum utilities that the ITA-Toolbox has: psd (ita_psd, the power or cross power spectral density by Welch averaging with the window, overlap and convention of MATLAB cpsd), interpolate_spectrum (ita_interpolate_spk, the DFT interpolated onto the bins of another length, by spline or linearly, on real and imaginary parts or on magnitude and phase) and extrapolate_low (the lower extrapolation of ita_spk_extrapolate, mean magnitude with an optional slope and the linear phase of the mean group delay). Tests check the densities against MATLAB cpsd on golden data from tests/golden/make_psd_matlab.m (3.4e-8 relative) and Parseval, that the interpolated spectrum of a one-pole filter follows its true response (1.4e-6), and that the extrapolation keeps a pure delay and gives the slope asked for. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This branch has not been deployed
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.
Adds to
pytta.functionsthree spectrum utilities that the ITA-Toolbox has:psd(signal, signal2=None, block_size=None, fft_size=None): the power spectral density of each channel, or the cross power spectral density withsignal2, asita_psd. It uses Welch averaging with a symmetric Hann window of the block size (the whole signal by default) and half-block overlap, one-sided, in units²/Hz. The cross spectrum follows the convention of MATLABcpsd, whichita_psdcalls, X conj(Y). That is the conjugate ofscipy.signal.csd.interpolate_spectrum(signal, n_samples, method='spline', abs_phase=False): the DFT interpolated onto the bins of another length, asita_interpolate_spk. The interpolation is by spline, as MATLABinterp1, or linear, on real and imaginary parts or on magnitude and unwrapped phase. It is meant for impulse responses.extrapolate_low(signal, freq_range, slope=0): the spectrum belowfreq_rangereplaced by its mean magnitude there, changed byslopedB per decade. The phase is linear, from the mean group delay of the range, and joins the phase at its lower end. This is the lower part ofita_spk_extrapolate, whose upper part is not implemented in the ITA-Toolbox either.Four other spectrum functions of the ITA-Toolbox are not included here.
ita_split_frequenciesrelies on the channel naming of the ITA-Toolbox.ita_extrapolateneeds a rational fit of poles and zeros.ita_smooth_notchesandita_lifterneedsmooth_frequency(#50), the cepstrum (#80),start_ir(#96) andtime_window(#49), so they can follow once those are merged.ita_decimate_spkwas also left out, since what its phase reconstruction should preserve is not clear from the code.The tests in
tests/test_spectrum.pyprint the measured differences:cpsd, called asita_psdcalls it, within 3.4e-8 relative (golden data fromtests/golden/make_psd_matlab.m). The integral of the density is the variance within 0.4 %.Checked with Python 3.12, numpy 1.26 and scipy 1.17. The 7 failures of
development(3 intest_h5io.py, 4 intest_pyttasave.py) are the same with and without this change.Co-Authored-By: Claude Fable 5.1 noreply@anthropic.com