|
SynchroPMU
C implementation of the Phasor Measurement Unit Estimator based on the Iterative Interpolated DFT Synchrophasor Estimation Algorithm
|
Implementation of the PMU estimator based on the Iterative Enhanced Interpolated DFT Algorithm. More...
#include <stdio.h>#include <complex.h>#include <math.h>#include <stdlib.h>#include "iniparser.h"#include "pmu_estimator.h"
Macros | |
| #define | NUM_CHANLS 1 |
| Number of channels to process (can be defined at compile time) | |
| #define | DEBUG 3 |
| Debug logging level - includes all messages. | |
| #define | INFO 2 |
| Info logging level - includes info and error messages. | |
| #define | ERROR 1 |
| Error logging level - only error messages. | |
| #define | LOGGING_LEVEL ERROR |
| Current logging level (can be defined at compile time) | |
| #define | error(...) fprintf(stderr, __VA_ARGS__) |
| Error logging macro - outputs to stderr. | |
| #define | info(...) |
| Info logging macro - outputs to stdout. | |
| #define | debug(...) |
| Debug logging macro - outputs to stdout. | |
| #define | debug_bins(...) |
| #define | wrap_angle(rad) (((float_p)(rad) - 2 * M_PI_p * rint((float_p)(rad) / (2 * M_PI_p)))) |
| Wraps an angle to the range [-π, π] radians. | |
| #define | sineasin(x) (pmue_sin(M_PI_p * (x)) / pmue_sin(ctx->hann_params.C4 * M_PI_p * (x))) |
| Sine-over-sine ratio used in Hanning window DFT. | |
| #define | whDFT(x) (pmue_cexp(-I * M_PI_p * ctx->hann_params.C3 * (x)) * (ctx->hann_params.C5 * sineasin((x) - 1) + ctx->hann_params.C1 * sineasin((x)) + ctx->hann_params.C6 * sineasin((x) + 1))) |
| Hanning window DFT formula. | |
| #define | wf(k, f, in_phsr) ((in_phsr) * whDFT((k) - ((f) / ctx->synch_params.df)) * (ctx->hann_params.inv_norm_factor)) |
| Weighted frequency bin calculation. | |
Functions | |
| int | pmu_init (pmu_context *ctx, void *cfg, bool_p config_from_ini) |
| Initialize a PMU estimator instance. | |
| int | pmu_estimate (pmu_context *ctx, float_p *in_signal_windows, float_p mid_fracsec, pmu_frame *out_frame) |
| Estimate synchrophasor, frequency, and ROCOF from input signal. | |
| int | pmu_deinit (pmu_context *ctx) |
| Deinitialize and free resources of PMU estimator instance. | |
| int | pmu_dump_frame (pmu_frame *frame, FILE *stream) |
| Print PMU frame data to output stream. | |
Implementation of the PMU estimator based on the Iterative Enhanced Interpolated DFT Algorithm.
This file contains the complete implementation of a Phasor Measurement Unit (PMU) estimator that uses advanced signal processing techniques to accurately estimate synchrophasors, frequency, and Rate of Change of Frequency (ROCOF) from power system signals.
The implementation uses the Iterative Enhanced Interpolated DFT (Discrete Fourier Transform) algorithm with the following key features:
| #define DEBUG 3 |
Debug logging level - includes all messages.
| #define debug | ( | ... | ) |
Debug logging macro - outputs to stdout.
| #define debug_bins | ( | ... | ) |
| #define ERROR 1 |
Error logging level - only error messages.
| #define error | ( | ... | ) | fprintf(stderr, __VA_ARGS__) |
Error logging macro - outputs to stderr.
| #define INFO 2 |
Info logging level - includes info and error messages.
| #define info | ( | ... | ) |
Info logging macro - outputs to stdout.
| #define LOGGING_LEVEL ERROR |
Current logging level (can be defined at compile time)
| #define NUM_CHANLS 1 |
Number of channels to process (can be defined at compile time)
Sine-over-sine ratio used in Hanning window DFT.
| #define wf | ( | k, | |
| f, | |||
| in_phsr ) ((in_phsr) * whDFT((k) - ((f) / ctx->synch_params.df)) * (ctx->hann_params.inv_norm_factor)) |
Weighted frequency bin calculation.
| #define whDFT | ( | x | ) | (pmue_cexp(-I * M_PI_p * ctx->hann_params.C3 * (x)) * (ctx->hann_params.C5 * sineasin((x) - 1) + ctx->hann_params.C1 * sineasin((x)) + ctx->hann_params.C6 * sineasin((x) + 1))) |
Hanning window DFT formula.
Wraps an angle to the range [-π, π] radians.
| int pmu_deinit | ( | pmu_context * | ctx | ) |
Deinitialize and free resources of PMU estimator instance.
Releases all dynamically allocated memory associated with the PMU context and resets the initialization flag. After calling this function, the context can be reinitialized with pmu_init() if needed.
| [in,out] | ctx | Pointer to the PMU context to deinitialize |
| int pmu_dump_frame | ( | pmu_frame * | frame, |
| FILE * | stream ) |
Print PMU frame data to output stream.
Outputs the contents of a pmu_frame structure in a human-readable format to the specified output stream (e.g., stdout, stderr, or a file).
| [in] | frame | Pointer to the PMU frame to dump |
| [in] | stream | Output stream (e.g., stdout, stderr, or FILE pointer from fopen) |
| int pmu_estimate | ( | pmu_context * | ctx, |
| float_p * | in_signal_windows, | ||
| float_p | mid_fracsec, | ||
| pmu_frame * | out_frame ) |
Estimate synchrophasor, frequency, and ROCOF from input signal.
This is the main estimation function that processes a window of input samples and produces synchrophasor and ROCOF estimates using the Iterative Enhanced Interpolated DFT algorithm.
| [in] | ctx | Pointer to initialized PMU context |
| [in] | in_signal_windows | Pointer to input signal samples. For multi-channel: array of pointers to signal windows for each channel. Array size must match NUM_CHANLS configuration. |
| [in] | mid_fracsec | Fractional second timestamp (relative to PPS) of the midpoint of the observation window. Used for phase correction. |
| [out] | out_frame | Pointer to output PMU frame structure where results are stored |
| int pmu_init | ( | pmu_context * | ctx, |
| void * | cfg, | ||
| bool_p | config_from_ini ) |
Initialize a PMU estimator instance.
Initializes a PMU estimator context with the specified configuration. The configuration can be loaded from an INI file or passed as a structure.
| [in,out] | ctx | Pointer to the PMU context structure to initialize |
| [in] | cfg | Configuration: either a filename (char*) if config_from_ini=1, or a pointer to an estimator_config structure if config_from_ini=0 |
| [in] | config_from_ini | Configuration source flag:
|