function [p,p1,p2] = maxflatI(K,M)
% Maximally flat Type-I FIR filter 
%   2K zeros at z=-1
%   2M-2 zeros away from z=-1
% note: if K = M, then p is halfband.
%
% Reference: O. Herrmann, "On the approximation problem 
% in Nonrecursive Digital Filter Design", IEEE Trans. on 
% Circuit Theory, Vol. 18, No. 3, May 1971, pp. 411-413
%
% Ivan Selesnick
% selesi@taco.poly.edu

p2 = 1;
g  = 1;
c  = 1;
for k = 1:M-1
   g  = conv(g,[-1 2 -1]/4);
   c  = c*(K-1+k)/k;
   p2 = [0 p2 0] + c*g;
end
p1 = 1;
for k = 1:2*K
   p1 = conv(p1,[1 1]/2);
end
p = conv(p1,p2);
