chat gpt实现的降采样算法

#include 

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;
}

chat gpt实现的降采样算法_第1张图片

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)

    

保障每个样本都被用到了。

你可能感兴趣的:(算法,gpt)