using 'controlchart' and 'findpeaks'

2 views (last 30 days)
Fercho_Sala on 13 Apr 2021
Commented: Star Strider on 15 Apr 2021
Hello everybody. I’m using the function “controlchart” to analyze something like the data in the picture, however I was wondering how to use the ‘’findpeaks’’ function to identify the peaks in the red circles and also the width of those peaks. Apparently the ‘’findpeaks’’ function doesn’t work properly in this case, it is possible to use both functions in one chart?. Thank you.
  1 Comment
Mathieu NOE
Mathieu NOE on 13 Apr 2021
we could probably better help you if you share a code and data

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 13 Apr 2021
That is going to be something of a challenge, however it is possible.
Using an example from the controlchart documentation:
load parts
st = controlchart(runout,'charttype',{'xbar' 'r'});
Ax = gca; % Axis Handle
Kids = Ax.Children; % Axis ‘Children’
x = Kids(4).XData; % Choose Desired Variable, Get ‘XData’
y = Kids(4).YData; % Choose Desired Variable, Get ‘YData’
[pks,locs] = findpeaks(y, 'MinPeakProminence',0.5); % Peaks With Desired Characteristics
plot(x, y)
hold on
plot(x(locs), y(locs), '^r')
hold off
That should work, although it will likely be necessary to experiment with it to get the correct variable and the desired peak characteristics.
Star Strider
Star Strider on 14 Apr 2021
@Walter Roberson — Thank you!
@Fernando Salamanca Guerrero — I cannot comment on how well my code works with your data. It may be necessary to change the code to work correctly with it, since it may have different characteristics from the characteristics of the data in the example code from the documentation that I used. I cannot help you with that because I do not have the data you are using, or your controlchart call. If you provide those, I can do more than guess as to what the correct approach would be.

Sign in to comment.

More Answers (1)

Fercho_Sala on 15 Apr 2021
Edited: Fercho_Sala on 15 Apr 2021
@Star Strider Here is the part of the code with the issue, it has been a bit difficult to identify the peaks in the 'controlchart' plot, so for that reason, I generated another plot for the 'findpeaks' function. However the idea is to mix the both functions in just one chart, overlapping by the 'findpeaks' results on the 'controlchart'. Tthe dataset is attached.
load parts;
st2 = controlchart(pws1,y,'Parent',ax9);
ax9.YGrid = 'on';
ax9.XGrid = 'on';
ax9.Children(1).Color = 'w';
ax9.Children(2).Color = 'w';
%%%tile and labels
title('Power [dB]');
ax9.XAxis.FontSize = 7
ylabel('Power dB for a LT 2.5h (7:30 - 10:00)','FontSize',11,'color','default');
xlim 'manual'
xlim(ax9,[95 151]);
ytickformat('%g dB');
ax9.XDir = 'reverse';
ax9.YAxisLocation = 'right';
%2.5h (7:30 - 10:00)
load parts;
[pks,locs,widths2,proms2] = findpeaks(pws1(:,151),y,'MinPeakHeight',30);
legend('Filtered Data','Peak','Prominence','Width');
ax11.YAxisLocation = 'right';
ax11.XDir = 'reverse';
ax11.XGrid = 'on';
ax11.YGrid = 'off';
title ('Layering (7:30 - 10:00)');
ylabel('Layering identification','FontSize',11,'FontName','Arial','color','default');
xlim(ax11,[75 95]);
ylim(ax11,[10.5 36]);
%number of peaks found
numberpks1 =(findpeaks(pws1(:,151),y,'MinPeakHeight',30));
numberpks2 =(findpeaks(pws2(:,151),y,'MinPeakHeight',30));
Star Strider
Star Strider on 15 Apr 2021
As always, my pleasure!
I definitely agree!

Sign in to comment.




Community Treasure Hunt

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

Start Hunting!