-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Schmitt Trigger Block with Uncertainty Support and Optional Interpolation #476
Conversation
0a843d7
to
ebc8a15
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried to look into it but got stuck trying to get it to compile and it was not clear to me what the right direction to fix this would be.
But overall looks very nice, I suspect this was something that was changed last minute and missed a few parts of the code.
EDIT: after writing this I gave it one more quick try with more understanding and got it working. I also added fixup commits for the code formatting.
requires(std::is_arithmetic_v<T> or (UncertainValueLike<T> && std::is_arithmetic_v<meta::fundamental_base_value_type_t<T>>)) | ||
struct SchmittTrigger { | ||
using value_t = meta::fundamental_base_value_type_t<T>; | ||
using EdgeType = std::conditional_t<std::is_floating_point_v<value_t>, T, float>; // float being used for integer types |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not clear to me and seems like it causes inconsistent types:
T -> EdgeType
double
->double
int ->
float` <= special caseUncertainValue<double>
->UncertainValue<double>
UncertainValue<int>
-> ``float` !!! inconsistency? would have to be handled explicitly in the rest of the code which it looks like it isn't.
// edge timing variables | ||
EdgeDetection lastEdge = EdgeDetection::NONE; | ||
EdgeType lastEdgeIdx{1}; /// relative index [-EdgeType|_MAX,1[ w.r.t. current sample of the last detected edge | ||
EdgeType lastEdgeOffset{0}; /// relative sub-sample offset [0, 1[ w.r.t. current sample of the last detected edge |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would mean that for integer datatype the position could only be 0 or 1?
Maybe we need an input and an output datatype?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The thing is that -- normally it's:
float
->float
double
->double
UncertainValue<float>
->UncertainValue<float>
UncertainValue<double>
->UncertainValue<double>
The integer types are a bit special because while the vertical values are discrete, the time-offsets aren't, thus my choice to default to float
or UncertainValue<float>
for them. Was also temporarily contemplating keeping them all as float
or UncertainValue<float>
but this would complicate the downstream logic probably.
My goal was first to have a viable working solution and to see how it works out in the field.
ebc8a15
to
0e521e5
Compare
0043518
to
91f9731
Compare
14d6234
to
f319c57
Compare
Also: * fixed '<=>' operator for when comparing with non-UncertainValue<T> * fixed up-conversion warning in UncertainValue.hpp * upgraded UncertainValue fmt-formatter to support number format specifiers Signed-off-by: rstein <[email protected]> Signed-off-by: Ralph J. Steinhagen <[email protected]>
Signed-off-by: Ralph J. Steinhagen <[email protected]>
implements a SchmittTrigger block with edge detection and optional interpolation Signed-off-by: rstein <[email protected]> Signed-off-by: Ralph J. Steinhagen <[email protected]>
f319c57
to
4665d84
Compare
Quality Gate failedFailed conditions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks really nice, thanks for the nice implementation, documentation, tests and issue follow-up. 👍
This PR introduces a new digitial
SchmittTrigger
block with configurable threshold and offset, as well as sub-sample edge timing interpolation options.Features
threshold
andoffset
values.NO_INTERPOLATION
: basic detection without interpolation.BASIC_LINEAR_INTERPOLATION
: simple linear interpolation between adjacent samples.LINEAR_INTERPOLATION
: linear regression over the samples within the threshold window.POLYNOMIAL_INTERPOLATION
: (TODO) Placeholder for future implementation using Savitzky–Golay filters.trigger_name_rising_edge
,trigger_name_falling_edge
)FIXME and TODOs
FIXME: In the
processBulk
method, there's a commented-out section related to input sample buffering and history. This needs to be revisited to ensure proper operation, especially when using interpolation methods that require a history buffer. The error seems to be unrelated to the underlying algorithm and probably also chosen block implementation (tbc.). To be followed up in the GR4 if that is the case.TODO: The
POLYNOMIAL_INTERPOLATION
method has not yet been implemented and requires the pendingTensor<T>
and SVD implementations. This will be addressed in a future update.