1
$\begingroup$

I'm trying to do some simple filtering for an audio signal using a window-sinc low pass filter. Supposing that my buffer has M values and the filter kernel size is N, after convolving these two arrays I would obtain an output of m+n-1 values. Which part should I take into consideration? I'm asking this because, if I read a M values array I should write a M values array. I have tried to take the first M or the last M values for output, but the result is not too good. I was wondering if I have to use a circular buffer in which I put every time M+N-1 values, but I read the first M values.

$\endgroup$
  • $\begingroup$ Are you performing one-shot filtering of single sample buffers, or are you going to be filtering an arbitrarily long signal one block at a time? $\endgroup$ – Jason R Mar 26 '13 at 13:02
  • $\begingroup$ Practically, I read a .wav or a .mp3 chunk by chunk, I do some filtering (like in winamp or in other player) and after that I play it. $\endgroup$ – Victor Mar 26 '13 at 20:44
  • 1
    $\begingroup$ OK, then in that case you need to make sure you maintain the state of the filter between blocks, as Hilmar's answer below suggests. $\endgroup$ – Jason R Mar 26 '13 at 20:54
3
$\begingroup$
  • Output the first M samples of your convolution result
  • Keep the remaining samples and ADD those to the result next buffer

Google "overlap add" for more information. While overlap add is a frequency domain method, it explains the framing and buffer handling well.

$\endgroup$
  • $\begingroup$ It worked! Thanks a lot. I have another question regarding recursive biquad filters. In this case, I need to store only out[i-1],out[i-2],in[i-1],in[i-2]. I am asking this because convolution is practically hidden behind the recursive formula. The problem is that I hear some "high frequency cracks". I've also created a post with this issue, but their solution didn't work. dsp.stackexchange.com/questions/8272/… I know that I was making a big mistake: the for loop should be placed after computing out[0] and out[1], but this change doesn't help me. $\endgroup$ – Victor Mar 27 '13 at 15:56

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.