How to alternatively cut a signal into segments of different sizes

4 views (last 30 days)
I have an EMG signal of duration 680 seconds, i want to make segments of this signal starting from the 1st 6 seconds and then the next 8 seconds and repeat this procedure till i have reached 680 seconds;i want to make alternative segments of 6s and 8s and then i want to concatenate the 6s data into 1 variable and 8 seconds into another variable. The final step is to to grow size of the 6s variable to 8s so that both the variables becomes of the same time. 6 seconds represents rest while the next 8s represents contraction. This set is repeated 10 times like rest for 6s and then contraction for the next 8s.
  4 Comments

Sign in to comment.

Accepted Answer

Mohammad Sami
Mohammad Sami on 4 Jun 2020
Edited: Mohammad Sami on 4 Jun 2020
You can use reshape to extract the signals
% Incorrect : prb2 = reshape(prb,14*2048,2,[]);
% Correction
prb2 = reshape(prb,14*2048,[],2);
prbsix = prb2(1:(6*2048),:,:);
prbeight = prb2((6*2048+1):end,:,:);
prbsix = [ prbsix ; zeros(2*2048,size(prbsix,2),size(prbsix,3))]; % pad with zeros
If you wish to reshape it back to 2D, you can do as follows
prbeight = reshape(prbeight,[],2);
prbsix = reshape(prbsix,[],2);
  14 Comments
Mohammad Sami
Mohammad Sami on 8 Jun 2020
Yes that should be correct for a 3 channel or n channel data as well.
The code does assume that your signal lenght will be divisible by 14s. It that is not the case you will get an error message.
Your summary is sort of correct except the reshape allows us to do it all in one go, rather then have to repeat for each individual block.
Mohammad Sami
Mohammad Sami on 8 Jun 2020
Do look into the documentations for the reshape function to see how it works.

Sign in to comment.

More Answers (0)

Categories

Find more on Measurements and Feature Extraction in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!