#include <stdio.h>
void downsample(const short *input, int inputSize, short *output, int outputSize) {
int ratio = inputSize / outputSize;
for (int i = 0; i < outputSize; ++i) {
int start = i * ratio;
int sum = 0;
for (int j = start; j < start + ratio; ++j) {
sum += input[j];
}
output[i] = sum / ratio;
}
}
int main() {
// 假设有一个原始音频数据 input,长度为 inputSize
short input[] = { /* 原始音频数据 */ };
int inputSize = sizeof(input) / sizeof(short);
int outputSize = inputSize / 2; // 降低采样率为原来的一半
short output[outputSize];
downsample(input, inputSize, output, outputSize);
// 输出降采样后的音频数据
for (int i = 0; i < outputSize; ++i) {
printf("%d ", output[i]);
}
return 0;
}
文章来源:https://www.toymoban.com/news/detail-647142.html
import math
ll = 3 # out put len, down sample len
a=[10,9,3,4,5,2,11,45,90,17,12,49,32,40,53,32,11,45,90,17]
b=[0]*ll
r= len(a)/ll
start = 0
ed =0
for ni in range(ll):
start = ed
ed = round(ni*r+r)
sm = 0
cnt =0
#print('stat',start,start+r)
for oi in range(start,ed):
print(oi)
sm += a[oi]
cnt = cnt +1
#print(cnt,sm)
b[ni]=int(sm/cnt)
print(b)
保障每个样本都被用到了。文章来源地址https://www.toymoban.com/news/detail-647142.html
到了这里,关于chat gpt实现的降采样算法的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!