How to divide a signal into groups of peaks
Show older comments
Hi, i have an audio sample , which im trying to divide into groups of signals , for energy and time analysis . here is the signal :

what i'm trying to do is, to get the start and the end indexes of this 4 chunks. right now i dont have a clue how to get this done . Thank you
4 Comments
Azzi Abdelmalek
on 13 Jul 2015
What are your criterion? What do you mean by start and end?
Luis Gomes Perini
on 13 Jul 2015
Hi,
your question is how to develop an algorithm that captures such peaks, or how to determine the start/end of peaks ?
Cheers, Luis Gomes Perini
cob
on 13 Jul 2015
Accepted Answer
More Answers (1)
Image Analyst
on 13 Jul 2015
Edited: Image Analyst
on 26 Dec 2020
Well, being an image analyst, I came up with a different approach. You can get a logical array defining what's a signal and what's the quiet parts with just two lines of code, one to threshold and one to do a morphological filter. Here's a full blown demo:
% Setup - read in the signal and plot it.
s=load('signal.mat')
signal = s.coarse_d;
subplot(3,1,1);
plot(signal, '-', 'Color', [0,.5,0]);
grid on;
% MAIN CODE IS THE FOLLOWING TWO LINES OF CODE.
% Threshold the signal
lowSignal = abs(signal) < 0.1;
% Remove stretches less than 10,000 elements long.
% And invert it to get the high signal areas instead of the quiet areas.
lowSignal = ~bwareaopen(lowSignal, 10000);
% Now we're done. Plot the results.
subplot(3,1,2);
plot(lowSignal, 'b-', 'LineWidth', 2);
grid on;
% Plot both on the same graph now.
subplot(3,1,3);
plot(signal, '-', 'Color', [0,.5,0]);
hold on;
plot(lowSignal, 'b-', 'LineWidth', 2);
grid on;

8 Comments
Image Analyst
on 13 Jul 2015
If you have a binary signal (true or false), then bwareaopen() lets you say how big are the "connected components" that you want to keep. For example in the "signal" part, the signal goes up and down very rapidly so there are hundreds of small chunks that are more than the threshold with hundreds of small chunks in between them where the signal value is low. We don't want all those low amplitude parts that occur in the main pulses of the signal. We only want to keep a quiet part if it's more than, say, 10,000 elements long. If it's only like 20 or 50 long, we want to throw those away - we don't want them because they're in the oscillating main signal pulses, not in the long stretch of quiet in between the main pulses. So calling that tells it to throw away short quiet chunks and only keep the really long quiet chunks. Does that explain it?
Star Strider
on 13 Jul 2015
That seems analogous to findpeaks with the appropriate 'MinPeakDistance' value set to ignore peaks within a set range of the designated x-variable (index or defined).
I have the Image Processing Toolbox, but haven’t used it to process 2D data. I may be overlooking significant functionality.
cob
on 13 Jul 2015
Image Analyst
on 13 Jul 2015
I just looked at the length of the gaps and picked something that I thought would be way longer than any short segment in the pulse, but not so long as to get rid of the long quiet stretches if your pulses happened to be closer together than what you showed (so it does not fail in some other data set).
MA-Winlab
on 12 Feb 2019
after identifying the non-silent parts, how can you put their data points in a colomn of a matrix. i.e., can you create a matrix that has the data points of each identified portion as a colomn. For example if there are 10 splikes (non silent portions), then how to store them (as data points) in 10 colomns in a matrix.
Thank you
Image Analyst
on 13 Feb 2019
You'd have to extract each segment using indexing then put them into a cell array because each segment won't have the same number of elements and thus cannot be put into a double array (unless the ends were padded with zeros or nans or something.
Surabhi KS
on 30 Sep 2021
You can make a class object.
Categories
Find more on Get Started with Signal Processing Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
