DSPRelated.com
Forums

Cascaded integrator comb decimation filter

Started by clairechan October 2, 2010
HI, Im new to DSP. Am now creating the CIC decimator. But my design has an
error in the matlab although Hogenauer pruning was use. I works fine for
decimation rate 6 and 10, for 3 and 2 have the "noise" occurs.. I dont know
which is correct as I comparing VHDL and Matlab. The below is my matlab
code:

load Pulse100nsSigned.DAT
D = 2; % Differential delay
R = 2; % Downsampler

delayBuffer1 = zeros(1,D);
delayBuffer2 = zeros(1,D);
delayBuffer3 = zeros(1,D);
delayBuffer4 = zeros(1,D);
delayBuffer5 = zeros(1,D);
delayBuffer6 = zeros(1,D);
intOut1 = 0;
intOut2 = 0;
intOut3 = 0;
intOut4 = 0;
intOut5 = 0;
intOut6 = 0;

x = [Pulse100nsSigned' zeros(1,20)]; % impulse input
y = []; % output

for i = 1:length(x)
% integrators
intOut1 = intOut1 + x(i)/4; 
intOut2 = intOut2 + intOut1/2;
intOut3 = intOut3 + intOut2/2;
intOut4 = intOut4 + intOut3/2;
intOut5 = intOut5 + intOut4/2;
intOut6 = intOut6 + intOut5;

% downsample
if mod(i,R)==1
    
% combs
combOut1 = intOut6/2 - delayBuffer1(2);
delayBuffer1(2) = delayBuffer1(1);
delayBuffer1(1) = intOut6/2;

combOut2 = combOut1 - delayBuffer2(2);
delayBuffer2(2) = delayBuffer2(1);
delayBuffer2(1) = combOut1;

combOut3 = combOut2/2 - delayBuffer3(2);
delayBuffer3(2) = delayBuffer3(1);
delayBuffer3(1) = combOut2/2;

combOut4 = combOut3/2 - delayBuffer4(2);
delayBuffer4(2) = delayBuffer4(1);
delayBuffer4(1) = combOut3/2;

combOut5 = combOut4/2 - delayBuffer5(2);
delayBuffer5(2) = delayBuffer5(1);
delayBuffer5(1) = combOut4/2;

combOut6 = combOut5/4 - delayBuffer6(2);
delayBuffer6(2) = delayBuffer6(1);
delayBuffer6(1) = combOut5/4;

y = [y combOut6];
end 

end
y

fid = fopen('resR2.log','rt');
[CICR2,count] = fscanf(fid, '%12d'); % directly convert to 32bits sign
number
tx = 0: length(x)-1;
t1 = 0: 2 : (length(y)-1 )*2;
t2 = 0: 2 : (length(CICR2)-1) *2;
stem(t1,y,'x');
hold on
stem(t2,CICR2,'r','o')
hold on
stem(tx,x,'g','fill')

xlabel('Samples')
ylabel('Amplitude')
title('CIC decimation Rate = 2')
legend('Matlab result', 'Simulation Result','Input');


clairechan <clairegsc@n_o_s_p_a_m.gmail.com> wrote:

>HI, Im new to DSP. Am now creating the CIC decimator. But my design has an >error in the matlab although Hogenauer pruning was use. I works fine for >decimation rate 6 and 10, for 3 and 2 have the "noise" occurs.. I dont know >which is correct as I comparing VHDL and Matlab. The below is my matlab >code:
I haven't looked at your code in detail but it seems to me for a CIC you're going to have to emulate fixed point arithmetic somehow. e.g. instead of x / 2 you will need floor(x / 2). In Matlab the fraction part stays around, unlike if this were a C expression using integers. Steve
On Oct 2, 8:53&#4294967295;am, "clairechan" <clairegsc@n_o_s_p_a_m.gmail.com>
wrote:
> HI, Im new to DSP. Am now creating the CIC decimator. But my design has an > error in the matlab although Hogenauer pruning was use. I works fine for > decimation rate 6 and 10, for 3 and 2 have the "noise" occurs.. I dont know > which is correct as I comparing VHDL and Matlab. The below is my matlab > code: >...
It is hard to find people to examine large pieces of code for you for free. It is even harder when you make it hard to read. Looking at your code makes me wonder if you write bad Fortran in VHDL, too. You might try: Indenting structures 3 or 4 spaces for readability and better understanding Using a name other than 'i' for your index. Matlab defaults this to sqrt(-1) but allows you to overwrite this, don't. It makes reading your code difficult for others (who you might want to help you). Preallocate arrays like 'y'. This forces you to think about what the size will be ahead of time. Generating the index will help clarify what is happening in the code. It's also faster for large arrays. Good luck. Dale B. Dalrymple