Fitting a simple digital signal from noisy measurements (piecewise linear fitting?)
1 view (last 30 days)
Show older comments
I have a digital signal from scope measurements:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/761141/image.png)
Note that the transitions seem to be mainly due to slewing (=charging load capacitance with a constant current) as opposed to bandwidth limitation (linear system, RC, ...).
This suggests this signal can be well described by a piecewise linear function.
What is the easiest way to do this in MATLAB?
0 Comments
Answers (1)
Star Strider
on 8 Oct 2021
I cannot find a built-in function that incorporates a slew rate, so so programming it yourself would be necessary.
One option could be:
sqs = @(t) (10*t).*(t>=0 & t<0.1) + 1.*(t>=0.1 & t<0.2) + (3-10*t).*(t>=0.2 & t <0.3);
t = linspace(0, 1);
figure
hold on
for n = 0:0.5:2;
plot(t+n, sqs(t), '-b')
end
hold off
grid
Adjust the slew rate, signal segment durations, and amplitudes to get the desired result.
I leave the rest to you.
.
2 Comments
Star Strider
on 8 Oct 2021
My pleasure!
The function I provided should be a prototype for that (set certain constants to instead be parameters, and use that as the objective function), unless a model of the circuit that produced that plot is available, and if so, just fit those parameters. The fitting process would be the same. The Optimization, Global Optimization, and Statistics and Machine Learning Toolboxes have nonlinear parameter estimation routines that should works with that, although the Global Optimization Toolbox functions could be more robust.
Another option would be to use the System Identification Toolbox functions to fit it. (Remember to use the compare function to get a visual representation of how good the fit is.)
.
See Also
Categories
Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!