I want to have only the slope of the signal. How can I do? I have tried to apply some filters but so far I have not been able to hit the nail on the head. I use Matlab.
1 Answer
A bump like this one is likely to be wide-band, especially with the sharp onset. Plus, the line may be hard to deal with in the Fourier domain. Hence, the combination is complicated to remove with a classical linear filter. The problem is very akin to baseline, background or trend removal, answered elsewhere here.
Several options are possible, for instance:
- use a non-linear filter, based on a median, or a minimum/maximum statistics,
- use morphological operators: a rolling ball, lot of straight segments, etc.
- use a knowledge on the data model, like a linear equation: $y=ax+b$, or the fact that the bump is "above",
- combine the above in a variational formulation, using appropriate data fidelity and penalty.
In your example, I suspect that a classical linear fit with robust distance (like a least-absolute distortion) could do the job. I will call all the above filters, in the wide sense that you will remplace a value with respect to some sort of combination of the others.
You can also call the following robust regression, LAD fitting. An example at work:
% Standard and Robust fit of a degree 1 polynomial w/ a bump
nSample = 1000;
% Create a similar composite signal
time = linspace(0,5,nSample)';
polyCoef = [0.2 0];
dataLine = polyval(polyCoef,time);
dataParabola = -8*(time-2).*(time-3);
dataParabola(dataParabola < 0) = 0;
data = dataLine+dataParabola;
% Use Matlab curve fitting toolbox
optsRobust = fitoptions('Method','LinearLeastSquares','Robust','LAR');
[fitObject,gof] = fit(time,data,'poly1',optsRobust);
h1=plot(fitObject,time,data);
grid on
-
1$\begingroup$ Hi Mr Laurent, Thanks for the answers, I appreciate it. Can I send you any doubts of mine about signal processing? It is because, I'm makeing a degree final project, And the truth is, I get lost a little bit in some of the mathematical methods of processing. I'm trying to understanding what I'm doing with those. Can I keep in touch via private messages? $\endgroup$ Jun 6, 2020 at 12:07
-
$\begingroup$ By the way, in your answer, why do you get an output variable named 'h1', something special? $\endgroup$ Jun 6, 2020 at 12:12
-
$\begingroup$ No,
h1
is a handle for the plot, I reused part of a former code, it is not needed here $\endgroup$ Jun 6, 2020 at 12:27 -
$\begingroup$ You can try, I cannot promise prompt answers. By posting questions here, you are likely to get more "expert answers" $\endgroup$ Jun 6, 2020 at 12:36
-
1$\begingroup$ Sure! Thank you. So I had posting a doubt 15 days ago o more, and I'm still waiting for a answer. Can you view that post, if it's no trouble? I share the link: dsp.stackexchange.com/questions/67906/… $\endgroup$ Jun 6, 2020 at 16:15