How to separate waves from a signal
13 views (last 30 days)
Image Analyst on 1 Jul 2022
If you have the Image Processing Toolbox (used to find the center of the "silent" parts), try this:
% Demo by Image Analyst
% Initialization Steps.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
fontSize = 20;
s1 = load('signal.mat')
s2 = load('time.mat')
y = s1.signal;
t = s2.time; % Don't use time as the name of a variable since it's a built-in function.
subplot(3, 1, 1);
plot(t, y, 'b-');
[upper, lower] = envelope(y, 30, 'peak');
plot(t, upper, 'r-', 'LineWidth', 2);
threshold = 0.01;
mask = upper < threshold;
% Throw out any sections narrower than, say, 50 elements.
mask = bwareafilt(mask, [50, inf]);
yline(threshold, 'Color', 'g', 'LineWidth', 2)
y(mask) = 0;
title('Signal plus envelopes and threshold', 'FontSize', fontSize)
subplot(3, 1, 2);
plot(t, mask, 'g-', 'LineWidth', 4)
title('Mask indicating where no signals are', 'FontSize', fontSize)
% Find the centroid (half way point between the pulses and the peak intensities
% because we want to erase the shorter pulses between those half way points.
propsFlat = regionprops(mask, 'Centroid');
xy = vertcat(propsFlat.Centroid);
midPoints = round([1; xy(:, 1); numel(mask)])
% Now scan across each pulse section and if the max value
% in that section is less than 0.5 erase the whole section.
yMasked = y; % Initialize.
for k = 1 : length(midPoints) - 1
index1 = midPoints(k);
index2 = midPoints(k+1);
if max(y(index1 : index2)) <= 0.5
yMasked(index1 : index2) = 0; % Erase this section.
subplot(3, 1, 3);
plot(t, yMasked, 'b-', 'LineWidth', 1)
title('Masked Signals', 'FontSize', fontSize)
More Answers (2)
Image Analyst on 30 Jun 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:
Jeffrey Clark on 30 Jun 2022
@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.