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!

