add the peak values of a signal to a graph regardless of number of peaks

조회 수: 5 (최근 30일)
Vitor
Vitor 2020년 1월 13일
답변: Star Strider 2020년 1월 14일
Hi, I'm having a problem that should be easy to solve but I'm not getting. I will try to explain, I have a data matrix corresponding to the time and peak force value applied to a load cell.
peaks = [temp1 peaks]
I need to add the values of each of these peaks in the attached chart. How can I do this?
function [ resultado ] = nadoatado10s( dat1,coefcalib )
if nargin == 2
dat_kg = coefcalib(1,1)* dat1(:,2) + coefcalib(1,2);
datkg = abs(dat_kg);
elseif nargin == 1
datkg = dat1;
end
freq = 1000;
tanalise = 10*freq;
dat1 = datkg.*9.7784;
dats = smooth(dat1(:,1),(freq/10),'moving');
datf = filtbutter(dats,15,freq);
figure('units','normalized','outerposition',[0 0 1 1])
plot(datf(:,1),'-')
title('Full cell data'); grid on; hold on; xlabel('Sample'); ylabel('Force [N]')
legend('Mark the activity beginning','Location','Best');
[x,y] = ginput(1); close all;
x = round(x);
y = x - tanalise; datcal = datf(y:x,1);
datcal = datcal(:,1); [nl,nc] = size (datcal); temp = [(0:nl-1)/freq]; %definindo var para tempo.
imp = trapz(temp,datcal);
[maxf,l] = max(datcal(:,1));
med = mean(datcal(:,1));
[mi,l2] = min(datcal(:,1));
fi = (maxf*10)-imp;
fiper = ((fi*100)/(maxf*10));
resultado = [maxf med fi imp fiper]; disp(' '); disp('OUT = [FORÇA MAX | FORÇA MEDIA | INDICE DE FADIGA REAL | IMPULSO | INDICE DE FADIGA [%]]'); %Disparando moldes de resultado em ordem de saída
txtmaxf = ['\fontsize{12} \leftarrow FORÇA MÁXIMA = ',num2str(maxf)]; txtmed = ['\fontsize{12} \leftarrow FORÇA MÉDIA = ',num2str(med)]; %Cria texto ref maxf e medf
limiar=med(1,1); [picos l3]=findpeaks(datcal,'MinPeakHeight',limiar,'MinPeakDistance', 300); temp1 = l3/freq; picos = [temp1 picos];
figure('units','normalized','outerposition',[0 0 1 1]) do)
plot(temp,datcal,'LineWidth',2,'LineStyle','-','Color','b'); title('Full cell data'); grid off; hold on; xlabel('Time [s]'); ylabel('Force [N]'); legend('Results on plot','Location','Best'); %Legenda
plot(picos(:,1),picos(:,2),'or');
line ([0 11], [maxf(1,1) maxf(1,1)],'LineWidth',2,'LineStyle','--','Color','r');
line([0 11],[med(1,1) med(1,1)],'LineWidth',2,'LineStyle','--','Color','k');
text(11.8,maxf(1,1)-5,txtmaxf,'HorizontalAlignment','right'); text(11.8,med(1,1)+5,txtmed,'HorizontalAlignment','right');
% B = arrayfun(@num2str,picos(:,2),'un',0);
%% I need help from here on putting the values on the chart.
end
function [datf] = filtbutter(dat,fc,freq,ftype) %Filtro Digital
if nargin == 2;
freq = 100;
ftype = 'low';
end
if nargin == 3;
ftype = 'low';
end
n=5; %ordem do filtro
wn=fc/(freq/2); %frequencia de corte de
[b,a] = butter(n,wn,ftype); %definindo os parametros para o filtro de Butterworth
[nlin,ncol] = size(dat);
datf = NaN(nlin,ncol);
for i = 1:ncol;
datf(:,i) = filtfilt(b,a,dat(:,i));
end
end
  댓글 수: 3
Vitor
Vitor 2020년 1월 14일
This only returns the sum of the peaks, I need to plot the value corresponding to the circle in each red circle in graph. You can help me please?
Meg Noah
Meg Noah 2020년 1월 14일
If idxMaxIndex holds the elements where the data are max, and ECG holds the data itself, then if you want rotated annotation (you can skip the rotation if you prefer)
for iheartbeat = 1:length(idxMaxIndex)
ht = text(1e3*t(idxMaxIndex(iheartbeat)), ...
ECG(idxMaxIndex(iheartbeat))+30, ...
['idx = ' num2str(idxMaxIndex(iheartbeat))]);
set(ht,'rotation',90);
end

댓글을 달려면 로그인하십시오.

답변 (1개)

Star Strider
Star Strider 2020년 1월 14일
Your code is a bit difficult to follow.
Insert this text call just after the plot call for the red circles:
text(picos(:,1), picos(:,2), compose('%.2f', picos(:,2)), 'HorizontalAlign','center', 'VerticalAlign','bottom')
so the complete call for the second figure is now:
figure('units','normalized','outerposition',[0 0 1 1])
plot(temp,datcal,'LineWidth',2,'LineStyle','-','Color','b');
title('Full cell data');
grid off;
hold on;
xlabel('Time [s]');
ylabel('Force [N]');
legend('Results on plot','Location','Best'); %Legenda
plot(picos(:,1),picos(:,2),'or');
text(picos(:,1), picos(:,2), compose('%.2f', picos(:,2)), 'HorizontalAlign','center', 'VerticalAlign','bottom')
line ([0 11], [maxf(1,1) maxf(1,1)],'LineWidth',2,'LineStyle','--','Color','r');
line([0 11],[med(1,1) med(1,1)],'LineWidth',2,'LineStyle','--','Color','k');
text(11.8,maxf(1,1)-5,txtmaxf,'HorizontalAlignment','right');
text(11.8,med(1,1)+5,txtmed,'HorizontalAlignment','right');
and the figure is:
1add the peak values of a signal to a graph regardless of number of peaks - 2020 01 13.png
Thie is entirely dependent on whatever is in ‘picos’, so when it changes, the plotted labels change accordingly. Make necessary changes to the font size and other parameters to get the result you want.
If you do not have the compose function, use sprintfc instead. It is undocumented, however everyone has it. The arguments to compose are the same as for sprintfc, so only the function name changes.

카테고리

Help CenterFile Exchange에서 Design Condition Indicators Interactively에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by