Automatic Signal segmentation for feature extraction
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
Hi,
Does anyone know how to do signal segmentation on the raw signal? I need to segment the raw signal into 8 different segments so that i can do feature extraction on individual segments.

2 件のコメント
Star Strider
2018 年 1 月 21 日
What is the corresponding time vector that corresponds to those samples, or the sampling frequency?
Radons
2018 年 1 月 21 日
It is sampled at 1Khz
採用された回答
Image Analyst
2018 年 1 月 21 日
Attach some signals so we can play with them.
Assuming the "tall" parts of the signal are not uniformly spaced (in which case you could extract them trivially with indexing at fixed indexes), then you need to find the center of the quiet parts. I'd start by thresholding the absolute value of the signal to find the low/quiet parts. You should have 9 of them, unless your tall signal parts hit the edge of your range. If you don't have 9, then I'd call imdilate repeatedly until you get exactly 9 quiet regions. Then I'd call regionprops() to get the centroid (middle index) of the quiet parts, and then I'd loop over the regions extracting the tall regions into cells. They need to be in cells because each region might have a different number of elements. Something like (untested)
quietParts = abs(signal) < threshold;
[~, numRegions] = bwlabel(quietParts);
while numRegions > 9
quietParts = imdilate(quietParts, [1,1,1]);
[~, numRegions] = bwlabel(quietParts);
end
% Now we should have the quiet parts. Find the centroids.
props = regionprops(quietParts, 'Centroid');
% Extract each tall signal part into a cell
for k = 1 : length(props)-1
index1 = round(props(k).Centroid;
index2 = round(props(k+1).Centroid;
individualSignals{k} = signal(index1:index2);
end
Note, the code above requires the Image Processing Toolbox.
19 件のコメント
Radons
2018 年 1 月 21 日
I just attached the signal at the top.
Anyway what do you mean by 9 quiet parts?
Image Analyst
2018 年 1 月 21 日
Like the parts with amplitude less than about 0.01 or so.
This works:
s = load('signal.mat')
signal = s.x;
subplot(2, 1, 1);
plot(signal, 'b-');
grid on;
threshold = 0.004;
subplot(2, 1, 2);
filteredSignal = sgolayfilt(abs(signal), 2, 2001);
plot(filteredSignal, 'b-');
grid on;
hold on;
quietParts = abs(filteredSignal) < threshold;
[~, numRegions] = bwlabel(quietParts)
while numRegions > 9
quietParts = imdilate(quietParts, [1,1,1]);
[~, numRegions] = bwlabel(quietParts);
end
% Now we should have the quiet parts. Find the centroids.
props = regionprops(quietParts, 'Centroid');
% Extract each tall signal part into a cell
for k = 1 : length(props)-1
index1 = round(props(k).Centroid(1));
index2 = round(props(k+1).Centroid(1));
line([index1, index1], ylim, 'Color', 'r');
line([index2, index2], ylim, 'Color', 'r');
individualSignals{k} = signal(index1:index2);
end
% Make a new figure.
figure
for k = 1 : length(individualSignals)
subplot(3, 3, k);
plot(individualSignals{k}, 'b-');
grid on;
end


Radons
2018 年 1 月 22 日
Thanks!! this is exactly what i wanted.
can i ask how do you choose the threshold to be 0.004 and framelen of the sgolayfilt function to be 2001?
Image Analyst
2018 年 1 月 22 日
For the 0.04, I just looked at the plots to find a threshold where about 8 peaks would be detected.
For the frame length, I just experimented until the smoothed curves showed the peaks and valleys well without too much noise. The shorter the frame length, the more closely it will look like the original noisy signal, making it harder to find the 8 peaks and 9 valleys.
Are there any ways to remove the noisy signals and extract only the peaks?
Image Analyst
2018 年 1 月 25 日
What are the peaks? For each chunk there are dozens of peaks.

Sorry for being unclear. I am referring to just the windowed segments as shown above.
Just threshold each chunk at 0.01 or whatever is just above the noise level, like this:
thisSignal = individualSignals{k}
index1 = find(thisSignal > 0.01, 1, 'first');
index2 = find(thisSignal > 0.01, 1, 'last');
croppedSignal = thisSignal(index1:index2);
Radons
2018 年 1 月 25 日
hmm. i actually have 35 other signals that does not have the same threshold. For example, if my noise threshold for the 1st signal is 0.02, the 2nd signal can be 0.01. So if i were to threshold it at a fixed value, say 0.02, then the 2nd signal will have some of the 'active' signal getting cut off. Any idea how to fix that?
Image Analyst
2018 年 1 月 25 日
You can try sgolayfilt with a shorter window to smooth it, then perhaps use findchangepts() to identify where it starts climbing.
Image Analyst
2022 年 11 月 1 日
It means you altered my code so that you're not assigning "individualSignals". Why did you change it to not assign those? Or else you're using a signal that should use a different threshold than I used for the original poster.
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
@Cey your mat file does not have a signals variable in it
s = load('matlab.mat')
s = struct with fields:
data: [10000×1 double]
data = s.signal;
Unrecognized field name "signal".
So what do you think you should do? How about getting the data field of s rather than the signal field?
I guess you didn't get the hint. Your field is called data so you should do
s = load('matlab.mat')
data = s.data;
That code does not create individualSignals at all in the case that either no regions or exactly one region are found in the data. You should initialize it with
individualSignals = cell(length(props)-1, 1);
Image Analyst
2022 年 11 月 2 日
Your threshold of 0.004 is not good when used with your filtered signal. So you get no regions. And you're filtering it WAY too much, so much so that you've pretty much lost any resemblance of the original signal.
Cey
2022 年 11 月 4 日
Thanks a lot, so what values should I get? @Image Analyst
Cey
2022 年 11 月 4 日
thank you for your help @Walter Roberson
Image Analyst
2022 年 11 月 4 日
その他の回答 (1 件)
Hristo Zhivomirov
2019 年 10 月 13 日
Hi, Radons!
I think that this the most suitable, easy-to-use and straightforward way.
Also, you can use the example.m file as reference.
All best,
Hristo
カテゴリ
ヘルプ センター および File Exchange で Descriptive Statistics についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
