所以,我已經實現了自己的卷積函數並將其輸出與Matlab conv函數中的一個進行比較。爲什麼我的C++ conv函數的輸出與conv Matlab調用中的輸出不同?
具體來說,我想conv([0.1, 0.23, 0.25, 0.18, 0.09], [0, 0, 1, 2, 3, 4, 5, 0, 0], 'same')
調用的輸出是一樣的,什麼是寫在output
調用conv({0, 0, 1, 2, 3, 4, 5, 0, 0}, 2, 6, {0.1, 0.23, 0.25, 0.18, 0.09}, 5, 5, output);
後。
這裏是我的代碼(它asssumes該信號已經填補,這就是爲什麼我有_start和_stop啄)
void conv(double* signal, int conv_start, int conv_stop, double* kernel, int kernel_len, int output_len, double* output){
int halfKernel = floor(kernel_len/2.0);
for (int i = 0; i<output_len; i++) output[i] = 0;
for (int c = conv_start; c<=conv_stop; c++){
for (int k = -halfKernel; k <=halfKernel; k++){
output[c-conv_start] += kernel[k+halfKernel]*signal[c+k];
}
}
}
和MATLAB函數的輸出: 1.0100 1.7700 2.6200 2.8700 2.2400
雖然我的是: 0.880000 1.630000 2.480000 2.790000 2.470000
。
我已經完成了上述輸入的計算也手工,然後我得到了與我自己的實現相同的結果。那麼,這是一個概念錯誤還是Matlab函數沒有做我認爲它應該做的事?