Skip to content

Instantly share code, notes, and snippets.

@tomoya55
Created August 28, 2009 08:08
Show Gist options
  • Select an option

  • Save tomoya55/176825 to your computer and use it in GitHub Desktop.

Select an option

Save tomoya55/176825 to your computer and use it in GitHub Desktop.
Convolution
int* ConvolveIn(int x[], int h[]){
int ix, ih;
//x[]とh[]の配列の大きさを求める
ix = sizeof(x)/sizeof(int);
ih = sizeof(h)/sizeof(int);
iy = ix + ih;
//output
int y[iy];
for(i=0;i<=iy;i++){
y[i]=0;
}
//Convolving
for(i=0;i<=ix;i++){
for(j=0;j<=ih;j++){
y[i+j] += x[i] * h[j];
}
}
//yの先頭ポインタを返す。
return y;
}
int* ConvolveOut(int x[], int h[]){
int ix, ih;
//x[]とh[]の配列の大きさを求める
ix = sizeof(x)/sizeof(int);
ih = sizeof(h)/sizeof(int);
iy = ix + ih;
//output
int y[iy];
//Convolving
for(i=0;i<=iy;i++){
y[i] = 0;
for(j=0;j<=ih;j++){
if(( i-j >= 0) && (i-j <= 80))
y[i] += h[j]*x[i-j];
}
}
return y;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment