function [bpr, Mpr, bma, Mma] = ifirplot(fpass, fstop, ripple, atten, M)
% design lowpass FIR filter using interpolated FIR design method, plot the
% amplitude response of prototype filter, masking subfilter, band-edge
% shaping subfilter and final IFIR filter
% ifirplot function invokes ifir to calculate the order and coefficient of
% prototype filter and masking subfilter
[bpr, Mpr, bma, Mma] = ifir(fpass, fstop, ripple, atten, M);
Mbe = M * Mpr;
bbe = zeros(1, Mbe);
bbe(1 : M : Mpr * M + 1) = bpr;
% plot figures
figure;
% prototype filter
subplot(2, 2, 1);
[hpr, w] = freqz(bpr, 1, 2 ^ 12);
plot(w / 2 / pi, 20 * log10(abs(hpr)));
title('Prototype Filter');
xlabel('Normalized frequency');
ylabel('Magnitude in dB');
xlim([0, 0.5]);
ylim([-150, 50]);
grid on;
% band-edge shaping subfilter
subplot(2, 2, 2);
[hbe, w] = freqz(bbe, 1, 2 ^ 12);
plot(w / 2 / pi, 20 * log10(abs(hbe)));
title('Band-Edge Shaping Subfilter');
xlabel('Normalized frequency');
ylabel('Magnitude in dB');
xlim([0, 0.5]);
ylim([-150, 50]);
grid on;
% masking subfilter
subplot(2, 2, 3);
hold on;
[hma, w] = freqz(bma, 1, 2 ^ 12);
plot(w / 2 / pi, 20 * log10(abs(hma)));
plot(w / 2 / pi, 20 * log10(abs(hbe)), 'r--');
title('Masking Subfilter');
xlabel('Normalized frequency');
ylabel('Magnitude in dB');
xlim([0, 0.5]);
ylim([-150, 50]);
grid on;
box on;
% final IFIR filter
subplot(2, 2, 4);
hifir = hma .* hbe;
plot(w / 2 / pi, 20 * log10(abs(hifir)));
title('Final IFIR Filter');
xlabel('Normalized frequency');
ylabel('Magnitude in dB');
xlim([0, 0.5]);
ylim([-150, 50]);
grid on;