I have an algorithm that looks at an audio frame, calculates a threshold in db-rms, and decides to filter the frame whether or not the threshold is crossed. However, filtering each block is producing discontinuities at the ends of the block. How can I rectify this? Is this an issue for overlap-add processing, and if so how can I get started with that? Thank you.

Spectrograph of audio clip (cropped poorly) before processing: Before processing

OLA Spectrograph of audio clip (cropped poorly) after processing: enter image description here

Here is some MATLAB:

% file reading
filename = 'audio.wav';
[x,fs] = wavread(filename);
x = x(:,1);
xCopy = x;

% constant filter
biQ{1} = dsp.BiquadFilter();
biQ{1}.SOSMatrix = cookEQ(fs,1000,-60,2,'lp').*0.2;
Zi = zeros(2,3);

% window length and overlap
len = length(x);
blockLen = 256;          % window length
hop = floor((blockLen)/2);     % hop size
w = hamming(blockLen);  % window
output = zeros(len,1);

% starting at hop to avoid if statement for first block
for pos=hop:hop:len-blockLen-hop

    ndx = pos+1:pos+blockLen;      % current window location
    window1 = x(ndx-hop) .* w;
    [window1,Zi(:,1)] = filter(biQ{1}.SOSMatrix(1:3),biQ{1}.SOSMatrix(4:6),window1,Zi(:,1));
    window2 = x(ndx) .* w;
    [window2,Zi(:,2)] = filter(biQ{1}.SOSMatrix(1:3),biQ{1}.SOSMatrix(4:6),window2,Zi(:,2));
    window3 = x(ndx+hop) .* w;
    [window3,Zi(:,1)] = filter(biQ{1}.SOSMatrix(1:3),biQ{1}.SOSMatrix(4:6),window3,Zi(:,3));

    firstHalf = window1(floor(length(window1)/2)+1:length(window1));
    secondHalf =  window3(1:floor(length(window1)/2));
    overlapAdder = [firstHalf ; secondHalf];
    output(ndx) = window2 + overlapAdder;


audiowrite([filename(1:end-4) '_ola.wav'],output,fs);
  • 1
    $\begingroup$ Do your blocks currently have any overlap (hop)? What is your frame size versus your hop size? Offhand, it does look like you need overlap add, with a windower on each frame (to minimize artifacts from the end of blocks) $\endgroup$ Aug 18, 2015 at 16:54
  • $\begingroup$ No overlap, haven't used overlap-add before. The windowing makes sense. I'll just hop by the overlap size, window, and add the two frame together, that might do it. $\endgroup$
    – panthyon
    Aug 18, 2015 at 16:57
  • 1
  • 1
    $\begingroup$ how are you filtering the block? filters have states, what are the states at the beginning of the filtering process and what do you do with the states at the end? then what are you gonna do if one block meets the "fliter this" threshold and the following block doesn't? what will you do with the states then? $\endgroup$ Aug 18, 2015 at 17:20
  • $\begingroup$ i'm preserving the state from block to block (initial conditions are zeros for the states). i'm not doing anything to the states when the threshold isn't met (im passing input to output in that case). i would think they might need to be reset if the criterion isn't met, although i may be very wrong. $\endgroup$
    – panthyon
    Aug 18, 2015 at 17:23


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.