DSPRelated.com
Forums

Convolution function in c++

Started by daviddoria January 26, 2007
I feel like this should be a very standard thing to need to do, however I
cannot find a function online ANYWHERE.  Anyone have one?

Thanks!

David

David wrote:
> I feel like this should be a very standard thing to need to do, however I > cannot find a function online ANYWHERE. Anyone have one?
So what do you want to convolve together? The simplest thing is to convolve two finite length vectors, akin y = conv(x,h). The next steps are streaming convolution (using circular buffers), block convolution (using overlap-add / save), and finally fast convolution (filtering in the frequency domain) with the different variants (single or multiply partitioned impulse responses). Different tricks and implementation issues apply at each step. You can also convolve images. Regards, Andor
daviddoria wrote:
> I feel like this should be a very standard thing to need to do, however I > cannot find a function online ANYWHERE. Anyone have one? > > Thanks! > > David
If you want to convolve two arrays it's pretty easy to program. Considering memory usage convolution is application specific, there is no best way for any given application. R.
"daviddoria" <doriad@rpi.edu> wrote in message
news:b-CdnSbFoswG2yfYnZ2dnUVZ_o-knZ2d@giganews.com...
> > I feel like this should be a very standard thing to need to do, however I > cannot find a function online ANYWHERE. Anyone have one? > > Thanks! > > David
If you know the maths then surely the code follows? It's just multiplications,loops and sums of delayed arrays. F. -- Posted via a free Usenet account from http://www.teranews.com
hi

you have to select the type of convolution you want for your application.
its fairly simple to write c/c++ code for that

APS


> >I feel like this should be a very standard thing to need to do, however
I
>cannot find a function online ANYWHERE. Anyone have one? > >Thanks! > >David >

On Jan 27, 12:48 am, "salaria" <apsala...@gmail.com> wrote:
> hi > > you have to select the type of convolution you want for your application. > its fairly simple to write c/c++ code for that > > APS > > > > > > >I feel like this should be a very standard thing to need to do, however > I > >cannot find a function online ANYWHERE. Anyone have one? > > >Thanks! > > >David
Try the SPUC dsp library http://spuc.sourceforge.net. Create a FIR using one side of the equation and then loop on the update/clock function with the other inputs. If you are only doing a convolution though it's probably better to either just write the code yourself or copy the appropriate section out of this

On Jan 26, 1:21 pm, "daviddoria" <dor...@rpi.edu> wrote:
> I feel like this should be a very standard thing to need to do, however I > cannot find a function online ANYWHERE. Anyone have one? > > Thanks! > > David
Try this: // Routine peforms linear convolution by straight forward calculation // calculates z= x convolve y // Written by Clay S. Turner // // inputs: // X array of data comprising vector #1 // Y array of data comprising vector #2 // Z pointer to place to save resulting data - needs to be lenx +leny-1 long // lenx # of items in vector 1 // leny # of items in vector 2 void LinearConvolution(double X[],double Y[], double Z[], int lenx, int leny) { double *zptr,s,*xp,*yp; int lenz; int i,n,n_lo,n_hi; lenz=lenx+leny-1; zptr=Z; for (i=0;i<lenz;i++) { s=0.0; n_lo=0>(i-leny+1)?0:i-leny+1; n_hi=lenx-1<i?lenx-1:i; xp=X+n_lo; yp=Y+i-n_lo; for (n=n_lo;n<=n_hi;n++) { s+=*xp * *yp; xp++; yp--; } *zptr=s; zptr++; } }
A Gaussian High Pass Filter (MIT'S FFTW based) is available at:
http://www.adislindia.com/login/pluginlinks.php

It performs a convolution and is an extension of CFFTWWrapper (http://
divyarathore.googlepages.com/fftwpluginforimageapprentice.htm).

- D. Rathore
www.adislindia.com