MATLAB: Findpeaks ( ‘WidthRefe​rence’,’ha​lfheight’ ) not finding width of peak

MATLABpeaksignal processing

Hi
I'm trying to find ( 'WidthReference','halfheight') something like this image
but it is not showing using this code , could you please show
me where is my error .
order =3 ;
framelen =13;
Averages=[R,L]';
Averages=mean(Averages)';
AV=smooth(Averages,6);
x=AV;
lx = 20;
sgf = sgolayfilt(x,order,framelen);
plot(sgf);
hold on;
findpeaks(sgf,'MinPeakProminence',0.003);
[pks,locs,widths,proms]=findpeaks(sgf,'Annotate','extents','WidthReference','halfheight');
pks= -pks;
plot(locs,pks,'g*');
text(locs+.02,pks,num2str((1:numel(pks))'));
this the output I get

Best Answer

I think you wanted this instead:
findpeaks(sgf,'MinPeakProminence',0.003,'WidthReference','halfheight','Annotate','extents');
[pks,locs,widths,proms]=findpeaks(sgf,'MinPeakProminence',0.003,'WidthReference','halfheight');
(use the same settings for when you plot without output arguments vs. when you do your assignment).