% Routine to compute the frequency response of a set of filters in the ISL5416.
% The filter parameters are set by calling the file init1.m before calling this
% routine.
% Filtresp computes and displays the composite frequency response of
% The CIC filter followed by up to 3 decimating FIR filters.
% If FIR1 or FIR2 is bypassed, use 'impulse.imp' as the file name
% and 1 as the decimation factor. The filter order is CIC -> FIR1 -> FIR2.
% Compute the total number of points to display--
% 256 points of resolution at the output sample rate.
points = 256 * fir2deci * fir1deci * displaylobes;
startfreq = 0;
stepsize = fsamp / (cicdeci / displaylobes) / points;
stopfreq = stepsize * (points - 1);
freq = [0:1:points-1] * fsamp / (cicdeci / displaylobes) / points;
% Compute the CIC response.
phs = [1:1:points-1] / (points / displaylobes);
phs = phs * pi;
cicresp = 20 * stages * log10(0.0000000001 + abs((sin(phs) ./ sin(phs/cicdeci)) / cicdeci));
cicresp = [0 cicresp];
% Compute the FIR1 frequency response
fir1 = fgetimp(firfile1);
fir1 = round(fir1*(2^19))/(2^19); % round to 20 bits
fir1resp = 20*log10(.00000001+abs(fft([fir1' zeros(1,points/(displaylobes)-size(fir1,1))])));
temp = fir1resp;
for i=1:(displaylobes-1)
fir1resp = [ fir1resp temp ];
end
% Compute the FIR2 frequency response
fir2 = fgetimp(firfile2);
fir2 = round(fir2*(2^19))/(2^19); % round to 20 bits
fir2resp = 20*log10(.00000001+abs(fft([fir2' zeros(1,points/(displaylobes*fir1deci)-size(fir2,1))])));
temp = fir2resp;
for i=1:(fir1deci*displaylobes-1)
fir2resp = [ fir2resp temp ];
end
% Compute the overall response
overallresp = cicresp + fir1resp + fir2resp;
% Set a magnitude floor (-160 dB)
for i=1:points
if overallresp(i) < -160
overallresp(i) = -160;
end
if cicresp(i) < -160
cicresp(i) = -160;
end
if fir1resp(i) < -160
fir1resp(i) = -160;
end
if fir2resp(i) < -160
fir2resp(i) = -160;
end
end
points
startfreq
stopfreq
stepsize
% Plot the frequency response.
hold off
plot(freq + j * cicresp,'g')
hold on
plot(freq + j * fir1resp,'c')
plot(freq + j * fir2resp,'r')
plot((freq +j * (overallresp)),'k')
legend('CIC', 'FIR 1', 'FIR 2', 'OVERALL');
xlabel('Frequency in Hz'); ylabel('dBFS');
title('CIC -> FIR1 -> FIR2 Frequency Response');
axis([0 40e6 -160 0]);
zoom on
grid