# How to automate extraction of multiple parts of a signal?

2 views (last 30 days)
Tomaszzz on 30 Nov 2021
Commented: Tomaszzz on 1 Dec 2021
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:
% 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

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.
Tomaszzz on 1 Dec 2021
Thanks a lot. This will do the job.