0
$\begingroup$

I am having the following filter structure, which is a second-order decimation:

enter image description here

Which actually implements the following equation/code: (ans-0.2727) $$\frac{2}{N(N+1)}\sum_{i=1}^{N} (N+1-i).d(i)$$

d=[1 0 1 0 1 0 1 0 1 0 1];
N=10;
sum2=0;
for i=1:1:N
   sum2=sum2+((N+1-i)*d(i));
end
second_order_ans=sum2/(N*(N+1));

However, I wanted to break this to two separate for loops (or) a cascade of two first-order decimations.

The first-order decimation corresponds to the following equation and code: (ans-0.5) $$\frac{1}{N}\sum_{i=1}^{N} d(i)$$

d=[1 0 1 0 1 0 1 0 1 0 1];
N=10;
sum=0;
for i=1:1:N
sum=sum+d(i);
end
first_order_ans=sum/N;

I tried the following for cascade but I get the output as 0.6182 and far away from 0.2727.

%second order - cascade
for i=2:1:(N-2)
sum2_c1(i)=sum2_c1(i-1)+d(i); %First counting
end

for i=2:1:(N-2)
sum2_c2(i)=sum2_c1(i)+sum2_c2(i-1); %Second counting
end
sum2_c=0;

for i=2:1:(N-2)
sum2_c=sum2_c+sum2_c2(i); %adding up
end

sum2_ansc=((sum2_c)*2)/(N*(N+1));
$\endgroup$
  • $\begingroup$ I can't see the decimation on the Simulink schematic $\endgroup$ – Ben Feb 24 at 18:59
  • $\begingroup$ @Ben The 1/(z-1) is the accumulator, which implements the decimation. $\endgroup$ – sundar Feb 24 at 19:18
  • $\begingroup$ Is this line OK : second_order_ans=sum2/(N*(N+1)) (equ is 2/(N*(N+1))*sum2) ? $\endgroup$ – Juha P Feb 25 at 15:42
  • $\begingroup$ @JuhaP I wonder that too. But I get similar answers only when I remove the "2". Might be, the summing operation in for loop compensates it. $\endgroup$ – sundar Feb 25 at 21:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.