function out = peakfilt (sig, fc,fb,G,fs)

% peakfilt              - Peak filter, second order
%
% out = peakfilt (sig,fc,fb,G,fs)
% 
% Input parameters:
% - sig:    input signal
% - G:      gain [dB]
% - fc:     cut-off frequency
% - fb:     bandwidth
% - fs:     sampling frequency
% Output parameter:
% - out:    output signal (column vector)

  % Initialisierung der Vektoren
len=length(sig)+2;
y=zeros(len,1);
yh=zeros(len,1);
x=zeros(len,1);
x(3:len)=sig;

  % Parameter (Allpassfilter 2-ter Ordnung): b und c
b=(tan(pi*fb/fs)-1)/(tan(pi*fb/fs)+1);
c=-cos(2*pi*fc/fs);
  % Gain: H0
H0=10^(G/20)-1;

for n=3:len
    yh(n) = -b*x(n)+c*(1-b)*x(n-1)+x(n-2)-c*(1-b)*yh(n-1)+b*yh(n-2);
    y(n)= H0/2*(x(n)-yh(n))+x(n);
end
out=y(3:end);