Effacer les filtres
Effacer les filtres

I am trying to do muscle fatigue analysis, what can be done changes in the code.

7 vues (au cours des 30 derniers jours)
Manav Divekar
Manav Divekar le 28 Nov 2021
with the following code i a trying to do muscle activation and fatigue analysis base on the fft values.
can someone help me with the code. what am i doing wrong and what changes can be done for the analysis
%% Import Data from TXT files
files = dir('*.txt'); % Returns all the files and folders in the directory
fileTable = struct2table(files);
numOfFiles = height(fileTable);
for k = 1:numOfFiles
if strfind(fileTable.name{k}, 'Fatigue')
secfiles{k} = fileTable.name{k};
end
end
allfiles = secfiles(~cellfun(@isempty,secfiles(:,1)),:);
masterData = struct;
for j = 1:length(allfiles)
file_info(:,j) = split(allfiles(j), "_");
masterData(j).group = file_info(1,j);
masterData(j).muscle = file_info(2,j);
masterData(j).trial = extractBefore(file_info(4,j),'.');
impFatigueA = importdata(allfiles(j));
end
%%
% Fatigue Data
impFatigueA = importdata('Fatigue_A.txt');
impFatigueK = importdata('Fatigue_K.txt');
impFatigueZ = importdata('Fatigue_Z.txt');
%impMVICT2 = importdata('G2_Tricep_MVIC_2.txt');
%% Removing the DC Offset from the Signal %%
impFatigueA2 = detrend(impFatigueA); % detrend removes the mean value or linear trend from a vector or matrix.
impFatigueK2 = detrend(impFatigueK); % detrend removes the mean value or linear trend from a vector or matrix.
impFatigueZ2 = detrend(impFatigueZ);
%% Rectifcication of the Signal
impFatigueA3 = abs(impFatigueA2);
impFatigueK3 = abs(impFatigueK2);
impFatigueZ3 = abs(impFatigueZ2);
%% Creating the Envelope of the EMG Signal %%
[b,a]=butter(5,2.5/1000,'low'); % low pass filter to cut off frequency at 10Hz, using a 5th order filter and a samppling frequencyt of 1000Hz.
impFatigueA4=filtfilt(b,a,impFatigueA3);
impFatigueK4=filtfilt(b,a,impFatigueK3);
impFatigueZ4=filtfilt(b,a,impFatigueZ3);
%% fft plot for impFatigueA4 %%
Fs=1000;
L=length(impFatigueA4);
t=L/Fs;
x=impFatigueA4;
Y = fft(x);
P2 = abs(Y/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = Fs*(0:(L/2))/L;
plot(f,P1)
title('Frequency Spectrum Plot')
xlabel('f (Hz)')
ylabel('|P1(f)|')
Error i am getting.
Index in position 1 exceeds array bounds (must not exceed 3).
Error in untitled (line 17)
masterData(j).trial = extractBefore(file_info(4,j),'.');

Réponses (1)

Neelanshu
Neelanshu le 6 Mai 2024
Hi Manav,
The variable file_info is a 2x1 cell array for the "Fatigue_A.txt" stored in the zip file shared by you. As the error message implies you are trying to access an element that does not exist.
Furthermore, to import data from files using "importdata", you need to use {} to extract the filename from the files, which is a cell array (as shown in the code snippet below).
for j = 1:length(allfiles)
file_info(:,j) = split(allfiles(j), "_");
masterData(j).group = file_info(1,j);
masterData(j).muscle = file_info(2,j);
% masterData(j).trial = extractBefore(file_info(4,j),'.'); % The index of file_info has to change
impFatigueA = importdata(allfiles{j});
end
You may refer to the following documentation to learn more about accessing data in tables :
Hope this helps.

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by