Function lsqlin smooth results
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi, I used lsqlin to create a linear model. The results are like this: ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1183788/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1183788/image.png)
There are hard peaks and i want to smoot them. In first try i used A and b lsqlin(C,d,A,b) to limit the gradients. The results are like these
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1183793/image.png)
Thank you very much!
0 commentaires
Réponse acceptée
Matt J
le 10 Nov 2022
Modifié(e) : Matt J
le 10 Nov 2022
You could add smoothing penalties on first differences to your lsqlin data. Assuming your signal is of length n, this would look like,
D=beta*diff(eye(n)); %differencing operator, in matrix form, with penatly weight beta
z=zeros(n-1,1);
C=[C;D];
d=[d;z];
signal = lsqlin(C,d,A,b);
0 commentaires
Plus de réponses (1)
Youssef Noureddine
le 10 Nov 2022
Hi Tobias,
I have 2 primary suggestions that would help you smooth this data,
- I would try using the 'smooth' function and selecting low span numbers and varying the smoothing method to and select the pair that produce the most ideal result.
https://www.mathworks.com/help/curvefit/smooth.html
- If that doesn't work, you can use the interp1 function to interpolate points between each sample to artifically smoothen the data. You can select the interpolation method to things such as 'cubic' or 'spline' here (although linear might work depending on if your sampling frequency is high enough). I would first start by interpolating mid way points to see if that is enough. If it is still rough, I would find every quarter jump and keep shrinking the jump size until your data is smooth enough.
https://www.mathworks.com/help/matlab/ref/interp1.html
Sincerely,
Youssef
0 commentaires
Voir également
Catégories
En savoir plus sur Linear Least Squares dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!