在我对具有恒定抽取因子的矢量进行下采样后,我想将矢量上采样回原始采样率(在执行某些分析之后)。但是,我正在努力进行上采样。
对于下采样,我从Accelerate框架应用vDSP_desamp,对于上采样,我尝试应用vDSP_vlint:
// Create some test data for input vector
float inputData[10] = {0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9};
int inputLength = 10;
int decimationFactor = 2; // Downsample by factor 2
int downSampledLength = inputLength/decimationFactor;
// Allocate downsampled output vector
float* downSampledData = malloc(downSampledLength*sizeof(float));
// Create filter (average samples)
float* filter = malloc(decimationFactor*sizeof(float));
for (int i = 0; i < decimationFactor; ++i){
filter[i] = 1.0/decimationFactor;
}
// Downsample and average
vDSP_desamp(inputData,
(vDSP_Stride) decimationFactor,
filter,
downSampledData,
(vDSP_Length) downSampledLength, // Downsample to 5 samples
(vDSP_Length) decimationFactor );
free(filter);
使用此代码的downSampledData
输出为:
0.05, 0.25, 0.45, 0.65, 0.85
要将(已处理的)数据向量上采样回原始采样率,请使用以下代码:
// For this example downSampledData is just copied to processedData ...
float* processedData = malloc(downSampledLength*sizeof(float));
processedData = downSampledData;
// Create vector used by vDSP_vlint to indicate interpolation constants.
float* b = malloc(downSampledLength*sizeof(float));
for (int i = 0; i < downSampledLength; i++) {
b[i] = i + 0.5;
}
// Allocate data vector for upsampled data
float* upSampledData = malloc(inputLength*sizeof(float));
// Upsample and interpolate
vDSP_vlint (processedData,
b,
1,
upSampledData,
1,
(vDSP_Length) inputLength, // Resample back to 10 samples
(vDSP_Length) downSampledLength);
但是,upSampledData
的输出是
0.15,0.35,0.55,0.75,0.43,0.05,0.05,0.05,0.08,0.12
显然不正确。我该如何申请vDSP_vlint
?或者我应该使用其他功能来对数据进行上采样?