Extract segments from signal
이전 댓글 표시
Hi,
I have a signal in form of a 6608x1 double and I'd like to extract segments from that signal.

I want to extract every segment of the signal where the signal drops by at least 3% compared to the prior max value. Also, the segments are only valid if the duration is at least 150 seconds. As soon as the signal goes up again, the segment is over. I want to store these segments in a seperate array, so I can plot these segments on top of the signal to highlight where the signal drops by at least 3% for at least 150 seconds.
Can someone help me define the criteria for this task in Matlab? I'm not quite sure how to approach this.
This is a drawing of how I would like this to look when I plot the segments on top of the signal.

Thanks in advance!
댓글 수: 4
Luca Ferro
2023년 5월 24일
could you please share the said signal in a .mat file?
Samuel
2023년 5월 24일
Daniel
2023년 5월 24일
What do you mean by "prior max value"? How is the prior max defined?
Samuel
2023년 5월 24일
채택된 답변
추가 답변 (1개)
Luca Ferro
2023년 5월 24일
편집: Luca Ferro
2023년 5월 24일
This is the closest i could go as of right now, i'll revise it in the next days. But i'll share it so that someone else can build on it to reach the final solution.
Basically what it does is analyzing the signal flat section per flat section.
flat=diff(signal);
[peaks ,peaksIdx]=findpeaks(signal); %find peaks
highlight=nan(size(signal,1),1);
peaksIdx=[peaksIdx ; inf];
for pp=1:size(peaks,1)-1 %loopsthrough each peak
ss=peaksIdx(pp);
peakLen=1;
startPeak=ss;
while ss<peaksIdx(pp+1) && signal(ss)==peaks(pp) && flat(ss)==0
peakLen=peakLen+1;
ss=ss+1;
end %detects peak and moves to the end of it
while flat(ss)~=0 && ss<peaksIdx(pp+1)
ss=ss+1;
end %moves to the next flat area
while ss<peaksIdx(pp+1) && flat(ss)==0
startFlat=ss;
flatLen=1;
if signal(ss)/peaks(pp) > 0.3
flatLen=flatLen+1;
end
highlight(startFlat:startFlat+flatLen-1)=signal(startFlat:startFlat+flatLen-1);
ss=ss+1;
end %if the flat area has the proper specifics highlights it
end
plot(signal,'color','blue');
hold on
plot(highlight,'color','red','LineWidth',3)
The issue that this has is that it only highlights the first drop and not the following ones.

Disclaimer: is not the best approach, is not the cleanest code. I'll revise the abuse of loops later to find a better structure.
카테고리
도움말 센터 및 File Exchange에서 Descriptive Statistics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

