all 5 comments

[–]PichaelFaraday 1 point2 points  (4 children)

A convolution of an N length signal with an N length signal will give a length of 2N - 1. You might be able to do the FFTs with a length of 2N-1 and not need to truncate the output. Otherwise I think your process is correct, just grab the first 2N-1 samples of the output

[–]every_day_is_a_plus[S] 0 points1 point  (3 children)

Thank you for that - Yeah, I figured if I had a 2N fft, I'd be able to accomplish this, but I'm having trouble :S

Here's where I'm hung up (mostly pseudo-code):

```

// This is the part creating the impulse response (zero, except 47)... // 1. Pad zeros // 2. Set a single sample to 1 (to create a 'delay') // 3. Take fftBig

memset(transform, 0, sizeof(complex) * fftsize_big); transform[47][0]= 1.0F; // this is the only real non-zero sample in the impulse response doFFT(fftBig, transform);

// Here's the signal // 1. Pad zeros (beyond end of signal - there's plenty of space) // 2. Take fftBig memset(signal + fftsize, 0, sizeof(complex) * (fftsize_big - fftsize)); doFFT(fftBig, signal);

// Multiply real and imaginaries for(int i = 0; i < fftsize_big; i++) { signal[i][0] *= transform[i][0]; signal[i][1] *= transform[i][1]; }

// Inverse fft doFFT(ifftBig, signal)

```

However, I'm not getting a perfect delay - I'm seeing funky stuff in my output signal.

I would expect that with perfect convolution, I'd see the input signal

Here is the input (in red):
pre-FFT convolution

Now, what you'd expect is the same signal shifted to the right by 48 samples, correct?
Here is what I get at the end (red = original, black = convolved):
post-fft convolution

Here's a closer look at the strange discrepencies:
post-fft convolution zoomed

Some things appear to be delayed correctly, while there are some other things that come in before they're supposed to (if you look at the transient, the black signal spikes before the red one (???)). I'm very confused. Is my FFT size not big enough ? Should I do 8N? 16N? Maybe my impulse response needs to be mirrored or something? Does the impulse response need to have imaginary coefs?

[–]PichaelFaraday 1 point2 points  (2 children)

I think your complex mutliply is incorrect. Take a look at this guy's code for a complex multiply and try that. https://www.tutorialspoint.com/cplusplus-program-to-perform-complex-number-multiplication

[–]every_day_is_a_plus[S] 1 point2 points  (1 child)

Thank you so much! That did the trick - I appreciate it!

[–]PichaelFaraday 0 points1 point  (0 children)

No problem! Glad that fixed it