Forum Discussion
Altera_Forum
Honored Contributor
11 years ago --- Quote Start --- Hi All, Can I please have the Matlab code for the Solution 2: Multi-stage decimation in "Understanding CIC compensation filers" (Altera booklet)? I have attached this document. This matlab code produces the plot on page 15. I would like to know how to generate the impulse reponse of the compensation FIR filter that implements additional decimation by 2. Kind Regards, Lee --- Quote End --- Below is my attempt. The compensation code is taken from above doc. The cic formula taken from xilinx cic compiler doc as the one given in above doc does not work in my hands. I have not added the mask
freq=linspace(0.00000001,1,1024);
H_cic = (sin(pi*freq*4)./sin(pi*freq)).^8;
H_cic = H_cic/max(H_cic);
%%%%%% CIC filter parameters %%%%%%
R = 4; %% Decimation factor
M = 1; %% Differential delay
N = 8; %% Number of stages
B = 18; %% Coeffi. Bit-width
Fs = 91.392e6; %% (High) Sampling freq in Hz before decimation
Fc = 4.85e6; %% Pass band edge in Hz
%%%%%%% fir2.m parameters %%%%%%
L = 110; %% Filter order; must be even
Fo = R*Fc/Fs; %% Normalized Cutoff freq; 0<Fo<=0.5/M;
% Fo = 0.5/M; %% use Fo=0.5 if you don't care responses are
%% outside the pass band
%%%%%%% CIC Compensator Design using fir2.m %%%%%%
p = 2e3; %% Granularity
s = 0.25/p; %% Step size
fp = ; %% Pass band frequency samples
fs = (Fo+s):s:0.5; %% Stop band frequency samples
f = *2; %% Normalized frequency samples; 0<=f<=1
Mp = ones(1,length(fp)); %% Pass band response; Mp(1)=1
Mp(2:end) = abs( M*R*sin(pi*fp(2:end)/R)./sin(pi*M*fp(2:end))).^N;
Mf = ;
f(end) = 1;
h = fir2(L,f,Mf); %% Filter length L+1
h_comp = h/sum(h); %% Floating point coefficients
plot(freq*Fs,20*log10(abs(H_cic)));
hold
= freqz(h_comp,1,linspace(0,1,1024/4)*Fs/4,Fs/4);
H_comp = ;
plot(freq*Fs,20*log10(abs(H_comp)),'r-');
grid;
axis();
H_all = H_cic.*abs(H_comp);
plot(freq*Fs,20*log10(abs(H_all)),'g-')