SEL CWS: user-selectable sliding-DFT and IEEE C37.118 phase estimation#21
Merged
Conversation
Lets users choose, via SEL CWS connection parameters, between the rolling
sliding DFT estimator (optional EMA smoothing, default) and the IEEE
C37.118-2018 Annex D filter-based estimator (P/M class); brings Gemstone
back in sync with the GSF implementation.
- Shared PhaseEstimate/PhaseEstimateHandler + IPhaseEstimator; new
PhaseEstimationAlgorithm { SlidingDft, IEEEC37_118 } enum
- SlidingDftPhaseEstimator + IEEEC37_118PhaseEstimator replace
RollingPhaseEstimator; both use VA,VB,VC,IA,IB,IC order (completes the
voltage/current alignment, fixing the IEEE positive-sequence indexing)
- ConnectionParameters: Algorithm selector + sliding-DFT options grouped
into General / Sliding DFT / IEEE C37.118 property categories
- FrameParser builds the selected estimator, rebuilding on parameter change
- Replaced the console demo with MSTest unit tests (9 sliding DFT + 6 IEEE)
…tructor or destructor' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
The initial CWS data frame spans 48 bytes: 16-byte common header + 8-byte nanosecond timestamp + first 24-byte sample. ParseFrame advanced only 32 (timestamp + first sample) before parsing the remaining 49 samples, omitting the common header. This read samples 1-49 of every packet 16 bytes (4 analog channels) too early, scrambling channel/sample alignment -- only the first sample of each 50-sample packet was correct -- and corrupting derived phase estimates. Advance offset/length by 48 instead of 32 so all 50 samples align and sample 49 ends exactly at the 1224-byte frame boundary. On-wire framing and the voltage-first channel order (VA,VB,VC,IA,IB,IC) were already correct.
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
Adds two user-selectable phasor/frequency/ROCOF estimation algorithms to the SEL CWS
protocol, chosen via connection parameters:
This re-syncs Gemstone with the matching GSF implementation. (Gemstone had previously
replaced the sliding DFT with the IEEE algorithm for the PNNL project; this restores
both and makes the choice configurable.)
ALSO: Includes fix for SEL CWS data-frame sample misalignment (samples 1-49 read 16 bytes early)
What changed
PhaseEstimationAlgorithm { SlidingDft, IEEEC37_118 }enumIPhaseEstimator; replace the previousRollingPhaseEstimatorAlgorithmselector + sliding-DFT options, grouped intoGeneral / Sliding DFT / IEEE C37.118 property-grid categories
Notes for reviewers
SlidingDft(consistent with GSF). This changes Gemstone's defaultbehavior, which previously always used the IEEE estimator — set
Algorithm = IEEEC37_118to retain the prior behavior.
completing the alignment from "Updated voltage/current orders" (the IEEE positive-sequence
was previously computed from the current channels).
IPhaseEstimatorare public (matching the prior publicRollingPhaseEstimator).UnitTestsproject had no reference to the library; added aProjectReference.SEL Offset Fix Summary
FrameParser.ParseFrameadvanced the buffer by 32 bytes (timestamp +first sample) after the base parser handled sample 0, omitting the 16-byte
common header. Samples 1-49 of every 50-sample packet were therefore read 16
bytes (4 analog channels) too early.
[VC(prev), IA(prev), IB(prev), IC(prev), VA(cur), VB(cur)]mislabeled as[VA,VB,VC,IA,IB,IC]; only thefirst sample per packet was correct, corrupting analog values and phase
estimates.
offset/lengthby 48 (header 16 + timestamp 8 + first sample24) so all 50 samples align; sample 49 now ends exactly at the 1224-byte
frame boundary.
Root cause
base.ParseFrametakesoffsetby value and leaves the caller's offset at theframe start, so the manual loop must skip the entire initial frame (48 bytes),
not just its body (32). The bare
32literal hid the missing header.Not affected
On-wire framing and the voltage-first channel order (VA,VB,VC,IA,IB,IC,
confirmed by config-frame SignalNames) parse correctly. This was a local
offset-arithmetic defect, not a protocol/device issue.