How to split my EMG signal into individual cycles?
Show older comments
Hi I have recorded an emg signal of 5 different muscles on someone performing manual wheelchair propulsion.
Sensor 1 = biceps
Sensor 2 = triceps
Sensor 3 = Anterioir Deltoid
Sensor 4 = Posterior Deltoid
Sensor 5 = Upper Trapezius
Each sensor also records the acceleration in the x, y and z directions.
I want to split the emg signal into seperate propulsion cycles (when the hand pushes and releases to when the hand hits the push rim again.) so that I can average each cycle, as well as convert time (s) to percentage of cycle.
I know there were 13-14 cycles during the recording as i videoed the subject while gathering data.
I have only looked at the bicep data as shown below and was wondeing if there is a way to do this with the information I have.
Please let me know if you need anymore information.
%% SEMG Signal Analysis - Row Test 1 Participant 1 28/06/2024
% *This is my practice code to figure out how to export the data into MATLAB and transfer the data into arrays that I can manipulate and do calculations with. *
clear all;
clc;
%% Importing raw data from csv. file
% *BOLD TEXT*
raw_data = readmatrix('P02_S09_T01.csv');
%% SEMG Time Data
% *Storing the Sub-frame data in arrays*
fs = 1926; % sampling frequency in Hz
columnIndex = 2; % Specify the index of the column you want to extract (1 for the Frame column, 2 for the Sub Frame column, and so on)
Sub_Frame = []; % Creating an array to store all the sub-frames related to the EMG data
row = 4;
while ~isnan(raw_data(row, columnIndex))
number = raw_data(row, columnIndex);
Sub_Frame = [Sub_Frame, number];
row = row + 1;
end
Time = (1:length(Sub_Frame))/fs; % converting the sub frame array into time in seconds array
%% Acceleration Sensor 1 (bicep) ACCY1
%
% Find the maximum row number
maxRow = size(raw_data, 1);
acc_fs = 148; %sa/sec
%find sub frame for acceleration
columnIndex = 2; % Specify the index of the column you want to extract (1 for the Frame column, 2 for the Sub Frame column, and so on)
Acc_Sub_Frame = []; % Creating an array to store all the sub-frames related to the EMG data
acc_row = 77955;
while acc_row <= maxRow
number = raw_data(acc_row, columnIndex);
Acc_Sub_Frame = [Acc_Sub_Frame, number];
acc_row = acc_row + 1;
end
Acc_Time = (1:length(Acc_Sub_Frame))/acc_fs; % converting the sub frame array into time in seconds array
columnIndex4 = 4; % Corresponds to ACCY1 (acceleration in the y-direction of sensor 1).
ACCY1 = []; % Creating an array to store all the AccY1
row2 = 77955;
while row2 <= maxRow
num = raw_data(row2, columnIndex4);
ACCY1 = [ACCY1, num];
row2 = row2 + 1;
end
acc_rms_signal = [];
window = 50;
acc_rms_signal = sqrt(movmean((ACCY1.^2),window));
%% Muscle arrays
% Sensor #1 - Biceps Brachii
% Sensor #2 - Triceps Brachii
% Sensor #3 - Anterioir Deltoid
% Sensor #4 - Posterior Deltoid
% Sensor #5 - Upper Trapezius
% *Storing the muscle data in arrays*
columnIndex = 3; % Specify the index of the column you want to extract (1 for the Frame column, 2 for the Sub Frame column, and so on)
Biceps_Brachii = [];% Creating an array to store all the frames related to the EMG data
row = 4; % This is the starting position of the Frame data
% Create a for loop to run through every sensor and store in each array.
while ~isnan(raw_data(row, columnIndex))
number = raw_data(row, columnIndex);
Biceps_Brachii = [Biceps_Brachii, number];
row = row + 1;
end
%% BP filter
% filtering from 20 to Hz
fnyq = fs/2;
fcuthigh = 20;
fcutlow = 450;
%4th order Butterworth BP filter
[b,a]=butter(4,[fcuthigh,fcutlow]/fnyq,'bandpass');
butterworth_filter_signal=filtfilt(b,a,Biceps_Brachii);
%% RMS
%
rms_signal = [];
window = 50;
rms_signal = sqrt(movmean((rec_signal.^2),window));
% Create a figure with two subplots
figure;
% Plot the first graph on the top
subplot(2, 1, 1);
plot(Time, rms_signal);
title('EMG');
% Plot the second graph on the bottom
subplot(2, 1, 2);
plot(Acc_Time, acc_rms_signal);
title('Acceleration');
Accepted Answer
More Answers (1)
Taylor
on 12 Aug 2024
0 votes
I would recommend using the findpeaks function. You can set a minimum amplitude value (Threshold) and minimum time between cycles (MinPeakDistance) if you have a rough idea of the frequency of contration cycles.
1 Comment
Renee Wurfel
on 13 Aug 2024
Categories
Find more on Applications in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!