function y = butterlp512(x)
%-- Written by Peter Shawhan for CGWA summer school
b = 1.0e-4 * [.006241911798543 0.037451470791261 0.093628676978152 0.124838235970870 0.093628676978152 0.037451470791261 0.006241911798543];
a = [1 -5.241600212134476 11.490257162793821 -13.479819790485376 8.923711776583994 -3.160088366078981 0.467579377556528];
%-- Initialize the output
y = zeros(1,length(x));
%-- Calculate first output specially because 'a' is not involved in numerator
y(1) = b(1)*x(1)/a(1);
%-- Loop 
for n=2:length(x)
  la = min(length(a),n);
  lb = min(length(b),n);
  y(n) = ( sum( b(1:lb).*fliplr(x(n-lb+1:n)) ) - sum( a(2:la).*fliplr(y(n-la+1:n-1)) ) ) / a(1);
end
