PTB-M4D / PyDynamic

Python library for the analysis of dynamic measurements
https://ptb-m4d.github.io/PyDynamic/
GNU Lesser General Public License v3.0
26 stars 13 forks source link

Need for seperate high pass or low pass filter identification #157

Closed bruns01 closed 5 months ago

bruns01 commented 4 years ago

The current filter design function(s) like LSIIR(...) try to fit a generic band-pass without any boundary conditions in the frequency range. Sometimes it is useful to limit the class of filters to either high- or low-pass in order to focus on the modelling of a specific characteristic of a system. For high-pass that means

For a low pass it's kind of inverse

I ask for a new feature to get the functionality to decide the filter class for the fitting process to be high-, low- or band-pass, where "band-pass" means the current implementation.

BjoernLudwigPTB commented 4 years ago

We probably can utilize scipy.optimize.lsq_linear to achieve the desired behaviour during the fitting routine. We could introduce a bounds parameter to allow for user specified boundaries as specified in lsq_linear's documentation. A second step might be preparing common preset bounds like "high", "low".

This is the result of today's discussion between @mgrub and @BjoernLudwigPTB .

@bruns01 Would a reference implementation to clone and try out be sufficient? Otherwise we could prepare a release candidate to allow for installation something like pip install PyDynamic==1.4.4-rc.

bruns01 commented 4 years ago

1) A reference implementation for testing is welcome. 2) I remember to have encountered problems with linear fit approximation in my own attempts. I blamed the rational function vs. linear fitting issue for the dissimilarity of the outcome. However, the current LSIIR functions do follow a linear fitting scheme, too, if I remember correctly. Hence, this would mean a totally different story.

BjoernLudwigPTB commented 4 years ago

This commit could possibly resolve the issue already for

bounds = (np.array([b0, -np.inf, ..., -np.inf]), np.array([b0, np.inf, ..., np.inf]))

with preceding b0=0 for the high-pass and b0=S0 for the low-pass. We will carry on with some thorough testing from next week tuesday.

The call should work as before with appended bounds parameter:

a, b, tau = LSIIR( Hvals, Nb, Na, f, Fs, bounds=bounds)
BjoernLudwigPTB commented 4 years ago

@bruns01 To test this implementation setup a test environment and install PyDynamic via

pip install git+https://github.com/PTB-PSt1/PyDynamic.git@improve_LSIIR

We adapted the corresponding example as noted above. Please observe, if this fits your needs. We would be really happy to hear if this is, what you were looking for.

BjoernLudwigPTB commented 5 months ago

We close this now as it stalled long time ago.