# Audio block-processing discontinuities

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:

OLA Spectrograph of audio clip (cropped poorly) after processing:

Here is some MATLAB:

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

% constant filter
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

release(biQ{1});
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;

end

audiowrite([filename(1:end-4) '_ola.wav'],output,fs);

• 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) – ruoho ruotsi Aug 18 '15 at 16:54
• 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. – panthyon Aug 18 '15 at 16:57
• – ruoho ruotsi Aug 18 '15 at 16:59
• 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? – robert bristow-johnson Aug 18 '15 at 17:20
• 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. – panthyon Aug 18 '15 at 17:23