Path: news.mathworks.com!not-for-mail
From: "Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de>
Newsgroups: comp.soft-sys.matlab
Subject: Re: filter
Date: Fri, 5 Aug 2011 22:17:31 +0000 (UTC)
Organization: Universit&#228;t Heidelberg
Lines: 19
Message-ID: <j1hq5q$c4b$1@newscl01ah.mathworks.com>
References: <j1hg4i$9mk$1@newscl01ah.mathworks.com>
Reply-To: "Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de>
NNTP-Posting-Host: www-06-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1312582651 12427 172.30.248.38 (5 Aug 2011 22:17:31 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 5 Aug 2011 22:17:31 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 869888
Xref: news.mathworks.com comp.soft-sys.matlab:739026

Dear Fernando,

And if you want to implement it by your own, here us the function as Matlab code:
  function [Y, z] = myFilter(b, a, X, z)
  % Author: Jan Simon, Heidelberg, (C) 2011 
  n    = length(a);
  z(n) = 0;
  Y    = zeros(size(X));
  for m = 1:length(Y)
     Y(m) = b(1) * X(m) + z(1);
     for i = 2:n
        z(i - 1) = b(i) * X(m) + z(i) - a(i) * Y(m);
     end
  end
  z = z(1:n - 1);

If you unroll the loop for a specific filter length and use temporary variables for X(m) and Y(m), the performance is not too bad compared to MATLAB's filter.

Kind regards, Jan