DSPRelated.com
Forums

Convolution of 2 different sized arrays of data?

Started by Fleabag November 22, 2005
Hi

I am not totally new to DSP, I did do a module in it at University as part
of my Masters, but that was around 15 years ago...

I am looking at implementing audio effects, such as reverberation and
amplifier/speaker modelling, by the convolution of an audio signal with an
impulse response recorded from a room or amplifier. Specifically I want to
implement a bass guitar amp model to improve my recorded bass guitar
sound.

I've done some research and I can understand some of the maths involved. I
know that I'm going to need to do an FFT of the audio, an FFT of the
impulse response, convolve those two then do an iFFT to get my new audio
signal.

But what's confusing me is how I would go about this convolution if the
audio data and the impulse data sets are of different size. For example,
my audio is probably going to be some power of 2, such as 4096 samples,
but a long reverb at 44.1kHz sampling might be 100000 samples or more.

Can anyone point me in the right direction for some further research
please? If you can give me some specific tech terms to look for then I can
maybe make some headway without having to ask for too much help here, I
don't want to impose on peoples' time too much (but if you do have some
example maths to paste here then that would of course be cool!).

Thanks to anyone who can find the time to help me!

Regards

David Parrott



Fleabag wrote:
> Hi > > I am not totally new to DSP, I did do a module in it at University as part > of my Masters, but that was around 15 years ago... > > I am looking at implementing audio effects, such as reverberation and > amplifier/speaker modelling, by the convolution of an audio signal with an > impulse response recorded from a room or amplifier. Specifically I want to > implement a bass guitar amp model to improve my recorded bass guitar > sound. > > I've done some research and I can understand some of the maths involved. I > know that I'm going to need to do an FFT of the audio, an FFT of the > impulse response, convolve those two then do an iFFT to get my new audio > signal. > > But what's confusing me is how I would go about this convolution if the > audio data and the impulse data sets are of different size. For example, > my audio is probably going to be some power of 2, such as 4096 samples, > but a long reverb at 44.1kHz sampling might be 100000 samples or more. > > Can anyone point me in the right direction for some further research > please? If you can give me some specific tech terms to look for then I can > maybe make some headway without having to ask for too much help here, I > don't want to impose on peoples' time too much (but if you do have some > example maths to paste here then that would of course be cool!). > > Thanks to anyone who can find the time to help me! > > Regards > > David Parrott > > >
The convolution of a sequence of N points with a sequence of M points is a sequence of (N+M-1) points. The simplist way of doing this is to pick a DFT length that is at least (M+N) points and zero pad the the two input sequences to that size before doing the FFTs. If you want to do this on a long sequence, or a continous real time sequence then you should look at either the "overlap add" or "overlap save" algorithms which if you use as google search words, will give you a bunch of hits. Most, (if not all introductory books) will have some coverage on these topics. I kind of like the one in Brigham's book.
Processing to be done real-time or off-line?

