% adyniir - Apply dynamic IIR filter to input signal
%
% adyniir :: arrow({[[K,N+1]], [[K,M]]}, {[[K,M]]}, [[K,N]]).
%
% N is the order of the IIR filter
% K is the number of independent channels to filter.
% M is the number of consecutive samples in input signal

function o=adyniir
	o=loop1(2,1,@(s1,s2)deal( ifx(s2(2)==1,@next1,@nextm), zeros(s1(1),s1(2)-1)));
end


function [y,yp]=next1(a,x,yp)
	y=x-sum(a(:,2:end).*yp,2);
	yp=[y,yp(:,1:end-1)];
end

function [y,yp]=nextm(a,x,yp)
	M=size(x,2);
	y=zeros(size(x));
	for i=1:M
		[y(:,i),yp]=next1(a,x(:,i),yp);
	end
end
