function [f,ampl,phase]=f_resp(B,A,n,tau,i_fig)
% Calculate frequency response and plot
%
%Call:    [f,ampl,phase]=f_resp(B,A,n,[tau,[i_fig]]);
%
%	B,A - filter coeficients;
%	n   - number of frequencies;
%	tau - sampling rate (1/2tau - Neiquist frequency);
%	i_fig - =1 - plot response (default);
%

if nargin<5
   i_fig=1;
elseif nargin<4
   tau=1;
end

fs=1/tau;
hh=freqz(B,A,n);
ampl=abs(hh);
%phase=unwrap(angle(hh),2*pi);
phase=angle(hh);
f=fs/(2*n) * (0:n-1);
if i_fig==1
    plot(f,ampl),title ('Amplitude-Frequency response'), ...
    xlabel('Frequency')
%    subplot(211),plot(f,ampl),grid, ...
%    title ('Amplitude-Frequency response')
%    subplot(212),plot(f,phase),grid,ylabel('Radians'), ...
%    title ('Phase-Frequency response'), xlabel('Frequency')
end