- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

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, LeeLink Copied

5 Replies

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

--- 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-')
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Hi Kaz,

Thank you very much for the attempt and reply. The code: H_comp = [H_comp H_comp H_comp H_comp]; Does this line of code return the frequency response of the compensation FIR filter, performing additional decimation by 2? Do you know how to calculate the impulse response of this decimat-by-2 FIR filter? Can you please attach the Xilinx cic compilor doc? It sounds useful! Kind Regards, Lee- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Hi Kaz,

Yes. But the fir compensation filter only compensates the cic filter which does the decimation by 4. The compensation filter did not do the additional decimation by 2. You can tell that by checking the repeating points on the plot of the fir filter, which has 22.8MHz output sampling frequency. How to do this additional decimation by 2 using the same compensation filter so the total decimation rate is 8 (4*2)? The fir ouput sampling frequency should be 11.4MHz. Thanks a lot, Lee- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page