SampleDown
Performs signal down-sampling, that is, use a sampling factor to reduce the sampling rate.
Specifically, down-sampling means that the source sampling sequence src is sequentially divided into several blocks, and each block contains factor numbers of sampling points. (factor – 1) sampling points in the blocks are discarded, and the remaining one sampling point is stored to dst. phase is the phase of the source sampling sequence, and it determines the position of the sampling point to be reserved in each block. The value range of phase is [0, factor – 1]. The length of the sampling result sequence is stored in the position pointed to by dstLen.
The processing manner may be described with the following formula:
;
;
.
The function interface declaration is as follows:
- Operations on integers:
HmppResult HMPPS_SampleDown_16s(const int16_t *src, int32_t srcLen, int16_t *dst, int32_t *dstLen, int32_t factor,int32_t *phase);
HmppResult HMPPS_SampleDown_16sc(const Hmpp16sc *src, int32_t srcLen, Hmpp16sc *dst, int32_t *dstLen, int32_t factor,int32_t *phase);
- Operations on floating-point numbers:
HmppResult HMPPS_SampleDown_32f(const float *src, int32_t srcLen, float *dst, int32_t *dstLen, int32_t factor, int32_t *phase);
HmppResult HMPPS_SampleDown_64f(const double *src, int32_t srcLen, double *dst, int32_t *dstLen, int32_t factor, int32_t *phase);
HmppResult HMPPS_SampleDown_32fc(const Hmpp32fc *src, int32_t srcLen, Hmpp32fc *dst, int32_t *dstLen, int32_t factor, int32_t *phase);
HmppResult HMPPS_SampleDown_64fc(const Hmpp64fc *src, int32_t srcLen, Hmpp64fc *dst, int32_t *dstLen, int32_t factor, int32_t *phase);
Parameters
Parameter |
Description |
Value Range |
Input/Output |
|---|---|---|---|
src |
Pointer to the source vector |
The value cannot be NULL. |
Input |
srcLen |
Length of the source vector |
(0, INT_MAX] |
Input |
dst |
Pointer to the destination vector |
The value cannot be NULL. |
Output |
dstLen |
Pointer to the length of the destination vector |
The value cannot be NULL. |
Output |
factor |
Sampling factor |
(0, INT_MAX] |
Input |
phase |
Pointer to the sampling phase |
Not empty and within the range [0, factor) |
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, dst, dstLen, or phase is NULL. |
HMPP_STS_SIZE_ERR |
The value of srcLen is less than or equal to 0. |
HMPP_STS_SAMPLE_FACTOR_ERR |
The sampling factor is less than or equal to 0. |
HMPP_STS_SAMPLE_PHASE_ERR |
The sampling phase is less than 0 or greater than or equal to factor. |
Example
#define BUFFER_SIZE_S 9
void SampleDownExample(void)
{
Hmpp16sc src1[BUFFER_SIZE_S] = { 14761, -14761, -9981, 9381, 286, -7115, -15360, -7959, -26648, -13094,
-29344, -999, -12922, 8793, -21146, 12262, 1568, -6382 };
Hmpp16sc src2[BUFFER_SIZE_S] = { 30000, -30000, -9976, 9976, -848, -2080, -22268, -32406, 29451, 8620,
19416, -30118, -31166, -28113, -11331, -8179, -30595, 14322 };
Hmpp16sc dst[65] = { 0 };
int32_t dstLen1 = 0;
int32_t dstLen2 = 0;
int32_t factor = 4;
int32_t phase = 2;
HmppResult result;
result = HMPPS_SampleDown_16sc(src1, BUFFER_SIZE_S, dst, &dstLen1, factor, &phase);
result |= HMPPS_SampleDown_16sc(src2, BUFFER_SIZE_S, dst + dstLen1, &dstLen2, factor, &phase);
printf("result = %d\n", result);
if (result != HMPP_STS_NO_ERR) {
return;
}
int32_t i = 0;
printf("dstLen1 = %d\ndst1 =", dstLen1);
for(; i < dstLen1; ++i){
printf(" %d %d ", dst[i].re, dst[i].im);
}
printf("\ndstLen2 = %d\ndst2 =", dstLen1);
for(; i < dstLen1 + dstLen2; ++i){
printf(" %d %d ", dst[i].re, dst[i].im);
}
printf("\n");
}
Output:
result = 0 dstLen1 = 2 dst1 = 286 -7115 -12922 8793 dstLen2 = 2 dst2 = -9976 9976 19416 -30118