pkg load signal
 cic = @(f) (sin (pi*(t=f+eps*!f)/2)./sin (pi*t/2/10)/10).^4;

 b = firpm (30, [0 .5 .7 1], @(n,f,g) deal (a=(g<=f(2))./cic (g), 1./(a+!a)));

 clf; [h f]=freqz (b); plot (f/=pi, 20*log10 (abs (h)))
 grid on; axis ([0 1 -60 6]); set (gca, 'xtick', [0:.1:1])
 title (sprintf ('firpm type-I CIC-compensation filter (order=%i)', length (b) - 1));
 ylabel ('Magnitude response (dB)'); xlabel ('Frequency (normalized)')
 axes ('position', [2 3 4 3]/10)
 plot (f, 20*log10 (abs (h).*cic (f))); axis ([0 .55 -.04 .04]); grid on
 title ('Compensated filter response')


