FPGA Intellectual Property
PCI Express*, Networking and Connectivity, Memory Interfaces, DSP IP, and Video IP
6343 Discussions

CIC compensation filers (FIR)

Altera_Forum
Honored Contributor II
1,475 Views

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
0 Kudos
5 Replies
Altera_Forum
Honored Contributor II
501 Views

 

--- 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-')
0 Kudos
Altera_Forum
Honored Contributor II
501 Views

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
0 Kudos
Altera_Forum
Honored Contributor II
501 Views

 

--- Quote Start ---  

Hi Kaz, 

 

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?  

 

--- Quote End ---  

 

 

Not exactly. The frequency response of compensation filter is the line of freqz. 

Then I interpolated it back by 4 in the frequency domain (by repeating 4 copies) in order to compare it (and multiply) with cic filter at same Fs 

 

 

--- Quote Start ---  

 

Do you know how to calculate the impulse response of this decimat-by-2 FIR filter?  

 

--- Quote End ---  

 

 

impulse response is just: 

plot(h_comp); 

 

if you mean frequency response of impulse input then it is the freqz line. 

 

The z domain approach can also be used for both filters and overall system.
0 Kudos
Altera_Forum
Honored Contributor II
501 Views

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
0 Kudos
Altera_Forum
Honored Contributor II
501 Views

 

--- Quote Start ---  

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 

--- Quote End ---  

 

 

It is meant to compensate and decimate by 2. when implementing the compensation filter you have to discard every other sample from output. Either directly or as part of your fir implementation(to reduce resource). The response itself is referred to input Fs
0 Kudos
Reply