function h = fir_kaiser(fpass,fstop,A)
% Input args
if nargin == 2
   A = 60;
end

% Kaiser filter design
beta = 0;
if A > 50
    beta = 0.1102 * (A - 8.7);
elseif A >= 21
    beta = 0.5842 * (A - 21)^0.4 + 0.07886 * (A - 21);
end

if fpass > fstop
    f = fstop;
    fstop = fpass;
    fpass = f;
end

fc = 0.5*(fpass + fstop);
df = abs(fstop - fpass);
M = (A - 8) / (2.285 * 2 * pi * df);
M = ceil(M);
L = M + 1;

w = kaiser(L,beta).';
n = [0:M] - M/2;
h = 2*fc*sinc(2*fc*n);
h = h .* w;

% Plot frequency response
N = 2^14;
f = [0:N-1]/N - 0.5;
plot(f,20*log10(abs(fftshift(fft(h,N)))),'LineWidth',2);
xlim([0 0.5]);
ylim([-100 10]);
grid on;
hold on;
ax = axis;
plot(fpass*[1 1],ax(3:4),'r');
plot(fstop*[1 1],ax(3:4),'r');
plot([fstop 0.5],-A*[1 1],'r');
hold off;
xlabel('Frequency [cycles/sample]');
ylabel('Magnitude Response [dB]');
shg;
