Help creating RMS Window

2 Ansichten (letzte 30 Tage)
Isaac Garcia
Isaac Garcia am 11 Mai 2024
Bearbeitet: Mathieu NOE am 2 Jan. 2025
Hello,
I am supposed to import data from 10 Excel files then filter, rectify and create a RMS window for the data, but I am stuck at the last step. I am not very good at MATLAB, but I believe that I am on the right track so far. Any help would be extremely appreciated. I included what I have so far; the commented section at the end is what I am supposed to work off of. I tried a similar loop like the ones prior but did not succeed. Thank you in advance!
clear all; clc
fileName ={'Gait_normal01.csv';'Gait_normal02.csv';'Gait_rightlimp01.csv';'Gait_rightlimp02.csv';'MVC_Extension01.csv';...
'MVC_Extension02.csv';'MVC_Flexion01.csv';'MVC_Flexion02.csv';'SitStand01.csv';'Squat01.csv'}
% read in Data
for i=1:10
EMGraw_data{i,1} =dlmread(fileName{i,1},',',5,2);
end
%filter
for i=1:10
i
for j=1:4
j
[B,A]=butter(2,[10/500 350/500],'bandpass');
EMGf{i,1}(:,j) = filtfilt(B,A,EMGraw_data{i,1}(:,j));
end
end
% rectify
for i=1:10
i
for j=1:4
j
EMGrec{i,1}(:,j) = abs(EMGf{i,1}(:,j));
end
end
% %Root mean square
% winlength = 299; %input 1-desired window length
% EMGrms=zeros(length(EMGrec)-winlength,1);
% for i=1:length(EMGrec)-winlength;
% win=EMGrec(i:i+winlength);
% EMGrms(i+(winlength+1)/2)=sqrt(sum(win.^2)/winlength);
% end

Antworten (1)

Mathieu NOE
Mathieu NOE am 13 Mai 2024
hello
here some demo code FYI
% dummy data
n = 1000;
Fs = 100;
dt = 1/Fs;
t=(0:n-1)*dt;
y = max(0.707,abs(cos(t))+0.1*rand(size(t)));
buffer = Fs; % 1 second buffer (size in samples)
overlap = round(0.5*Fs); % overlap (here 50 % of buffer size) (size in samples)
[t_rms,y_rms] = my_rms(t,y,buffer,overlap);
figure(1),
plot(t,y,t_rms,y_rms,'r-*');
legend('raw data','1 s rms');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [t_rms,x_rms] = my_rms(t,x,buffer,overlap)
%%%% main loop %%%%
m = length(x);
dt = mean(diff(t));
shift = buffer-overlap; % nb of samples between 2 contiguous buffers
for ci=1:fix((m-buffer)/shift +1)
start_index = 1+(ci-1)*shift;
stop_index = min(start_index+ buffer-1,m);
t_rms(ci) = dt*(start_index+stop_index)/2; % time (centered in buffer)
x_rms(ci) = sqrt(mean(x(start_index:stop_index).^2));
end
end
  4 Kommentare
Alessandro
Alessandro am 26 Dez. 2024
I did and i'd like to cite you in my thesis. How do i do it?
Mathieu NOE
Mathieu NOE am 2 Jan. 2025
Bearbeitet: Mathieu NOE am 2 Jan. 2025
hello and happy new year
it's maybe a too great honor to be cited in your thesis
I would simply prefer you to press the "accept" button (you should see a box that says "Accept this answer." )

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Parallel for-Loops (parfor) finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by