Deleting overlapping segments between two vectors

2 views (last 30 days)
Hi all,
I have two speech signals represented as two logical vectors where 1 = speech and 0 = no speech. I want to find places where both channels contain speech and delete those segments in both arrays.
As a test script, I have the following:
a = zeros(1,20);
b = zeros(1,20);
a(1:3) = 1; a(7:10) = 1; a(18:20) = 1;
b(4:6) = 1; b(9:12) = 1; b(15:17) = 1;
for i = 1:numel(a)
if a(1,i)==1 && b(1,i)==1
crossval(1,i) = true;
else
crossval(1,i) = false;
end
end
% Positions where both channels are = 1
idx = find(crossval==1)
From this example code, I want to remove the segment in position 7-10 in vector a and segment in position 9-12 in vector b since they are overlapping, and I want to keep the other segments.
Does anybody have a good idea on how to do this?

Accepted Answer

darova
darova on 30 Mar 2020
Use bwselect
cross = a.*b;
ix = find(cross); % cross indices
ia = bwselect(a,ix,1+ix*0); % find regions in 'a'
ib = bwselect(b,ix,1+ix*0); % find regions in 'b'
a(ia) = [];
b(ib) = [];
  2 Comments
Sine Palm
Sine Palm on 30 Mar 2020
Thanks for you suggestion - unfortunately I don't have the imageToolbox and no license for it. Do you have a suggestion without that toolbox?
darova
darova on 30 Mar 2020
try this
function main
clc
a = zeros(20,1);
b = zeros(20,1);
a(1:3) = 1; a(7:10) = 1; a(18:20) = 1;
b(4:6) = 1; b(9:12) = 1; b(15:17) = 1;
cross = a & b;
ac = fselect(a,cross);
bc = fselect(b,cross);
[a b cross ac bc]
end
function ac = fselect(a,cross)
ac1 = ffill(a,cross); % fill forward
ac2 = ffill(flip(a),flip(cross)); % fill backward
ac = ac1 | flip(ac2); % merge
end
function ac = ffill(a,cross)
ac1 = cross;
for i = 1:length(a)-1
if ac1(i) == a(i+1)
ac1(i+1) = ac1(i);
end
end
ac = ac1;
end

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!