How to automate extraction of multiple parts of a signal?

1 view (last 30 days)
Hi all,
I have a signal ('gas_lat_env_norm') collected over a 10 s period ('time'). I have identified timings of certain events ('l_heel_strike_uncroppedtime') and plotted them over the signal (events 1,2,3 red circles).
I want to:
  • extract the signal between 1 and 2
  • extract the signal between 2 and 3
I am able to do this in this way:
load 'gas_lat_env_norm' % load signal
load 'time' % load time
load 'l_heel_strike_uncroppedtime' % load timings of events
% Extract the signal between event 1 and event 2
ind1=time>=l_heel_strike_uncroppedtime(1) & time<=l_heel_strike_uncroppedtime(2); % cycle 1
gas_lat_cycle1 = gas_lat_env_norm(ind1);
% Extract the signal between event 2 and event 3
ind2=time>=l_heel_strike_uncroppedtime(2) & time<=l_heel_strike_uncroppedtime(3); % cycle 2
gas_lat_cycle2 = gas_lat_env_norm(ind2); % signal
% plot first extracted signal
figure('color','w');
plot(time(ind1),gas_lat_env_norm(ind1))
ylabel('% of max activity');
xlabel ('Time (s)');
box off;
axis tight;
% plot second extracted signal
figure('color','w');
plot(time(ind2),gas_lat_env_norm(ind2))
ylabel('% of max activity');
xlabel ('Time (s)');
box off;
axis tight;
% Make a mean of gas_lat_cycle1 and gas_lat_cycle2?
gas_lat_cycle = (gas_lat_cycle1 + gas_lat_cycle2)/2
Error: Matrix dimensions must agree.
However, the number of events may differ depending on a signal and therefor I would like to make this process automated and
  • extract the signal betweene 3 and 4 and so on (4-5; 5-6....) (if such would(and will) be present)
  • make the mean and standard devation of the mean of each extracted signal periods and save it as one variables
Could you please help?

Accepted Answer

Image Analyst
Image Analyst on 30 Nov 2021
You can threshold at 10 or 15 or so, then look for starting and stopping indexes
inPeak = gas_lat_env_norm > 10;
startingIndexes = strfind(inPeak, [0, 1]);
endingIndexes = strfind(inPeak, [1, 0]);
I presume you know what to do from there.
It could be a little easier to extract certain peaks if you have the Image Processing Toolbox where you can label (identify) individual peaks and then use ismember() to get just the peak you want.
  4 Comments
John Navarro
John Navarro on 1 Dec 2021
Just read the size and times of "l_heel_strike_uncroppedtime", loaded to the new vector and use it to define the starting and ending points, like Image Analysit propose.
In others words create a vector which size +1 bigger than the number of events and then load the times into that vector such as
a= [0, l_heel_strike_uncroppedtime(1), l_heel_strike_uncroppedtime (2) ... l_heel_strike_uncroppedtime (n)],
Using a for loop could help.

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!