For a piece of software I've been working on lately I need to implement FFT convolution for performance reasons.

Doing so has been mildly succesfull but there is still a error somewhere causing lots of small spikes to show up on the waveform. Also when looking at the spectrum of the signal, lots of distortion can be seen which is filtered out mostly at 15 KHz.

What I do in the filter is the following with overlap - add:

  1. Create the filter kernel of 101 points and FFT it
  2. Create a buffer holding 200 samples of audio
  3. When there are 200 samples ready, FFT the signal and multiply with the filter kernel FFT.
  4. IFFT the filtered signal again
  5. Add last 100 samples from the previous run to the first 100 samples of the current output
  6. Save the last 100 samples for the next run.

The small spikes and distortion when looking at the spectrum seems to come from a missing sample somewhere, but I can't track down exactly where it happens.

The following code is what I use to do the filtering:

function TFFTAnalyzer.doAnalyzer(Sample: Single) : Single;
  I: Integer;

  Temp : Single;
  Result := X[BufferPos];
  X[BufferPos] := Sample;

  BufferPos := BufferPos + 1;
  if BufferPos > 200 then
    BufferPos := 1;

  if BufferPos = 200 then
    //Add 100 zeros
    for I := 0 to 512 do
      if I > 200 then
        X[I] := 0;

    //Calculate the FFT of the sample buffer
    FFT_transform(1024, X);

    I := 0;

    while I <= 1024 do
      Temp := X[I] * FilterX[I] - X[I + 1] * FilterX[I + 1];
      X[I + 1] := X[I] * FilterX[I + 1] + X[I + 1] * FilterX[I]; // imaginary part
      X[I] := Temp; // real part

      I := I + 2;

    //Inverse FFT the signal
    FFT_inverse(1024, X);

    //Overlap the first 100 samples
    for I := 0 to 100 do
      X[I] := (X[I] + Overlap[I]);// / 2;

    //Save last 100 samples for next overlap
    for I := 200 to 300 do
      Overlap[I - 200] := X[I];

This is the picture showing the problem

This is the picture showing the problem with the spikes and distortion.

  • $\begingroup$ is it 32 bit or 64 bit computation ? $\endgroup$ – Fat32 Dec 17 '15 at 0:55
  • $\begingroup$ i really don't want to decode your code. is your FFT size 1024? your 101-tap filter kernel, are you zero-padding that out to 1024 before you FFT that? if so, with either overlap-add or overlap-save, you should be able to get 924 samples out from each frame. $\endgroup$ – robert bristow-johnson Dec 17 '15 at 5:12
  • $\begingroup$ The program uses 32 bit computation. The filter I try to create uses 1024 point FFT's, where I have a filter kernel of 101 taps that I calculate over a buffer of 200 samples. The delay can't be too high, so I can't create a huge buffer of samples. $\endgroup$ – Jesse Willem Dec 17 '15 at 21:43
  • $\begingroup$ I provided an indirect solution to you. $\endgroup$ – Fat32 Dec 21 '15 at 0:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.