Pwelch
The Welch method estimates the power spectral density of a modified periodogram. It windows data, calculates the power spectral density of the data in the windows, and then averages the obtained values.
The function interface declaration is as follows:
HmppResult HMPPS_Pwelch_32f(const float* src, const float* window, float* dst, int32_t len, double overLap, int32_t nfft, int32_t windowLen);
HmppResult HMPPS_Pwelch_64f(const double* src, const double* window, double* dst, int32_t len, double overLap, int32_t nfft, int32_t windowLen);
HmppResult HMPPS_Pwelch_32fc(const Hmpp32fc* src, const float* window, float* dst, int32_t len, double overLap, int32_t nfft, int32_t windowLen);
HmppResult HMPPS_Pwelch_64fc(const Hmpp64fc* src, const double* window, double* dst, int32_t len, double overLap, int32_t nfft, int32_t windowLen);
Parameters
Parameter |
Description |
Value Range |
Input/Output |
|---|---|---|---|
src |
Pointer to the array that stores the source signal vector |
The value cannot be NULL. |
Input |
window |
Pointer to the array that stores the window vector |
This parameter can be NULL. If this parameter is left empty, the default value is 1. The length is windowLen. |
Input |
dst |
Estimated array of power spectral density |
The value cannot be NULL. |
Output |
overlap |
Ratio of the overlapping part between two adjacent segments to the window length |
(0, 0.95] |
Input |
nfft |
Number of FFT points |
The value is within the range [INT_MIN, windowLen]. If the value is less than 0, the default value of windowLen is used. |
Input |
len |
Length of the source signal vector |
(0, INT_MAX] |
Input |
windowLen |
Length of the window vector |
(0, len] |
Input |
Return Value
- Success: HMPP_STS_NO_ERR
- Failure: An error code is returned.
Error Codes
Error Code |
Description |
|---|---|
HMPP_STS_NULL_PTR_ERR |
The value of src or dst is NULL. |
HMPP_STS_SIZE_ERR |
The value of len is less than or equal to 0. |
HMPP_SYS_MALLOC_FAILED |
The malloc function fails to be executed. |
Example
#define BUFFER_SIZE_T 5
#define NFFT 2
#define WINDOWLEN 2
#define OVERLAP 0.5
void PwelchExample()
{
float src[BUFFER_SIZE_T] = {1, 2.5, 3.3, 1, 5};
float window[2] = {1,1};
float dst[BUFFER_SIZE_T];
HMPPS_Zero_32f(dst, BUFFER_SIZE_T); //Initialize all elements of dst to 0.
HmppResult result = HMPPS_Pwelch_32f(src, window, dst, BUFFER_SIZE_T, OVERLAP, WINDOWLEN, NFFT);
if (result == HMPP_STS_NO_ERR) {
printf("dst = ");
for (int32_t i = 0; i < (NFFT + 1) / 2; i++) {
printf("%.2f ", dst[i]);
}
printf("\n");
}
}
Output:
dst = 0.97 0.18