another option is to convolve in the time domain i.e. no need to do an
fft on both the impulse response and the signal, if you have matlab it
is as simple as importing the signal from a wave file (a) and impulse
response from a wave file  (b)  as vectors and then use conv(a,b). and
exp[ort back to a wave file.

i used the following code

a=wavread('song');
b=wavread('room impulse');
ab=conv(a,b);

if max(ab)>(-min(ab))
peakamp=max(ab)
else
peakamp=(-min(ab));
end;

p=ab/peakamp;
wavwrite(p,11025,'convolved output.wav');

Fleabag wrote:

> Hi > > I am not totally new to DSP, I did do a module in it at University as part > of my Masters, but that was around 15 years ago... > > I am looking at implementing audio effects, such as reverberation and > amplifier/speaker modelling, by the convolution of an audio signal with an > impulse response recorded from a room or amplifier. Specifically I want to > implement a bass guitar amp model to improve my recorded bass guitar > sound. > > I've done some research and I can understand some of the maths involved. I > know that I'm going to need to do an FFT of the audio, an FFT of the > impulse response, convolve those two then do an iFFT to get my new audio > signal. > > But what's confusing me is how I would go about this convolution if the > audio data and the impulse data sets are of different size. For example, > my audio is probably going to be some power of 2, such as 4096 samples, > but a long reverb at 44.1kHz sampling might be 100000 samples or more. > > Can anyone point me in the right direction for some further research > please? If you can give me some specific tech terms to look for then I can > maybe make some headway without having to ask for too much help here, I > don't want to impose on peoples' time too much (but if you do have some > example maths to paste here then that would of course be cool!). > > Thanks to anyone who can find the time to help me! > > Regards > > David Parrott >
What are you trying to do again? If you're applying an essentially linear effect like reverb you _either_ do a point-by-point multiply the FFT of the sound with the FFT of the filter response then do an inverse FFT, or you convolve the time-domain signal (i.e. you implement a plain old FIR filter). Pure convolution in the FFT domain is equivalent to pure point-by-point multiplication by a time-varying signal in the time domain. For reverb I suspect that you could get close with an IIR with a high delay; I don't know if "close" would be "ick", "close but still cheezy", "wow! good reverb!" or better than analog. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com
Stan Pawlukiewicz wrote:
> Fleabag wrote: > >> Hi >> >> I am not totally new to DSP, I did do a module in it at University as >> part >> of my Masters, but that was around 15 years ago... >> >> I am looking at implementing audio effects, such as reverberation and >> amplifier/speaker modelling, by the convolution of an audio signal >> with an >> impulse response recorded from a room or amplifier. Specifically I >> want to >> implement a bass guitar amp model to improve my recorded bass guitar >> sound. >> >> I've done some research and I can understand some of the maths >> involved. I >> know that I'm going to need to do an FFT of the audio, an FFT of the >> impulse response, convolve those two then do an iFFT to get my new audio >> signal. >> >> But what's confusing me is how I would go about this convolution if the >> audio data and the impulse data sets are of different size. For example, >> my audio is probably going to be some power of 2, such as 4096 samples, >> but a long reverb at 44.1kHz sampling might be 100000 samples or more. >> >> Can anyone point me in the right direction for some further research >> please? If you can give me some specific tech terms to look for then I >> can >> maybe make some headway without having to ask for too much help here, I >> don't want to impose on peoples' time too much (but if you do have some >> example maths to paste here then that would of course be cool!). >> >> Thanks to anyone who can find the time to help me! >> >> Regards >> >> David Parrott >> >> >> > The convolution of a sequence of N points with a sequence of M points is > a sequence of (N+M-1) points. The simplist way of doing this is to pick > a DFT length that is at least (M+N) points and zero pad the the two > input sequences to that size before doing the FFTs. If you want to do > this on a long sequence, or a continous real time sequence then you > should look at either the "overlap add" or "overlap save" algorithms > which if you use as google search words, will give you a bunch of hits. > Most, (if not all introductory books) will have some coverage on these > topics. I kind of like the one in Brigham's book.
If the impulse response isn't very long, a transversal FIR will be simpler. If the IR is short enough, the FIR will be faster as well. Conversion to and from the frequency domain allows multiplication to replace convolution, but it isn't worth driving ten miles out of ones way to buy gas a penny cheaper. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
in article 1132671563.449008.35900@z14g2000cwz.googlegroups.com, dbell at
dbell@niitek.com wrote on 11/22/2005 09:59:

> Processing to be done real-time or off-line?
actually, it shouldn't make much difference if the audio file is much, much larger than the impulse response. this is really, at its root, the "fast convolution" issue. of course, when doing convolution in the frequency domain presumably using the FFT, the convolution you are doing is circular convolution of two equal length sequences (we'll say the lengths of both is N) which results in a periodic result. you zero pad the impulse response (which is of length L) to length N and do that "overlap-add" or "overlap-save" thingie. let's say that the IR length, L, is given and what you have to determine is the size N, of the two sequences and thus the number of zero samples, M-1 = N-L that you pad with. M is the number of samples processed for each frame. the frame location advances by M samples each frame. the radix-2 FFT and iFFT will have a cost function that looks like � � Cost = A*N*log2(N) + B*N + C*log2(N) + D for some constants, A, B, C, and D. �in the olden days we just said that B, C, and D were practically zero (because multiplications used to cost so much more than anything else) but i wouldn't say that now. �the cost of the complex array multiplication is proportional to N so that just changes the "B" (and maybe "D") coefficients a little. �so given a value L, to minimize the cost per sample you have to determine M so that you minimize � � Cost/M = (A*(M+L-1)*log2(M+L-1) + B*(M+L-1) + C*log2(M+L-1) + D)/M so you have to choose M to minimize the cost per sample above, given your overall cost parameters, A, B, C, and D. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
in article AcGdnXGrcfb43x7enZ2dnUVZ_v-dnZ2d@web-ster.com, Tim Wescott at
tim@seemywebsite.com wrote on 11/22/2005 11:08:

> What are you trying to do again?
actually, i needed to review the OP and probably, unless he is doing reverb emulation of a very large room, i don't think that fast convolution will help at all.
> If you're applying an essentially linear effect like reverb you _either_ > do a point-by-point multiply the FFT of the sound with the FFT of the > filter response then do an inverse FFT, or you convolve the time-domain > signal (i.e. you implement a plain old FIR filter). > > Pure convolution in the FFT domain is equivalent to pure point-by-point > multiplication by a time-varying signal in the time domain.
dunno what you mean by "pure", Tim, but i usually think it might mean "linear convolution" and "linear" means in time, not the "L" of "LTI". anyway, the FFT method (which is a component of what i would normally call "fast convolution") does not do linear convolution. it does "circular convolution."
> For reverb I suspect that you could get close with an IIR with a high > delay; I don't know if "close" would be "ick", "close but still cheezy", > "wow! good reverb!" or better than analog.
a good reverb, whether you're trying to emulate a real room with a real impulse response, or just trying to create a good reverb of a fictional or hypothetical room, is *very* difficult. a "good" reverb will have an impulse response with reflections happening at mutually random times eventually (toward the "tail" of the impulse response) sounding like exponentially decaying white noise. a kinda "cushhhhhhhh....." sound. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
in article mrOdnSFQSfEN1x7enZ2dnUVZ_t6dnZ2d@rcn.net, Jerry Avins at
jya@ieee.org wrote on 11/22/2005 11:42:

> If the impulse response isn't very long, a transversal FIR will be > simpler. If the IR is short enough, the FIR will be faster as well. > Conversion to and from the frequency domain allows multiplication to > replace convolution, but it isn't worth driving ten miles out of ones > way to buy gas a penny cheaper.
that's a good point, Jerry. this sounded so familiar to me that i looked up in Google groups where we had talked about this recently on comp.dsp. i tried to define the issue here: http://groups.google.com/group/comp.dsp/msg/f4db8236019f395d it depends on how your FFT cost function is, but there is a tradeoff. back in the early 80's, when we ignored everything other than the cost of multiplication, i seem to remember that the tradeoff happened at about an FIR length of 8. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
r b-j,

Actually I was asking because of a practical problem.  If the OP plans
to hook this to his instrument, using an FFT to implement a reverb with
a 100K sample data requirement would mean a 2+ second delay at 44.1
Ksps to accumulate enough data to generate FFT outputs.  Playing a
guitar with the sound out delayed by 2+ seconds could be rather
confusing.  If he was looking to integrate this with his instrument he
should do a time domain implementation to avoid the data accumulation
delay.

Dirk