How to separate waves from a signal
Afficher commentaires plus anciens
I have the following signal on the image above:

I want to delete all the waves of small amplitudes (under 0.1) and retrace the signal so I can have this figure
3 commentaires
Jeffrey Clark
le 30 Juin 2022
@Abdelhakim Souidi , you could use Find local maxima - MATLAB findpeaks (mathworks.com) with appropriate settings to identify all local peaks and then just ones above 0.1 then zero the amplitudes between the X midpoints of the high and low peak points that include the low peaks. If you dont have the Signal Processing Toolbox a more work is needed to use the find function and others to issolate the actual few high and low peaks before setting amplitudes to zero.
Image Analyst
le 30 Juin 2022
@Jeffrey Clark, your Comment actually looks like an "Answer" to me, not a Comment. Can you therefore move it down to the official "Answers" section? This "Comments" section, where you posted, is supposed to be where people ask the original poster to clarify the wording of the question, attach data, etc. Answers go below in the Answers section. A benefit is that down there (unlike here) you can earn "reputation points" if the original poster Accepts your Answer or if anyone clicks the "Vote" icon. Thanks in advance. 🙂
Abdelhakim Souidi
le 1 Juil 2022
Réponse acceptée
Plus de réponses (2)
Image Analyst
le 30 Juin 2022
Not hard, but you forgot to attach your data. But it would go something like this
[upper, lower] = envelope(y);
mask = upper < 0.1;
y(mask) = 0;
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
1 commentaire
Abdelhakim Souidi
le 1 Juil 2022
Jeffrey Clark
le 30 Juin 2022
0 votes
@Abdelhakim Souidi , I couldn't determine if you had the data or just an image to work with. If you are working with just an image the someone with image processing could provide a more appropriate response. If you are looking to separate the signals in data you have (although they look very separate with the little information you provided) then from the information provided frequency is expected not to be a discriminator and only amplitude at the peaks are. If that is the case please refer to my original comment as one approach to your answer. Please mark as answered if you find this true.
7 commentaires
Abdelhakim Souidi
le 1 Juil 2022
Jeffrey Clark
le 1 Juil 2022
Modifié(e) : Jeffrey Clark
le 1 Juil 2022
@Abdelhakim Souidi ,@Image Analyst, so you know how to find the tall ones (green), do that again to find all of them (red and green), the difference being the ones to be suppressed.

Difference the locs of the ones to keep and discard to find the midpoints, then set sh1(ty>lower & ty<upper) = 0. So assuming you get pks2 and locs2 contining them all then something like this:
discard = find(~any(locs'==locs2));
% should account for the case where might be zero or more than one short peaks
for i = discard
if i == 1
sh1(ty<(locs2(i+1)+locs2(i))/2) = 0;
elseif i==length(locs2)
sh1(ty>=(locs2(i-1)+locs2(i))/2) = 0;
else
sh1(ty>=(locs2(i-1)+locs2(i))/2 & ty<(locs2(i+1)+locs2(i))/2) = 0;
end
end
Abdelhakim Souidi
le 1 Juil 2022
Abdelhakim Souidi
le 1 Juil 2022
Jeffrey Clark
le 1 Juil 2022
@Abdelhakim Souidi , yes I kept saying midpoint but didn't when working without real data. I don't have access to findpeaks so I rolled my own, I updated the sample code above and got this with your data. Note that if the tiny signal leading into/out of the large signals is an issue you may want to zero data closer to the large peaks than midway:

Abdelhakim Souidi
le 1 Juil 2022
Modifié(e) : Abdelhakim Souidi
le 1 Juil 2022
Jeffrey Clark
le 1 Juil 2022
@Abdelhakim Souidi , I assume you are getting the peaks you wanted with your post:
[pks,locs, wdth] = findpeaks(sh1,ty,'MinPeakProminence',0.1,'Annotate','extents','WidthReference','halfheight');
As I said I don't have access to findpeaks but reading the documentation the parameters 'Annotate' and after only apply to when there are no returns requested and a plot is made, so only 'MinPeakProminence',0.1 affects the default behavior. In addition, the data you posted in signal.mat and time.mat doesn't match the figures you posted (compare with my plot from these files in previous post). If the MinPeakProminence you used actually found the large peaks in your plots I don't think the value would work for the data you sent, and I'm not sure what it would need to be to find both the small and large peaks without picking up peaks nearby. Perhaps you should look into using both 'MinPeakHeight' and 'MinPeakDistance' instead.
I added documentation of what the code I provided expectations are:
% locs is the rerurn from findpeaks for the time (ty) relative data for the large amplitude peaks
% locs2 is the rerurn from findpeaks for the times for large and small peaks
% sh1 is the sampled signal amplitude
% ty is the time associated with each sample amplitude
discard = find(~any(locs'==locs2));
for i = discard % clear amplitudes associated with the small peaks
if i == 1
sh1(ty<(locs2(i+1)+locs2(i))/2) = 0;
elseif i==length(locs2)
sh1(ty>=(locs2(i-1)+locs2(i))/2) = 0;
else
sh1(ty>=(locs2(i-1)+locs2(i))/2 & ty<(locs2(i+1)+locs2(i))/2) = 0;
end
end
Catégories
En savoir plus sur Descriptive Statistics dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
