function 	LPFIR(fp1,fs1,dp1,ds1,fs,G,m)

% fp1 		passband edge frequency [kHz]
% fs1		stopband edge frequency [kHz]
% dp1		passband ripple 	[dB]
% ds1		stopband loss 		[dB]
% fs		sampling frequency 	[kHz]
% G		Passband Gain
% m		coefficient resolution 	[bits]
n=2^14;		% fft length

Gdb=20*log10(G);
m=2^m;
ft=fs1-fp1;
dp=1-10^(-dp1/20);
ds=10^(-ds1/20);
xf=(0:n-1)*fs/n;
[No,Fo,Mo,W]=remezord([fp1 fs1],[G 0],[dp ds],fs);
Filter_Order=No
h=remez(No,Fo,Mo,W);
h=round(m*h)/m;
le=ceil(length(h)/2);
h_dec=h(1:le);

% Conversion to 2's complement
h2=m*h_dec;
for i=1:le
  if h2(i)<0
  h2(i)=2*m+h2(i);
  end
end
h_bin=dec2bin(h2);
h_hex=dec2hex(h2);

% Print Filter Coefficients
format long
Decimal_Filter_Coefficients=h_dec;
format short
TwosComp_Bin_Coefficients=h_bin
TwosComp_Hex_Coefficients=h_hex;
DC_Gain=sum(h);

% Plot Filter Response
subplot(3,1,1)
m1=min(h);
m2=max(h);
%impz(h);
plot(h);
title('Impulse Response of FIR LP Filter')
axis([0 No 1.2*m1 1.05*m2]);
grid;

subplot(3,1,2);
f1=20*log10(abs(fft(h,n)+10^(-20)));
plot(xf,f1);
axis([0 fs/2 -1.4*ds1 .1*ds1]);
title('Frequency Response of FIR LP Filter')
xlabel('Frequency (kHz)');
ylabel('Magnitude (dB)');
grid;

subplot(3,1,3);
f1max=max(f1);
plot(xf,f1);
%axis([0 1.1*fp1 Gdb-4*dp1 Gdb+2*dp1]);
axis([0 1.1*fp1 Gdb-3 f1max+2*dp1]);
xlabel('Frequency (kHz)');
ylabel('Magnitude (dB)');
grid;

