Signal processing - difficult. How to extract specific parts of the signal identified via findpeaks?

4 views (last 30 days)
Hi all,
I have a signal (attached) which is a sensor orientation y during human walking. I have identified certain indices in the signal (attached 'start'', red circles over the signal) and I am extracting parts of the signal between those indices using the code below.
However, I want to discard (ignore) part of the signal between two blue x-es (on the left at the bottom) which is a moment when a person turns around and start walking again. Any idea how to do this?
load 'signal'
load 'start'
%This is how I indetify the indices
% Identify all troughs in data
[all_trough_value,all_trough_location]= findpeaks(-thigh_orient_y, 'MinPeakProminence',7);
all_trough_value = -all_trough_value;
% Identify main trough (i.e. main peaks with a prominence of at least 10)
[main_trough_value,main_trough_location]= findpeaks(thigh_orient_y,'MinPeakProminence',15);
% Identify first local minima before main through (start of the cycle)
counter = 0;
for i = 1:length(main_trough_location)
index = find(all_trough_location < main_trough_location(i),1,'last');
if isempty(index)
continue
end
counter = counter + 1;
start_location(counter) = all_trough_location(index); % find start location
start_value(counter) = all_trough_value(index); % find start value
end
%Settings
T_or_y = thigh_orient_y;
a = start_location;
n = length(a)-1;
T_or_y_cycle = cell(n,1) ;
%Fill in cells with signal between the indices
for i = 1:n
T_or_y_cycle{i} = T_or_y(a(i):a(i+1)) ;
end
%Plot all over one figure
figure;
hold on
for i = 1:length(T_or_y_cycle)
plot(T_or_y_cycle{i},'r') ;
title('RThigh orientation Y'); xlabel('% of movement cycle'); ylabel('degrees')
box off; axis tight;
end
Ideally, the solution should work also for walking on the stairs (walk up twice and walk down twice)/ attached 'signal 2' and 'start2'

Accepted Answer

Image Analyst
Image Analyst on 17 Feb 2022
What does "discard" mean to you? Do you just want to set them to the min value?
% Create a mask
mask = some function that will be easier if you have the Image Processing Toolbox.
signal(mask) = min(signal);
Or maybe just remove those elements so the second part is stitched onto the first part
signal(mask) = [];
In either case you have to create a mask that identifies the parts you want to discard. You might be able to use movmax() with an appropriate window size, then threshold and use bwareafilt() from the Image Processing Toolbox to identify runs of a certain length. If you don't have that toolbox you can probably inspect the spacing betwee peaks and if it's too long, delete the elements in between.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!