smoothing with Gaussian Kernel for loop problem

1 vue (au cours des 30 derniers jours)
KHOULOUD DABOUSSI
KHOULOUD DABOUSSI le 16 Nov 2022
Commenté : Mathieu NOE le 22 Nov 2022
im having a probelm with smoothing the data "ys" using gaussian kernel function everytime i run the for loop i recieve uhat = ys and kerf = 0 0 0 0 0 ... anyone can help me?
ns =length(ys);
nv =length(tv);
lambda = 0.05;
tv = (1:1:1000)';
for i = 1 : ns
k=(tv-tv(i));
kerf=exp(-k.*k/2*(lambda^2))/(sqrt(2*pi)*lambda);
uhat(i)=sum(kerf.*ys(i))/sum(kerf);
end

Réponse acceptée

Mathieu NOE
Mathieu NOE le 18 Nov 2022
hello
try this
lambda = 0.05;
tv = (1:1:1000)';
nv =length(tv);
ys = sin(4*pi*tv./max(tv))+0.25*rand(nv,1);% dummy data
for i = 1 : nv
k=(tv-tv(i));
kerf=exp(-k.*k/2*(lambda^2))/(sqrt(2*pi)*lambda);
uhat(i)=sum(kerf(:).*ys(:))/sum(kerf);
end
plot(tv,ys,tv,uhat);
  8 commentaires
KHOULOUD DABOUSSI
KHOULOUD DABOUSSI le 21 Nov 2022
by chance,do you have any idea how to select the optimal bandwidth (lambda)? not using ksdensity?
Mathieu NOE
Mathieu NOE le 22 Nov 2022
hello again
well, statistics are not my field of expertise
there are some publications that describe some methods for optimal tuning of lambda
but then i's up to you to code that as a matlab function (would basically be your own version of ksdensity)

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by