FIRフィルタの実装3 Circular Buffer


// N : number of coefficients
// h(n) : filter coefficients, n = 0,…N-1
// x(n) : stored input data, n = 0,…2N-1
// input sample : variable that contains the newest input sample
// index : variable that contains the current place where the new sample is to be stored

x[index] = input_sample
// Filter the data
ynew = 0;
for (i=0;i<N;i++){
    if((index-i)<0){
        ynew = ynew + h[i]*x[index-i+N];
    } else {
        ynew = ynew + h[i]*x[index-i];
    }
}
index = (index+1)%N;