# Retaining filter state for processing data in chunks

I am have data in 1 minute chunks but I would like perform filtering on these as if the data was one contiguous signal. How might I hold the filters state between processing data chunks to achieve this.

I am using an FIR in MATLAB with the filter() function.

You can use the filter function of matlab with initial conditions with the following syntax: (excerpted from Matlab 6.0 command window help)

[Y,Zf] = FILTER(B,A,X,Zi) gives access to initial and final conditions, Zi
and Zf, of the delays.  Zi is a vector of length MAX(LENGTH(A),LENGTH(B))-1
or an array of such vectors, one for each column of X.


Hope this helps.

• I didn't realise it was built in, fantastic. I was thinking of more esoteric ways to try and handle this. Thanks – CatsLoveJazz Nov 9 '16 at 20:28

the filter function has the parameter zi for the initial filter state. It also returns zf, as the final filter state. Hence, you can do as follows:

% Assuming chunks contains the chunks as the columns:
zi = 0;
for c = 1:size(chunks,2)
[y, zi] = filter(..., zi);
end


Then, the filter state is retained between the calls. However, you need to take care that you need to perform overlap and add of the returned sequences y.