# Extracting a Varying DC from a Signal

I have a signal that has both AC and DC components and both a re varying with time. How can I extract the varying DC wave from the signal?

eg: A PPG (Photopletysmography) signal extracted from a healthy patient.

• An example would be nice... – jojek Sep 2 '15 at 9:50
• I edited the question – Saad Qureshi Sep 2 '15 at 10:05
• PPG is an interesting medical application. See the following link for signal examples, information extraction, etc: ncbi.nlm.nih.gov/pmc/articles/PMC3394104 – user14819 Sep 3 '15 at 4:59

DC, by definition, is the non-varying part of the signal. To find the DC component you simply average the entire signal.

How can I extract the varying DC wave from the signal?

This sounds more like you want to extract the low frequency part of the signal. The most basic filter for this is a moving average filter. However, I would recommend a smoother filter, such as a Gaussian filter. Start with $\sigma$ about 1/6 the period of the low frequency oscillations you are interested in and modify to suit.

You could also solve an optimization problem.
If the data is given by the vector $y$ the following optimization problem would work:

$$\hat{x} = \arg \min_{x} \left \{ {\left \| x - y \right \|}_{2}^{2} + \lambda {\left \| Lx \right \|}_{1} \right \}$$

Where the $L$ matrix enforces smoothness.
For instance is could be:

$$\hat{x} = \arg \min_{x} \left \{ {\left \| x - y \right \|}_{2}^{2} + \lambda \sum_{i = 1}^{N - 1} {\left \| {x}_{i} - {x}_{i - 1} \right \|}_{1} \right \}$$

Now, by choosing large ennough $\lambda$ the solution enforces the derivative to be zero -> DC.

It would even work with ${\ell}_{2}$ regularization.
Though if the model is DC jumps, the ${\ell}_{1}$ would be a much better choice.

• Why the down vote? This works like a charm for this cases. – Royi Apr 12 '16 at 18:35

You can try to perform FFT on the signal and extract the first sample, or zero index of the FFT array (assuming it is zero-based index array). This is a direct approach to observe DC signal in comparison to other method of curve fitting with smoothing algorithm. For example, Savitzky-Golay can smooth out high frequency and obtain the pedestal shape of the signal.