3
$\begingroup$

enter image description here

I have some data, the blue curve which I want to filter out the background to get a flat signal with dips(Idea is to divide signal (except the dips) by the background). The orange curve is my best fit so far. You can see that it agrees for most of the points, apart from the deviation at around 1000. Otherwise, the fitting was very good. and It almost returned a noiseless result by dividing the blue curve (raw data) by the fitting.

I expect something like belowenter image description here However, the problem was that my fitting also has dips (which i don't want to divide out my dip!),also since the background was changing constantly, using a higher order fitting function returns wiggles, so it makes it really hard to have no wiggles between the dips. Here is the bad example,again, the blue = raw data, orange = fitting, green = processed data. enter image description here

And I want something like this, where the blue curve sorts of fill the gap![enter image description here]4 Any ideas how to do this? I tried using lowpass filter, doesn't work. What i'm using now is Peak detect/ find peak method. I also tried Fourier transform and remove higher k components, but it doesn't work! I appreciate for any idea ! And I can write the code myself.

$\endgroup$
6
  • 1
    $\begingroup$ You could create an interpolating function on the data with the dips excluded, i.e. find peak positions, extract all data within +/-N of peak, interpolate and then sample your interpolation function at all data points and use this to divide out background. Low pass filtering, or moving average before fitting, etc. should also be ok. without access to the data it's going to be tough to help. $\endgroup$
    – N.J.Evans
    Jun 2, 2016 at 17:42
  • 1
    $\begingroup$ It would be easier to help if you could provide the data. $\endgroup$ Jun 2, 2016 at 20:07
  • 1
    $\begingroup$ You can use Quantile Regression for this as explained here. $\endgroup$ Jun 3, 2016 at 3:50
  • $\begingroup$ N.J.Evans. That's exactly How i did it. But it fitted the gaps between peaks with a dip which is something i don't want. $\endgroup$ Jun 3, 2016 at 10:08
  • $\begingroup$ Quantile Regression failed $\endgroup$ Jun 3, 2016 at 10:33

1 Answer 1

2
$\begingroup$

One quick approximation uses the compound median filter defined here.

I converted the blue line in your image to a vector of amplitudes trace. The orange line is the filtered output, the green line is the residual. Vary the second input parameter of CompoundMedianFilter to see other baseline approximations.

ListLinePlot[{trace, CompoundMedianFilter[trace, 15], 
              trace - CompoundMedianFilter[trace, 15]},
             Frame -> True, PlotRange -> {-180, 280}]

baseline subtraction

$\endgroup$
2
  • $\begingroup$ It's not supposed to be block function $\endgroup$ Jun 3, 2016 at 10:09
  • $\begingroup$ To be honest, i think my fit i still the best so far. $\endgroup$ Jun 3, 2016 at 10:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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