Skip to content

Add filter-reading support to MTH5 - #1

Draft
kujaku11 wants to merge 11 commits into
yoshiya-usui:mainfrom
kujaku11:mth5
Draft

Add filter-reading support to MTH5#1
kujaku11 wants to merge 11 commits into
yoshiya-usui:mainfrom
kujaku11:mth5

Conversation

@kujaku11

Copy link
Copy Markdown

The current functionality of reading an MTH5 only reads the data and the calibrations/filters are skipped for now unless the user creates files for them. This PR aims at adding functionality to the MTH5 class to get the filters directly from the MTH5 file.

Add filter-reading functionality to MTH5: introduce FilterInfo struct, HDF5 string attribute helpers, and methods to read filter names and filter objects (readFilter, readFilterNamesFromChannel, getChannelFilters). Update MTH5.cpp/h to include attribute parsing, path resolution for Filters groups, name normalization, and basic scanning of filter type groups (zpk, coefficient, time_delay, fap, fir). Include logging via OutputFiles and proper HDF5 resource cleanup. Add usage documentation (MTH5_FILTER_READING.md) and an example program (MTH5_filter_example.cpp). Implementation currently reads metadata and names (filter.name) and leaves detailed per-type dataset parsing as TODOs for future enhancement.

yoshiya-usui and others added 10 commits August 29, 2025 16:00
Add filter-reading functionality to MTH5: introduce FilterInfo struct, HDF5 string attribute helpers, and methods to read filter names and filter objects (readFilter, readFilterNamesFromChannel, getChannelFilters). Update MTH5.cpp/h to include attribute parsing, path resolution for Filters groups, name normalization, and basic scanning of filter type groups (zpk, coefficient, time_delay, fap, fir). Include logging via OutputFiles and proper HDF5 resource cleanup. Add usage documentation (MTH5_FILTER_READING.md) and an example program (MTH5_filter_example.cpp). Implementation currently reads metadata and names (filter.name) and leaves detailed per-type dataset parsing as TODOs for future enhancement.
@kujaku11

Copy link
Copy Markdown
Author

@yoshiya-usui I'm not great at C++ so I had some help with copilot to add some functionality to the MTH5 for getting the filters directly from the MTH5. I still need to format the filter into real and imaginary and probably a few more things before this PR is ready. But if you could have a look and comment the structure and hints on how to ensure the functionality works for the workflow of TRACMT.

@yoshiya-usui

Copy link
Copy Markdown
Owner

Thank you for informing me how to add functionality to the MTH5 class to get the filters directly from the MTH5 and for giving me a sample program.
I thought it was smarter to read calibrations/filters directly from MTH5 and use them in the analysis.
One of the reasons I did not implement such a function was that I was not familiar with some filter type groups.
Are there any documents describing the details of individual filter type groups?
Once how to convert them to real and imaginary parts (or amplitude and phase) becomes clear, the implementation may not be difficult.
One way is to support the most widely used type of calibrations/filters, for the moment.
Anyway, I will check your implementation.
However, it may take at least several days.

@kujaku11

Copy link
Copy Markdown
Author

@yoshiya-usui Some documentation on the supported filters stored in an mth5 file is here: https://mth5.readthedocs.io/en/latest/examples/notebooks/filters_example.html. Commonly what we do is take all the filters and make a total channel response which incorporates all the gains, and frequency dependent responses. Those are in frequency, amplitude, phase format now, but could easily be changed to real and imaginary, like in the TRACMT calibration function https://github.com/yoshiya-usui/TRACMT/blob/main/src/CalibrationFunction.cpp.

Sort channel filters by sequence number and add facilities to validate and combine them into a ChannelResponse. Introduces ChannelResponse struct in MTH5.h and three new methods in MTH5.cpp: validateFilterUnits (checks sequence ordering and unit consistency), createChannelResponse (builds a response from a filter list and sets units/normalization), and getChannelResponse (convenience wrapper that loads filters and creates the response). Also logs operations and errors, and adds declarations for the new methods in the header.
@yoshiya-usui

Copy link
Copy Markdown
Owner

Thank you so much for giving detailed information and very insightful modification plans.
Now I am modifying the code based on your suggestions.
Hopefully, I will give an idea of my implementation tomorrow.

@yoshiya-usui

yoshiya-usui commented Feb 20, 2026

Copy link
Copy Markdown
Owner

I send a reply to your gmail address, as follows, because I am not used to the functions of GitHub (e.g., branching).
I am sending my idea of how to read and apply filters in TRACMT and the modified source codes.
I checked that the codes can be built, but I have never tested the code.
Moreover, some parts have not implemented, for example, reading functions of each filter characteristic.

Your code is definitely smart.
I am sorry that I degraded some parts of your implementations.
Because my code is basically written following C++98, I replaced some parts using modern C++ functions to make a consistency with the existing sources.
I changed the code to use the pointer of the filter class because polymorphic procedures can be implemented easily using pointers, at least in my experience with old C++.

I implemented the functions to calculate the frequency response of each filter, tentatively.
But, probably, there are many bugs.

I have some questions.
About the FIR filter, it must be symmetric, and only half of the coefficients are stored in MTH5, right?
Is the number of the coefficient necessarily even?

To correct the Fourier transforms by dividing the response functions, the order of filters should be reversed, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants