0
votes

i'm trying to make a simple convolution of two signals. One is a signal (music for example) and the other one is an IR (simple delay like this scheme:

IR[0] = 1.0
IR[1->511] = 0 
IR[512] = 0.5
IR[513->1023] = 0;

so it should make a small echo.

I've learned that convolution in the time domain, is multiplication in the frequency domain.

so my idea is to take the FFT of both signals (music and IR) and to multiply the resulting couple numbers re & im (from re + im*i), then take the iFFT and admire the result.

fft(fftMusic);
fft(fftIR);
for (int i = 0; i < n; i++)
    fftMusic[i] = fftMusic[i] * fftIR[i];
ifft(fftusic);
for (int i = 0; i < n; i++)
        fftMusic[i] = fftMusic[i] * 2/double(n);

The only problem is that it doesn't works.

I've tried both RFDT and CFDT and i produces a strange result : my signal is delayed but in reverse. Is it a FFT thing ?

first for the RDFT (Real DFT : re in, re & im out), i added +n/2 zero samples at the end or both music and IR, for the convolution, then used 4 overlapped buffers (it is the number required) and calculated when the time is right the FFT of both then multiply, then iFFT etc.

Second for the CDFT (complex DFT : re & im in & out), i put a sample of music every two sample (and zero for the imaginary part) then did the cdft, multiplied ,etc

but both doesn't works and give the same result: a weird mix of reversed and delayed sounds.

please help.

  • List item
1
You need to read up on overlap-add/overlap-save methodsPaul R
i already use overlapp-add method i don't know why ovelapp-save would improve (maybe performance a little bit) the results. but thanks anyway.IonOne
OK - you can use either overlap-add or overlap-save so that you don't get circular convolution - it wasn't clear from your question though that you are already using overlap-add. Evidently the problem lies elsewhere.Paul R
The convolution in the frequency domain, is a multiplication right ? but it is a complex multiplication so if we have bufferInput = (Re_Input + Im_Input * i) and IR = (Re_IR + Im_IR * i) we have to multiply both as this : result = (Re_Input + Im_Input * i) * (Re_IR + Im_IR * i) result = (Re_Input * Re_Ir - Im_Input * Im_IR) + i * (Re_Input * Im_IR + Im_Input * Re_IR) that's the complex conjugate i guess. and it works finally...IonOne

1 Answers

0
votes

First of all, it is good practice to use vectorized code so instead of

for (int i = 0; i < n; i++)
    fftMusic[i] = fftMusic[i] * fftIR[i];

use

fftMusic = fftMusic .* fftIR;

Now to your problem, did you try the simply plain convolution? And if yes, what were the results?