Ios 使用accelerate对数据进行上采样时遇到的问题

Ios 使用accelerate对数据进行上采样时遇到的问题,ios,objective-c,c,iphone,accelerate,Ios,Objective C,C,Iphone,Accelerate,在我用一个恒定的抽取因子对一个向量进行下采样之后,我想将向量上采样回到原始采样率(在执行一些分析之后)。然而,我正在努力进行上采样 对于下采样,我从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 inputLen

在我用一个恒定的抽取因子对一个向量进行下采样之后,我想将向量上采样回到原始采样率(在执行一些分析之后)。然而,我正在努力进行上采样

对于下采样,我从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);
要将(处理过的)数据向量上采样回原始采样率,我使用以下代码:

// 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);
//在本例中,下采样数据只是复制到processedData。。。
float*processedData=malloc(下采样长度*sizeof(float));
processedData=下采样数据;
//创建vDSP_vlint用于指示插值常数的向量。
float*b=malloc(下采样长度*sizeof(float));
对于(int i=0;i
但是,
upSampledData
的输出是

0.15,0.35,0.55,0.75,0.43,0.05,0.05,0.05,0.08,0.12

这显然是不正确的。我应该如何应用
vDSP\u vlint
?还是应该使用其他函数对数据进行上采样

// 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);