I am trying the DC blocking function in matlab. The algorithm of DC blocking is to find DC of the signal first and then remove the DC value from the signals. Here are the codes I tried, which are sample codes from Matlab:

  t         = (0:0.001:10000)';
  x         = sin(30*pi*t) + 1;

  hDCBlock1 = dsp.DCBlocker('Order', 4);  % IIR is default
  hDCBlock2 = dsp.DCBlocker('Algorithm', 'FIR', 'Length', 100);
  hDCBlock3 = dsp.DCBlocker('Algorithm', 'Subtract mean');
  for idx = 1 : 10
    range = (1:1000) + 1000*(idx-1);
    y1 = step(hDCBlock1, x(range));
    y2 = step(hDCBlock2, x(range));
    y3 = step(hDCBlock3, x(range));
    t(1:1000),y1, ...
    t(1:1000),y2, ...
  legend(sprintf('Input DC:%.3f',    mean(x)), ...
    sprintf('IIR DC:%.3f',           mean(y1)), ...
    sprintf('FIR DC:%.3f',           mean(y2)), ...
    sprintf('Subtract mean DC:%.3f', mean(y3)));

I tried to adjust the length of data and order of the IIR, the DC given by IIR always returns a bias error. However the FIR and mean does not, or gives very little errors.

Could anyone explain on this?


i think this is about a well-known limit cycle problem with IIR filters, particularly implemented using fixed-point arithmetic. this is something i wrote a long time ago. from which approximately half of this article is derived from.

maybe later i will copy my thing over here and dress up the equations nicely with $\LaTeX$.

| improve this answer | |

The IIR has a tail that gets cut and discarded at the end of the array. Taking into account the tail in the mean calculation would probably show zero mean.

Your sine is ascending in the beginning of the array and descending at the end of the array, symmetrically, and this probably makes the discarded non-zero FIR outputs outside the array cancel each other.

| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.