function [y]=IIRlowpass( in, simufreq, timeconst )
%function [y]=IIRlowpass( in, simufreq, timeconst )
%
% Infinite impulse response low pass filter, i.e. simulating an RC low-pass
% filter.
% in: the time series that is the input
% simufreq: simulation frequency
% timeconst: equivalent to R*C, cutoff at 1/timeconst

y=zeros(1,length(in));
y(1)=in(1);
for i=2:length(in);
    alpha=1-exp(-1/timeconst/simufreq);
    y(i)=(1-alpha)*y(i-1)+alpha*in(i);
    %y(i)=(1-alpha)*y(i-1)+in(i);
end; %for

plot((1:length(in))/simufreq,y);

